@rvoh/dream 2.1.3 → 2.1.4-alpha.1
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/cli/index.js +4 -0
- package/dist/cjs/src/dream/QueryDriver/Kysely.js +4 -6
- package/dist/cjs/src/dream/QueryDriver/helpers/kysely/foreignKeyTypeFromPrimaryKey.js +3 -0
- package/dist/cjs/src/dream/constants.js +1 -1
- package/dist/cjs/src/helpers/cli/generateFactoryContent.js +13 -3
- package/dist/cjs/src/helpers/cli/generateMigrationContent.js +17 -3
- package/dist/cjs/src/package-exports/system.js +1 -0
- package/dist/esm/src/cli/index.js +4 -0
- package/dist/esm/src/dream/QueryDriver/Kysely.js +4 -6
- package/dist/esm/src/dream/QueryDriver/helpers/kysely/foreignKeyTypeFromPrimaryKey.js +3 -0
- package/dist/esm/src/dream/constants.js +1 -1
- package/dist/esm/src/helpers/cli/generateFactoryContent.js +13 -3
- package/dist/esm/src/helpers/cli/generateMigrationContent.js +17 -3
- package/dist/esm/src/package-exports/system.js +1 -0
- package/dist/types/src/Dream.d.ts +14 -0
- package/dist/types/src/dream/QueryDriver/Base.d.ts +3 -3
- package/dist/types/src/dream/QueryDriver/Kysely.d.ts +4 -4
- package/dist/types/src/dream/QueryDriver/helpers/kysely/foreignKeyTypeFromPrimaryKey.d.ts +2 -2
- package/dist/types/src/dream/constants.d.ts +1 -1
- package/dist/types/src/dream-app/index.d.ts +4 -5
- package/dist/types/src/helpers/cli/generateMigrationContent.d.ts +1 -1
- package/dist/types/src/helpers/cli/generateStiMigrationContent.d.ts +1 -1
- package/dist/types/src/package-exports/system.d.ts +1 -0
- package/dist/types/src/package-exports/types.d.ts +1 -1
- package/dist/types/src/types/db.d.ts +2 -0
- package/dist/types/src/types/db.ts +2 -0
- package/dist/types/src/types/dream.d.ts +1 -2
- package/dist/types/src/types/dream.ts +1 -3
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +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.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 +2 -2
- package/docs/classes/index.Decorators.html +19 -19
- package/docs/classes/index.Dream.html +132 -122
- 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 +55 -55
- package/docs/classes/system.CliFileWriter.html +2 -2
- package/docs/classes/system.DreamBin.html +2 -2
- package/docs/classes/system.DreamCLI.html +5 -5
- package/docs/classes/system.DreamImporter.html +2 -2
- package/docs/classes/system.DreamLogos.html +2 -2
- package/docs/classes/system.DreamSerializerBuilder.html +8 -8
- package/docs/classes/system.ObjectSerializerBuilder.html +8 -8
- package/docs/classes/utils.Encrypt.html +2 -2
- 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-1.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.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/modules/db.html +1 -1
- package/docs/modules/errors.html +1 -1
- package/docs/modules/index.html +1 -1
- package/docs/modules/openapi.html +1 -1
- package/docs/modules/system.html +2 -1
- package/docs/modules/types.html +4 -3
- package/docs/modules/utils.html +1 -1
- package/docs/types/index.DateTime.html +1 -1
- 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 +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionRef.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
- package/docs/types/openapi.OpenapiSchemaNull.html +1 -1
- 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 +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
- 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.Camelized.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 +1 -1
- 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.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 -0
- 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 +1 -1
- package/docs/types/types.ViewModelClass.html +1 -1
- package/docs/types/types.WhereStatementForDream.html +1 -1
- package/docs/types/types.WhereStatementForDreamClass.html +1 -1
- package/docs/variables/index.DateTime-1.html +1 -1
- package/docs/variables/index.DreamConst.html +1 -1
- package/docs/variables/index.ops.html +1 -1
- package/docs/variables/openapi.openapiPrimitiveTypes-1.html +1 -1
- package/docs/variables/openapi.openapiShorthandPrimitiveTypes-1.html +1 -1
- package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
- package/docs/variables/system.primaryKeyTypes.html +1 -0
- package/docs/variables/types.TRIGRAM_OPERATORS.html +1 -1
- package/package.json +1 -1
- package/docs/variables/types.primaryKeyTypes.html +0 -1
|
@@ -14,6 +14,10 @@ ${INDENT}all properties default to not nullable; null can be allowed by appendin
|
|
|
14
14
|
${INDENT} subtitle:string:optional
|
|
15
15
|
${INDENT}
|
|
16
16
|
${INDENT}supported types:
|
|
17
|
+
${INDENT} - uuid:
|
|
18
|
+
${INDENT} - uuid[]:
|
|
19
|
+
${INDENT} a column optimized for storing UUIDs
|
|
20
|
+
${INDENT}
|
|
17
21
|
${INDENT} - citext:
|
|
18
22
|
${INDENT} - citext[]:
|
|
19
23
|
${INDENT} case insensitive text (indexes and queries are automatically case insensitive)
|
|
@@ -67,6 +67,7 @@ import sqlResultToDreamInstance from '../internal/sqlResultToDreamInstance.js';
|
|
|
67
67
|
import Query from '../Query.js';
|
|
68
68
|
import QueryDriverBase from './Base.js';
|
|
69
69
|
import checkForNeedToBeRunMigrations from './helpers/kysely/checkForNeedToBeRunMigrations.js';
|
|
70
|
+
import foreignKeyTypeFromPrimaryKey from './helpers/kysely/foreignKeyTypeFromPrimaryKey.js';
|
|
70
71
|
import runMigration from './helpers/kysely/runMigration.js';
|
|
71
72
|
export default class KyselyQueryDriver extends QueryDriverBase {
|
|
72
73
|
// ATTENTION FRED
|
|
@@ -211,12 +212,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
211
212
|
* gives the driver the opportunity to switch i.e. bigserial to bigint.
|
|
212
213
|
*/
|
|
213
214
|
static foreignKeyTypeFromPrimaryKey(primaryKey) {
|
|
214
|
-
|
|
215
|
-
case 'bigserial':
|
|
216
|
-
return 'bigint';
|
|
217
|
-
default:
|
|
218
|
-
return primaryKey;
|
|
219
|
-
}
|
|
215
|
+
return foreignKeyTypeFromPrimaryKey(primaryKey);
|
|
220
216
|
}
|
|
221
217
|
/**
|
|
222
218
|
* @internal
|
|
@@ -229,6 +225,8 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
229
225
|
switch (dreamconf.primaryKeyType) {
|
|
230
226
|
case 'bigint':
|
|
231
227
|
case 'bigserial':
|
|
228
|
+
case 'uuid7':
|
|
229
|
+
case 'uuid4':
|
|
232
230
|
case 'uuid':
|
|
233
231
|
case 'integer':
|
|
234
232
|
return dreamconf.primaryKeyType;
|
|
@@ -9,16 +9,17 @@ export default function generateFactoryContent({ fullyQualifiedModelName, column
|
|
|
9
9
|
const dreamTypeImports = ['UpdateableProperties'];
|
|
10
10
|
const dreamImports = [];
|
|
11
11
|
const additionalImports = [];
|
|
12
|
+
const nodeImports = [];
|
|
12
13
|
const belongsToNames = [];
|
|
13
14
|
const belongsToTypedNames = [];
|
|
14
15
|
const associationCreationStatements = [];
|
|
15
16
|
const attributeDefaults = [];
|
|
16
17
|
let counterVariableIncremented = false;
|
|
17
18
|
for (const attribute of columnsWithTypes) {
|
|
18
|
-
const [attributeName,
|
|
19
|
+
const [attributeName, _attributeType, ...descriptors] = attribute.split(':');
|
|
19
20
|
if (attributeName === undefined)
|
|
20
21
|
continue;
|
|
21
|
-
if (
|
|
22
|
+
if (_attributeType === undefined)
|
|
22
23
|
continue;
|
|
23
24
|
const optional = optionalFromDescriptors(descriptors);
|
|
24
25
|
if (optional)
|
|
@@ -28,6 +29,7 @@ export default function generateFactoryContent({ fullyQualifiedModelName, column
|
|
|
28
29
|
continue;
|
|
29
30
|
if (/(_type|_id)$/.test(attributeName))
|
|
30
31
|
continue;
|
|
32
|
+
const attributeType = /uuid$/.test(attributeName) ? 'uuid' : _attributeType;
|
|
31
33
|
if (!attributeType)
|
|
32
34
|
throw new Error(`Must pass a column type for ${attributeName} (i.e. ${attributeName}:string)`);
|
|
33
35
|
const safeAttributeType = camelize(attributeType)?.toLowerCase();
|
|
@@ -95,6 +97,14 @@ export default function generateFactoryContent({ fullyQualifiedModelName, column
|
|
|
95
97
|
dreamImports.push('DateTime');
|
|
96
98
|
attributeDefaults.push(`${attributeVariable}: [DateTime.now()],`);
|
|
97
99
|
break;
|
|
100
|
+
case 'uuid':
|
|
101
|
+
nodeImports.push('randomUUID');
|
|
102
|
+
attributeDefaults.push(`${attributeVariable}: randomUUID(),`);
|
|
103
|
+
break;
|
|
104
|
+
case 'uuid[]':
|
|
105
|
+
nodeImports.push('randomUUID');
|
|
106
|
+
attributeDefaults.push(`${attributeVariable}: [randomUUID()],`);
|
|
107
|
+
break;
|
|
98
108
|
default:
|
|
99
109
|
if (/\[\]$/.test(attributeType)) {
|
|
100
110
|
attributeDefaults.push(`${attributeVariable}: [],`);
|
|
@@ -105,7 +115,7 @@ export default function generateFactoryContent({ fullyQualifiedModelName, column
|
|
|
105
115
|
const relativePath = absoluteDreamPath('models', fullyQualifiedModelName);
|
|
106
116
|
const modelClassName = globalClassNameFromFullyQualifiedModelName(fullyQualifiedModelName);
|
|
107
117
|
return `\
|
|
108
|
-
${dreamImports.length ? `import { ${uniq(dreamImports).join(', ')} } from '@rvoh/dream'\n` : ''}import { ${uniq(dreamTypeImports).join(', ')} } from '@rvoh/dream/types'
|
|
118
|
+
${nodeImports.length ? `import { ${uniq(nodeImports).join(', ')} } from 'node:crypto'\n` : ''}${dreamImports.length ? `import { ${uniq(dreamImports).join(', ')} } from '@rvoh/dream'\n` : ''}import { ${uniq(dreamTypeImports).join(', ')} } from '@rvoh/dream/types'
|
|
109
119
|
import ${modelClassName} from '${relativePath}'${additionalImports.length ? '\n' + uniq(additionalImports).join('\n') : ''}
|
|
110
120
|
${counterVariableIncremented ? '\nlet counter = 0\n' : ''}
|
|
111
121
|
export default async function create${modelClassName}(attrs: UpdateableProperties<${modelClassName}> = {}) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import pluralize from 'pluralize-esm';
|
|
2
2
|
import Query from '../../dream/Query.js';
|
|
3
3
|
import InvalidDecimalFieldPassedToGenerator from '../../errors/InvalidDecimalFieldPassedToGenerator.js';
|
|
4
|
+
import camelize from '../camelize.js';
|
|
4
5
|
import compact from '../compact.js';
|
|
5
6
|
import snakeify from '../snakeify.js';
|
|
6
|
-
import camelize from '../camelize.js';
|
|
7
7
|
const STI_TYPE_COLUMN_NAME = 'type';
|
|
8
8
|
const COLUMNS_TO_INDEX = [STI_TYPE_COLUMN_NAME];
|
|
9
9
|
export default function generateMigrationContent({ connectionName = 'default', table, columnsWithTypes = [], primaryKeyType = 'bigserial', createOrAlter = 'create', stiChildClassName, } = {}) {
|
|
@@ -13,11 +13,17 @@ export default function generateMigrationContent({ connectionName = 'default', t
|
|
|
13
13
|
const { columnDefs, columnDrops, indexDefs, indexDrops } = columnsWithTypes.reduce((acc, attributeDeclaration) => {
|
|
14
14
|
const { columnDefs, columnDrops, indexDefs, indexDrops } = acc;
|
|
15
15
|
const [nonStandardAttributeName, _attributeType, ...descriptors] = attributeDeclaration.split(':');
|
|
16
|
+
if (!nonStandardAttributeName)
|
|
17
|
+
return acc;
|
|
16
18
|
/**
|
|
17
19
|
* Automatically set email columns to citext since different casings of
|
|
18
20
|
* email address are the same email address
|
|
19
21
|
*/
|
|
20
|
-
const attributeType = nonStandardAttributeName
|
|
22
|
+
const attributeType = /email$/.test(nonStandardAttributeName)
|
|
23
|
+
? 'citext'
|
|
24
|
+
: /uuid$/.test(nonStandardAttributeName)
|
|
25
|
+
? 'uuid'
|
|
26
|
+
: _attributeType;
|
|
21
27
|
const processedAttrType = camelize(attributeType)?.toLowerCase();
|
|
22
28
|
const userWantsThisOptional = optionalFromDescriptors(descriptors);
|
|
23
29
|
// when creating a migration for an STI child, we don't want to include notNull;
|
|
@@ -232,7 +238,7 @@ function generateColumnStr(attributeName, attributeType, descriptors, { omitInli
|
|
|
232
238
|
const providedDefaultArg = descriptors.find(d => /^default\(/.test(d));
|
|
233
239
|
const providedDefault = providedDefaultArg?.replace(/^default\(/, '')?.replace(/\)$/, '');
|
|
234
240
|
const notNull = !optional;
|
|
235
|
-
const isUnique =
|
|
241
|
+
const isUnique = /(email|token|uuid)$/.test(attributeName);
|
|
236
242
|
const hasExtraValues = providedDefault || notNull || isUnique;
|
|
237
243
|
const isArray = /\[\]$/.test(attributeType);
|
|
238
244
|
if (hasExtraValues)
|
|
@@ -281,6 +287,14 @@ function generateBelongsToStr(connectionName, associationName, { primaryKeyType,
|
|
|
281
287
|
}
|
|
282
288
|
function generateIdStr({ primaryKeyType }) {
|
|
283
289
|
switch (primaryKeyType) {
|
|
290
|
+
case 'uuid7':
|
|
291
|
+
return `\
|
|
292
|
+
.addColumn('id', 'uuid', col =>
|
|
293
|
+
col
|
|
294
|
+
.primaryKey()
|
|
295
|
+
.defaultTo(sql\`uuid_generate_v7()\`),
|
|
296
|
+
)`;
|
|
297
|
+
case 'uuid4':
|
|
284
298
|
case 'uuid':
|
|
285
299
|
return `\
|
|
286
300
|
.addColumn('id', 'uuid', col =>
|
|
@@ -3,6 +3,7 @@ export { CliFileWriter } from '../cli/CliFileWriter.js';
|
|
|
3
3
|
export { default as DreamCLI } from '../cli/index.js';
|
|
4
4
|
export { default as DreamImporter } from '../dream-app/helpers/DreamImporter.js';
|
|
5
5
|
export { DreamAppAllowedPackageManagersEnumValues, } from '../dream-app/index.js';
|
|
6
|
+
export { primaryKeyTypes } from '../dream/constants.js';
|
|
6
7
|
export { default as DreamLogos } from '../helpers/DreamLogos/DreamLogos.js';
|
|
7
8
|
export { default as DreamSerializerBuilder } from '../serializer/builders/DreamSerializerBuilder.js';
|
|
8
9
|
export { default as ObjectSerializerBuilder } from '../serializer/builders/ObjectSerializerBuilder.js';
|
|
@@ -14,6 +14,10 @@ ${INDENT}all properties default to not nullable; null can be allowed by appendin
|
|
|
14
14
|
${INDENT} subtitle:string:optional
|
|
15
15
|
${INDENT}
|
|
16
16
|
${INDENT}supported types:
|
|
17
|
+
${INDENT} - uuid:
|
|
18
|
+
${INDENT} - uuid[]:
|
|
19
|
+
${INDENT} a column optimized for storing UUIDs
|
|
20
|
+
${INDENT}
|
|
17
21
|
${INDENT} - citext:
|
|
18
22
|
${INDENT} - citext[]:
|
|
19
23
|
${INDENT} case insensitive text (indexes and queries are automatically case insensitive)
|
|
@@ -67,6 +67,7 @@ import sqlResultToDreamInstance from '../internal/sqlResultToDreamInstance.js';
|
|
|
67
67
|
import Query from '../Query.js';
|
|
68
68
|
import QueryDriverBase from './Base.js';
|
|
69
69
|
import checkForNeedToBeRunMigrations from './helpers/kysely/checkForNeedToBeRunMigrations.js';
|
|
70
|
+
import foreignKeyTypeFromPrimaryKey from './helpers/kysely/foreignKeyTypeFromPrimaryKey.js';
|
|
70
71
|
import runMigration from './helpers/kysely/runMigration.js';
|
|
71
72
|
export default class KyselyQueryDriver extends QueryDriverBase {
|
|
72
73
|
// ATTENTION FRED
|
|
@@ -211,12 +212,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
211
212
|
* gives the driver the opportunity to switch i.e. bigserial to bigint.
|
|
212
213
|
*/
|
|
213
214
|
static foreignKeyTypeFromPrimaryKey(primaryKey) {
|
|
214
|
-
|
|
215
|
-
case 'bigserial':
|
|
216
|
-
return 'bigint';
|
|
217
|
-
default:
|
|
218
|
-
return primaryKey;
|
|
219
|
-
}
|
|
215
|
+
return foreignKeyTypeFromPrimaryKey(primaryKey);
|
|
220
216
|
}
|
|
221
217
|
/**
|
|
222
218
|
* @internal
|
|
@@ -229,6 +225,8 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
229
225
|
switch (dreamconf.primaryKeyType) {
|
|
230
226
|
case 'bigint':
|
|
231
227
|
case 'bigserial':
|
|
228
|
+
case 'uuid7':
|
|
229
|
+
case 'uuid4':
|
|
232
230
|
case 'uuid':
|
|
233
231
|
case 'integer':
|
|
234
232
|
return dreamconf.primaryKeyType;
|
|
@@ -9,16 +9,17 @@ export default function generateFactoryContent({ fullyQualifiedModelName, column
|
|
|
9
9
|
const dreamTypeImports = ['UpdateableProperties'];
|
|
10
10
|
const dreamImports = [];
|
|
11
11
|
const additionalImports = [];
|
|
12
|
+
const nodeImports = [];
|
|
12
13
|
const belongsToNames = [];
|
|
13
14
|
const belongsToTypedNames = [];
|
|
14
15
|
const associationCreationStatements = [];
|
|
15
16
|
const attributeDefaults = [];
|
|
16
17
|
let counterVariableIncremented = false;
|
|
17
18
|
for (const attribute of columnsWithTypes) {
|
|
18
|
-
const [attributeName,
|
|
19
|
+
const [attributeName, _attributeType, ...descriptors] = attribute.split(':');
|
|
19
20
|
if (attributeName === undefined)
|
|
20
21
|
continue;
|
|
21
|
-
if (
|
|
22
|
+
if (_attributeType === undefined)
|
|
22
23
|
continue;
|
|
23
24
|
const optional = optionalFromDescriptors(descriptors);
|
|
24
25
|
if (optional)
|
|
@@ -28,6 +29,7 @@ export default function generateFactoryContent({ fullyQualifiedModelName, column
|
|
|
28
29
|
continue;
|
|
29
30
|
if (/(_type|_id)$/.test(attributeName))
|
|
30
31
|
continue;
|
|
32
|
+
const attributeType = /uuid$/.test(attributeName) ? 'uuid' : _attributeType;
|
|
31
33
|
if (!attributeType)
|
|
32
34
|
throw new Error(`Must pass a column type for ${attributeName} (i.e. ${attributeName}:string)`);
|
|
33
35
|
const safeAttributeType = camelize(attributeType)?.toLowerCase();
|
|
@@ -95,6 +97,14 @@ export default function generateFactoryContent({ fullyQualifiedModelName, column
|
|
|
95
97
|
dreamImports.push('DateTime');
|
|
96
98
|
attributeDefaults.push(`${attributeVariable}: [DateTime.now()],`);
|
|
97
99
|
break;
|
|
100
|
+
case 'uuid':
|
|
101
|
+
nodeImports.push('randomUUID');
|
|
102
|
+
attributeDefaults.push(`${attributeVariable}: randomUUID(),`);
|
|
103
|
+
break;
|
|
104
|
+
case 'uuid[]':
|
|
105
|
+
nodeImports.push('randomUUID');
|
|
106
|
+
attributeDefaults.push(`${attributeVariable}: [randomUUID()],`);
|
|
107
|
+
break;
|
|
98
108
|
default:
|
|
99
109
|
if (/\[\]$/.test(attributeType)) {
|
|
100
110
|
attributeDefaults.push(`${attributeVariable}: [],`);
|
|
@@ -105,7 +115,7 @@ export default function generateFactoryContent({ fullyQualifiedModelName, column
|
|
|
105
115
|
const relativePath = absoluteDreamPath('models', fullyQualifiedModelName);
|
|
106
116
|
const modelClassName = globalClassNameFromFullyQualifiedModelName(fullyQualifiedModelName);
|
|
107
117
|
return `\
|
|
108
|
-
${dreamImports.length ? `import { ${uniq(dreamImports).join(', ')} } from '@rvoh/dream'\n` : ''}import { ${uniq(dreamTypeImports).join(', ')} } from '@rvoh/dream/types'
|
|
118
|
+
${nodeImports.length ? `import { ${uniq(nodeImports).join(', ')} } from 'node:crypto'\n` : ''}${dreamImports.length ? `import { ${uniq(dreamImports).join(', ')} } from '@rvoh/dream'\n` : ''}import { ${uniq(dreamTypeImports).join(', ')} } from '@rvoh/dream/types'
|
|
109
119
|
import ${modelClassName} from '${relativePath}'${additionalImports.length ? '\n' + uniq(additionalImports).join('\n') : ''}
|
|
110
120
|
${counterVariableIncremented ? '\nlet counter = 0\n' : ''}
|
|
111
121
|
export default async function create${modelClassName}(attrs: UpdateableProperties<${modelClassName}> = {}) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import pluralize from 'pluralize-esm';
|
|
2
2
|
import Query from '../../dream/Query.js';
|
|
3
3
|
import InvalidDecimalFieldPassedToGenerator from '../../errors/InvalidDecimalFieldPassedToGenerator.js';
|
|
4
|
+
import camelize from '../camelize.js';
|
|
4
5
|
import compact from '../compact.js';
|
|
5
6
|
import snakeify from '../snakeify.js';
|
|
6
|
-
import camelize from '../camelize.js';
|
|
7
7
|
const STI_TYPE_COLUMN_NAME = 'type';
|
|
8
8
|
const COLUMNS_TO_INDEX = [STI_TYPE_COLUMN_NAME];
|
|
9
9
|
export default function generateMigrationContent({ connectionName = 'default', table, columnsWithTypes = [], primaryKeyType = 'bigserial', createOrAlter = 'create', stiChildClassName, } = {}) {
|
|
@@ -13,11 +13,17 @@ export default function generateMigrationContent({ connectionName = 'default', t
|
|
|
13
13
|
const { columnDefs, columnDrops, indexDefs, indexDrops } = columnsWithTypes.reduce((acc, attributeDeclaration) => {
|
|
14
14
|
const { columnDefs, columnDrops, indexDefs, indexDrops } = acc;
|
|
15
15
|
const [nonStandardAttributeName, _attributeType, ...descriptors] = attributeDeclaration.split(':');
|
|
16
|
+
if (!nonStandardAttributeName)
|
|
17
|
+
return acc;
|
|
16
18
|
/**
|
|
17
19
|
* Automatically set email columns to citext since different casings of
|
|
18
20
|
* email address are the same email address
|
|
19
21
|
*/
|
|
20
|
-
const attributeType = nonStandardAttributeName
|
|
22
|
+
const attributeType = /email$/.test(nonStandardAttributeName)
|
|
23
|
+
? 'citext'
|
|
24
|
+
: /uuid$/.test(nonStandardAttributeName)
|
|
25
|
+
? 'uuid'
|
|
26
|
+
: _attributeType;
|
|
21
27
|
const processedAttrType = camelize(attributeType)?.toLowerCase();
|
|
22
28
|
const userWantsThisOptional = optionalFromDescriptors(descriptors);
|
|
23
29
|
// when creating a migration for an STI child, we don't want to include notNull;
|
|
@@ -232,7 +238,7 @@ function generateColumnStr(attributeName, attributeType, descriptors, { omitInli
|
|
|
232
238
|
const providedDefaultArg = descriptors.find(d => /^default\(/.test(d));
|
|
233
239
|
const providedDefault = providedDefaultArg?.replace(/^default\(/, '')?.replace(/\)$/, '');
|
|
234
240
|
const notNull = !optional;
|
|
235
|
-
const isUnique =
|
|
241
|
+
const isUnique = /(email|token|uuid)$/.test(attributeName);
|
|
236
242
|
const hasExtraValues = providedDefault || notNull || isUnique;
|
|
237
243
|
const isArray = /\[\]$/.test(attributeType);
|
|
238
244
|
if (hasExtraValues)
|
|
@@ -281,6 +287,14 @@ function generateBelongsToStr(connectionName, associationName, { primaryKeyType,
|
|
|
281
287
|
}
|
|
282
288
|
function generateIdStr({ primaryKeyType }) {
|
|
283
289
|
switch (primaryKeyType) {
|
|
290
|
+
case 'uuid7':
|
|
291
|
+
return `\
|
|
292
|
+
.addColumn('id', 'uuid', col =>
|
|
293
|
+
col
|
|
294
|
+
.primaryKey()
|
|
295
|
+
.defaultTo(sql\`uuid_generate_v7()\`),
|
|
296
|
+
)`;
|
|
297
|
+
case 'uuid4':
|
|
284
298
|
case 'uuid':
|
|
285
299
|
return `\
|
|
286
300
|
.addColumn('id', 'uuid', col =>
|
|
@@ -3,6 +3,7 @@ export { CliFileWriter } from '../cli/CliFileWriter.js';
|
|
|
3
3
|
export { default as DreamCLI } from '../cli/index.js';
|
|
4
4
|
export { default as DreamImporter } from '../dream-app/helpers/DreamImporter.js';
|
|
5
5
|
export { DreamAppAllowedPackageManagersEnumValues, } from '../dream-app/index.js';
|
|
6
|
+
export { primaryKeyTypes } from '../dream/constants.js';
|
|
6
7
|
export { default as DreamLogos } from '../helpers/DreamLogos/DreamLogos.js';
|
|
7
8
|
export { default as DreamSerializerBuilder } from '../serializer/builders/DreamSerializerBuilder.js';
|
|
8
9
|
export { default as ObjectSerializerBuilder } from '../serializer/builders/ObjectSerializerBuilder.js';
|
|
@@ -2377,6 +2377,13 @@ export default class Dream {
|
|
|
2377
2377
|
* For HasMany associations, returns an array (empty if no records). For BelongsTo/HasOne
|
|
2378
2378
|
* associations, returns the associated model or null if not found.
|
|
2379
2379
|
*
|
|
2380
|
+
* @remarks
|
|
2381
|
+
* **Warning:** Using `association` in loops or when processing multiple records can lead to the
|
|
2382
|
+
* [N+1 query problem](https://guides.rubyonrails.org/active_record_querying.html#eager-loading-associations).
|
|
2383
|
+
* Each call to `association` on an unloaded association will trigger a separate database query.
|
|
2384
|
+
* To avoid this, use {@link Dream.load | `load`} or {@link Dream.preload | `preload`} to eager load
|
|
2385
|
+
* associations before accessing them.
|
|
2386
|
+
*
|
|
2380
2387
|
* ```ts
|
|
2381
2388
|
* // Basic association loading
|
|
2382
2389
|
* const user = await post.association('user')
|
|
@@ -2429,6 +2436,13 @@ export default class Dream {
|
|
|
2429
2436
|
* For HasMany associations, returns an array (empty if no records). For BelongsTo/HasOne
|
|
2430
2437
|
* associations, returns the associated model or throws RecordNotFound if not found.
|
|
2431
2438
|
*
|
|
2439
|
+
* @remarks
|
|
2440
|
+
* **Warning:** Using `associationOrFail` in loops or when processing multiple records can lead to the
|
|
2441
|
+
* [N+1 query problem](https://guides.rubyonrails.org/active_record_querying.html#eager-loading-associations).
|
|
2442
|
+
* Each call to `associationOrFail` on an unloaded association will trigger a separate database query.
|
|
2443
|
+
* To avoid this, use {@link Dream.load | `load`} or {@link Dream.preload | `preload`} to eager load
|
|
2444
|
+
* associations before accessing them.
|
|
2445
|
+
*
|
|
2432
2446
|
* ```ts
|
|
2433
2447
|
* // Basic association loading - throws RecordNotFound if user doesn't exist
|
|
2434
2448
|
* const user = await post.associationOrFail('user')
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { CompiledQuery, DeleteQueryBuilder, SelectQueryBuilder, UpdateQueryBuilder } from 'kysely';
|
|
2
2
|
import Dream from '../../Dream.js';
|
|
3
|
+
import { SchemaBuilderAssociationData, SchemaBuilderColumnData } from '../../helpers/cli/ASTBuilder.js';
|
|
3
4
|
import { AssociationStatement } from '../../types/associations/shared.js';
|
|
4
|
-
import { DbConnectionType } from '../../types/db.js';
|
|
5
|
-
import { DreamColumnNames, DreamConstructorType, DreamTableSchema
|
|
5
|
+
import { DbConnectionType, PrimaryKeyType } from '../../types/db.js';
|
|
6
|
+
import { DreamColumnNames, DreamConstructorType, DreamTableSchema } from '../../types/dream.js';
|
|
6
7
|
import { PreloadedDreamsAndWhatTheyPointTo, QueryToKyselyDBType, QueryToKyselyTableNamesType } from '../../types/query.js';
|
|
7
8
|
import DreamTransaction from '../DreamTransaction.js';
|
|
8
9
|
import Query from '../Query.js';
|
|
9
|
-
import { SchemaBuilderAssociationData, SchemaBuilderColumnData } from '../../helpers/cli/ASTBuilder.js';
|
|
10
10
|
export default class QueryDriverBase<DreamInstance extends Dream> {
|
|
11
11
|
query: Query<DreamInstance, any>;
|
|
12
12
|
protected readonly dreamClass: DreamConstructorType<DreamInstance>;
|
|
@@ -3,8 +3,8 @@ import { DialectProviderCb } from '../../db/DreamDbConnection.js';
|
|
|
3
3
|
import Dream from '../../Dream.js';
|
|
4
4
|
import { SchemaBuilderInformationSchemaRow } from '../../helpers/cli/ASTBuilder.js';
|
|
5
5
|
import { AssociationStatement } from '../../types/associations/shared.js';
|
|
6
|
-
import { DbConnectionType } from '../../types/db.js';
|
|
7
|
-
import { DreamColumnNames, DreamTableSchema, OrderDir,
|
|
6
|
+
import { DbConnectionType, PrimaryKeyType } from '../../types/db.js';
|
|
7
|
+
import { DreamColumnNames, DreamTableSchema, OrderDir, SqlCommandType } from '../../types/dream.js';
|
|
8
8
|
import { PreloadedDreamsAndWhatTheyPointTo, QueryToKyselyDBType, QueryToKyselyTableNamesType } from '../../types/query.js';
|
|
9
9
|
import DreamTransaction from '../DreamTransaction.js';
|
|
10
10
|
import Query from '../Query.js';
|
|
@@ -48,14 +48,14 @@ export default class KyselyQueryDriver<DreamInstance extends Dream> extends Quer
|
|
|
48
48
|
* returns the foreign key type based on the primary key received.
|
|
49
49
|
* gives the driver the opportunity to switch i.e. bigserial to bigint.
|
|
50
50
|
*/
|
|
51
|
-
static foreignKeyTypeFromPrimaryKey(primaryKey: PrimaryKeyType): "bigint" | "
|
|
51
|
+
static foreignKeyTypeFromPrimaryKey(primaryKey: PrimaryKeyType): "bigint" | "integer" | "uuid";
|
|
52
52
|
/**
|
|
53
53
|
* @internal
|
|
54
54
|
*
|
|
55
55
|
* used to return the computed primary key type based
|
|
56
56
|
* on the primaryKeyType set in the DreamApp class.
|
|
57
57
|
*/
|
|
58
|
-
static primaryKeyType():
|
|
58
|
+
static primaryKeyType(): PrimaryKeyType;
|
|
59
59
|
/**
|
|
60
60
|
* destroys a dream, possibly implementing soft delete if reallyDestroy is false
|
|
61
61
|
* and the record being deleted implements soft delete.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PrimaryKeyType } from '../../../../types/
|
|
2
|
-
export default function foreignKeyTypeFromPrimaryKey(primaryKey: PrimaryKeyType): "bigint" | "
|
|
1
|
+
import { PrimaryKeyType } from '../../../../types/db.js';
|
|
2
|
+
export default function foreignKeyTypeFromPrimaryKey(primaryKey: PrimaryKeyType): "bigint" | "integer" | "uuid";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const primaryKeyTypes: readonly ["
|
|
1
|
+
export declare const primaryKeyTypes: readonly ["uuid7", "uuid4", "bigserial", "bigint", "integer"];
|
|
2
2
|
export declare const TRIGRAM_OPERATORS: readonly ["%", "<%", "<<%"];
|
|
3
3
|
declare class RequiredAttribute {
|
|
4
4
|
constructor();
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { CompiledQuery } from 'kysely';
|
|
2
2
|
import { Context } from 'node:vm';
|
|
3
3
|
import Dream from '../Dream.js';
|
|
4
|
-
import { primaryKeyTypes } from '../dream/constants.js';
|
|
5
4
|
import QueryDriverBase from '../dream/QueryDriver/Base.js';
|
|
6
5
|
import { EncryptOptions } from '../encrypt/index.js';
|
|
7
6
|
import autogeneratedFileDisclaimer from '../helpers/cli/autoGeneratedFileDisclaimer.js';
|
|
@@ -13,7 +12,7 @@ import expandStiClasses from '../helpers/sti/expandStiClasses.js';
|
|
|
13
12
|
import inferSerializerFromDreamOrViewModel, { inferSerializersFromDreamClassOrViewModelClass } from '../serializer/helpers/inferSerializerFromDreamOrViewModel.js';
|
|
14
13
|
import isDreamSerializer from '../serializer/helpers/isDreamSerializer.js';
|
|
15
14
|
import serializerNameFromFullyQualifiedModelName from '../serializer/helpers/serializerNameFromFullyQualifiedModelName.js';
|
|
16
|
-
import { DbConnectionType } from '../types/db.js';
|
|
15
|
+
import { DbConnectionType, PrimaryKeyType } from '../types/db.js';
|
|
17
16
|
import { DreamModelSerializerType, SimpleObjectSerializerType } from '../types/serializer.js';
|
|
18
17
|
export default class DreamApp {
|
|
19
18
|
/**
|
|
@@ -116,7 +115,7 @@ export default class DreamApp {
|
|
|
116
115
|
private _paginationPageSize;
|
|
117
116
|
get paginationPageSize(): number;
|
|
118
117
|
private _primaryKeyType;
|
|
119
|
-
get primaryKeyType():
|
|
118
|
+
get primaryKeyType(): PrimaryKeyType;
|
|
120
119
|
private _projectRoot;
|
|
121
120
|
get projectRoot(): string;
|
|
122
121
|
private _paths;
|
|
@@ -153,13 +152,13 @@ export default class DreamApp {
|
|
|
153
152
|
get parallelDatabasesEnabled(): boolean;
|
|
154
153
|
load<RT extends 'models' | 'serializers'>(resourceType: RT, resourcePath: string, importCb: (path: string) => Promise<any>): Promise<void>;
|
|
155
154
|
plugin(cb: (app: DreamApp) => void | Promise<void>): void;
|
|
156
|
-
set<ApplyOpt extends DreamAppSetOption>(applyOption: ApplyOpt, options: ApplyOpt extends 'bypassDeprecationChecks' ? boolean : ApplyOpt extends 'db' ? DreamDbCredentialOptions | string : ApplyOpt extends 'encryption' ? DreamAppEncryptionOptions : ApplyOpt extends 'primaryKeyType' ?
|
|
155
|
+
set<ApplyOpt extends DreamAppSetOption>(applyOption: ApplyOpt, options: ApplyOpt extends 'bypassDeprecationChecks' ? boolean : ApplyOpt extends 'db' ? DreamDbCredentialOptions | string : ApplyOpt extends 'encryption' ? DreamAppEncryptionOptions : ApplyOpt extends 'primaryKeyType' ? PrimaryKeyType : ApplyOpt extends 'importExtension' ? GeneratorImportStyle : ApplyOpt extends 'logger' ? DreamLogger : ApplyOpt extends 'projectRoot' ? string : ApplyOpt extends 'inflections' ? () => void | Promise<void> : ApplyOpt extends 'packageManager' ? DreamAppAllowedPackageManagersEnum : ApplyOpt extends 'paths' ? DreamDirectoryPaths : ApplyOpt extends 'parallelTests' ? number : ApplyOpt extends 'unicodeNormalization' ? UnicodeNormalizationForm : ApplyOpt extends 'paginationPageSize' ? number : never, secondaryOptions?: ApplyOpt extends 'db' ? DreamDbCredentialOptions : never): void;
|
|
157
156
|
on<T extends DreamHookEventType>(hookEventType: T, cb: T extends 'db:log' ? (event: KyselyLogEvent) => void : T extends 'repl:start' ? (context: Context) => void | Promise<void> : never): void;
|
|
158
157
|
}
|
|
159
158
|
export type DreamHookEventType = 'db:log' | 'repl:start';
|
|
160
159
|
export interface DreamAppOpts {
|
|
161
160
|
projectRoot: string;
|
|
162
|
-
primaryKeyType:
|
|
161
|
+
primaryKeyType: PrimaryKeyType;
|
|
163
162
|
db: DreamDbCredentialOptions;
|
|
164
163
|
inflections?: () => void | Promise<void>;
|
|
165
164
|
paths?: DreamDirectoryPaths;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PrimaryKeyType } from '../../types/
|
|
1
|
+
import { PrimaryKeyType } from '../../types/db.js';
|
|
2
2
|
export default function generateMigrationContent({ connectionName, table, columnsWithTypes, primaryKeyType, createOrAlter, stiChildClassName, }?: {
|
|
3
3
|
connectionName?: string;
|
|
4
4
|
table?: string | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PrimaryKeyType } from '../../types/
|
|
1
|
+
import { PrimaryKeyType } from '../../types/db.js';
|
|
2
2
|
export default function generateStiMigrationContent({ table, columnsWithTypes, primaryKeyType, stiChildClassName, }: {
|
|
3
3
|
table?: string;
|
|
4
4
|
columnsWithTypes?: string[];
|
|
@@ -3,6 +3,7 @@ export { CliFileWriter } from '../cli/CliFileWriter.js';
|
|
|
3
3
|
export { default as DreamCLI } from '../cli/index.js';
|
|
4
4
|
export { default as DreamImporter } from '../dream-app/helpers/DreamImporter.js';
|
|
5
5
|
export { DreamAppAllowedPackageManagersEnumValues, type DreamAppAllowedPackageManagersEnum, } from '../dream-app/index.js';
|
|
6
|
+
export { primaryKeyTypes } from '../dream/constants.js';
|
|
6
7
|
export { default as DreamLogos } from '../helpers/DreamLogos/DreamLogos.js';
|
|
7
8
|
export { default as DreamSerializerBuilder } from '../serializer/builders/DreamSerializerBuilder.js';
|
|
8
9
|
export { default as ObjectSerializerBuilder } from '../serializer/builders/ObjectSerializerBuilder.js';
|
|
@@ -7,7 +7,7 @@ export { type SerializerRendererOpts } from '../serializer/SerializerRenderer.js
|
|
|
7
7
|
export { type BelongsToStatement } from '../types/associations/belongsTo.js';
|
|
8
8
|
export { type HasManyStatement } from '../types/associations/hasMany.js';
|
|
9
9
|
export { type HasOneStatement } from '../types/associations/hasOne.js';
|
|
10
|
-
export { type DbConnectionType, type DbTypes } from '../types/db.js';
|
|
10
|
+
export { type DbConnectionType, type DbTypes, type PrimaryKeyType } from '../types/db.js';
|
|
11
11
|
export { type StrictInterface } from '../types/utils.js';
|
|
12
12
|
export { type DreamAssociationMetadata, type DreamAttributes, type DreamClassAssociationAndStatement, type DreamClassColumn, type DreamColumn, type DreamColumnNames, type DreamOrViewModelClassSerializerKey, type DreamOrViewModelSerializerKey, type DreamParamSafeAttributes, type DreamParamSafeColumnNames, type DreamSerializable, type DreamSerializableArray, type DreamSerializerKey, type DreamSerializers, type DreamVirtualColumns, type UpdateableAssociationProperties, type UpdateableProperties, type ViewModel, type ViewModelClass, } from '../types/dream.js';
|
|
13
13
|
export { type DreamModelSerializerType, type InternalAnyTypedSerializerRendersMany, type InternalAnyTypedSerializerRendersOne, type SerializerCasing, type SimpleObjectSerializerType, } from '../types/serializer.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { postgresDatatypes } from '../db/dataTypes.js';
|
|
2
|
+
import { primaryKeyTypes } from '../dream/constants.js';
|
|
2
3
|
export type DbConnectionType = 'primary' | 'replica';
|
|
3
4
|
export type AssociationTableNames<DB, Schema> = keyof DB & keyof Schema extends never ? unknown : keyof DB & keyof Schema & string;
|
|
4
5
|
export type Tables<DB> = keyof DB;
|
|
@@ -6,4 +7,5 @@ export type TableInterfaces<DB> = valueof<DB>;
|
|
|
6
7
|
type valueof<T> = T[keyof T];
|
|
7
8
|
export type NonArrayDbTypes = (typeof postgresDatatypes)[number];
|
|
8
9
|
export type DbTypes = NonArrayDbTypes | `${NonArrayDbTypes}[]`;
|
|
10
|
+
export type PrimaryKeyType = (typeof primaryKeyTypes)[number] | 'uuid';
|
|
9
11
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { postgresDatatypes } from '../db/dataTypes.js'
|
|
2
|
+
import { primaryKeyTypes } from '../dream/constants.js'
|
|
2
3
|
|
|
3
4
|
export type DbConnectionType = 'primary' | 'replica'
|
|
4
5
|
|
|
@@ -12,3 +13,4 @@ type valueof<T> = T[keyof T]
|
|
|
12
13
|
|
|
13
14
|
export type NonArrayDbTypes = (typeof postgresDatatypes)[number]
|
|
14
15
|
export type DbTypes = NonArrayDbTypes | `${NonArrayDbTypes}[]`
|
|
16
|
+
export type PrimaryKeyType = (typeof primaryKeyTypes)[number] | 'uuid'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ColumnType, Updateable } from 'kysely';
|
|
2
2
|
import { STI_SCOPE_NAME } from '../decorators/class/STI.js';
|
|
3
3
|
import Dream from '../Dream.js';
|
|
4
|
-
import {
|
|
4
|
+
import { TRIGRAM_OPERATORS } from '../dream/constants.js';
|
|
5
5
|
import CalendarDate from '../helpers/CalendarDate.js';
|
|
6
6
|
import { DateTime } from '../helpers/DateTime.js';
|
|
7
7
|
import OpsStatement from '../ops/ops-statement.js';
|
|
@@ -11,7 +11,6 @@ import { FindEachOpts } from './query.js';
|
|
|
11
11
|
import { DreamModelSerializerType, SimpleObjectSerializerType } from './serializer.js';
|
|
12
12
|
import { FilterInterface, Inc, RejectInterface } from './utils.js';
|
|
13
13
|
import { AliasedSchemaAssociation } from './variadic.js';
|
|
14
|
-
export type PrimaryKeyType = (typeof primaryKeyTypes)[number];
|
|
15
14
|
export type DreamPrimaryKeyType<I extends Dream, Schema extends I['schema'] = I['schema'], TableName extends keyof Schema = I['table'] & keyof Schema, PrimaryKey extends I['primaryKey' & keyof I] extends undefined ? 'id' : I['primaryKey' & keyof I] = I['primaryKey' & keyof I] extends undefined ? 'id' : I['primaryKey' & keyof I]> = Schema[TableName]['columns'][PrimaryKey & keyof Schema[TableName]['columns']]['coercedType'];
|
|
16
15
|
export type Timestamp = ColumnType<DateTime | CalendarDate>;
|
|
17
16
|
export type MAX_VARIADIC_DEPTH = 25;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ColumnType, Updateable } from 'kysely'
|
|
2
2
|
import { STI_SCOPE_NAME } from '../decorators/class/STI.js'
|
|
3
3
|
import Dream from '../Dream.js'
|
|
4
|
-
import {
|
|
4
|
+
import { TRIGRAM_OPERATORS } from '../dream/constants.js'
|
|
5
5
|
import CalendarDate from '../helpers/CalendarDate.js'
|
|
6
6
|
import { DateTime } from '../helpers/DateTime.js'
|
|
7
7
|
import OpsStatement from '../ops/ops-statement.js'
|
|
@@ -17,8 +17,6 @@ import { DreamModelSerializerType, SimpleObjectSerializerType } from './serializ
|
|
|
17
17
|
import { FilterInterface, Inc, RejectInterface } from './utils.js'
|
|
18
18
|
import { AliasedSchemaAssociation } from './variadic.js'
|
|
19
19
|
|
|
20
|
-
export type PrimaryKeyType = (typeof primaryKeyTypes)[number]
|
|
21
|
-
|
|
22
20
|
export type DreamPrimaryKeyType<
|
|
23
21
|
I extends Dream,
|
|
24
22
|
Schema extends I['schema'] = I['schema'],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
window.navigationData = "data:application/octet-stream;base64,
|
|
1
|
+
window.navigationData = "data:application/octet-stream;base64,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"
|