@mikro-orm/core
Advanced tools
@@ -573,2 +573,9 @@ import type { EntityManager } from '../EntityManager.js'; | ||
| /** @internal */ | ||
| export declare class StringPropertyOptionsBuilder<Value, Options> extends UniversalPropertyOptionsBuilder<Value, Options, IncludeKeysForProperty> { | ||
| trim(): StringPropertyOptionsBuilder<Value, Options>; | ||
| lowercase(): StringPropertyOptionsBuilder<Value, Options>; | ||
| uppercase(): StringPropertyOptionsBuilder<Value, Options>; | ||
| private withOptions; | ||
| } | ||
| /** @internal */ | ||
| export declare class OneToManyOptionsBuilderOnlyMappedBy<Value extends object> extends UniversalPropertyOptionsBuilder<Value, EmptyOptions & { | ||
@@ -586,3 +593,3 @@ kind: '1:m'; | ||
| declare const propertyBuilders: PropertyBuilders; | ||
| type PropertyBuildersOverrideKeys = 'bigint' | 'array' | 'decimal' | 'json' | 'datetime' | 'time' | 'enum'; | ||
| type PropertyBuildersOverrideKeys = 'bigint' | 'array' | 'decimal' | 'json' | 'string' | 'text' | 'datetime' | 'time' | 'enum'; | ||
| /** Map of factory functions for creating type-safe property builders (scalars, enums, embeddables, and relations). */ | ||
@@ -596,2 +603,4 @@ export type PropertyBuilders = { | ||
| json: <T>() => UniversalPropertyOptionsBuilder<T, EmptyOptions, IncludeKeysForProperty>; | ||
| string: () => StringPropertyOptionsBuilder<InferPropertyValueType<typeof types.string>, EmptyOptions>; | ||
| text: () => StringPropertyOptionsBuilder<InferPropertyValueType<typeof types.text>, EmptyOptions>; | ||
| formula: <T>(formula: string | FormulaCallback<any>) => UniversalPropertyOptionsBuilder<T, EmptyOptions, IncludeKeysForProperty>; | ||
@@ -598,0 +607,0 @@ datetime: (length?: number) => UniversalPropertyOptionsBuilder<InferPropertyValueType<typeof types.datetime>, EmptyOptions, IncludeKeysForProperty>; |
@@ -475,2 +475,23 @@ import { types } from '../types/index.js'; | ||
| /** @internal */ | ||
| export class StringPropertyOptionsBuilder extends UniversalPropertyOptionsBuilder { | ||
| trim() { | ||
| return this.withOptions({ trim: true }); | ||
| } | ||
| lowercase() { | ||
| return this.withOptions({ case: 'lower' }); | ||
| } | ||
| uppercase() { | ||
| return this.withOptions({ case: 'upper' }); | ||
| } | ||
| withOptions(options) { | ||
| const type = this['~options'].type; | ||
| const TypeClass = typeof type === 'function' ? type : type.constructor; | ||
| const currentOptions = typeof type === 'function' ? {} : type.options; | ||
| return new StringPropertyOptionsBuilder({ | ||
| ...this['~options'], | ||
| type: new TypeClass({ ...currentOptions, ...options }), | ||
| }); | ||
| } | ||
| } | ||
| /** @internal */ | ||
| export class OneToManyOptionsBuilderOnlyMappedBy extends UniversalPropertyOptionsBuilder { | ||
@@ -491,2 +512,8 @@ /** Point to the owning side property name. */ | ||
| json: () => new UniversalPropertyOptionsBuilder({ type: types.json }), | ||
| string: () => new StringPropertyOptionsBuilder({ | ||
| type: types.string, | ||
| }), | ||
| text: () => new StringPropertyOptionsBuilder({ | ||
| type: types.text, | ||
| }), | ||
| formula: (formula) => new UniversalPropertyOptionsBuilder({ formula }), | ||
@@ -493,0 +520,0 @@ datetime: (length) => new UniversalPropertyOptionsBuilder({ type: types.datetime, length }), |
+1
-1
| { | ||
| "name": "@mikro-orm/core", | ||
| "version": "7.2.0-dev.11", | ||
| "version": "7.2.0-dev.12", | ||
| "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
+2
-2
@@ -18,3 +18,3 @@ import { ArrayType } from './ArrayType.js'; | ||
| import { SmallIntType } from './SmallIntType.js'; | ||
| import { StringType } from './StringType.js'; | ||
| import { type StringTypeOptions, StringType } from './StringType.js'; | ||
| import { TextType } from './TextType.js'; | ||
@@ -27,3 +27,3 @@ import { TimeType } from './TimeType.js'; | ||
| import { UuidType } from './UuidType.js'; | ||
| export type { TransformContext, IType }; | ||
| export type { TransformContext, IType, StringTypeOptions }; | ||
| export { Type, DateType, TimeType, DateTimeType, BigIntType, BlobType, Uint8ArrayType, ArrayType, EnumArrayType, EnumType, JsonType, IntegerType, SmallIntType, TinyIntType, MediumIntType, FloatType, DoubleType, BooleanType, DecimalType, StringType, UuidType, TextType, UnknownType, IntervalType, CharacterType, }; | ||
@@ -30,0 +30,0 @@ /** Registry of all built-in type constructors, keyed by their short name (e.g., `types.integer`, `types.uuid`). */ |
| import { Type } from './Type.js'; | ||
| import type { Platform } from '../platforms/Platform.js'; | ||
| import type { EntityProperty } from '../typings.js'; | ||
| export interface StringTypeOptions { | ||
| trim?: boolean; | ||
| case?: 'upper' | 'lower'; | ||
| } | ||
| /** @internal */ | ||
| export declare abstract class BaseStringType extends Type<string | null | undefined, string | null | undefined> { | ||
| readonly options: StringTypeOptions; | ||
| constructor(options?: StringTypeOptions); | ||
| convertToDatabaseValue(value: string | null | undefined): string | null | undefined; | ||
| compareAsType(): string; | ||
| ensureComparable(): boolean; | ||
| private normalize; | ||
| } | ||
| /** Maps a database VARCHAR column to a JS `string`. */ | ||
| export declare class StringType extends Type<string | null | undefined, string | null | undefined> { | ||
| export declare class StringType extends BaseStringType { | ||
| getColumnType(prop: EntityProperty, platform: Platform): string; | ||
| compareAsType(): string; | ||
| ensureComparable(): boolean; | ||
| getDefaultLength(platform: Platform): number; | ||
| } |
+34
-4
| import { Type } from './Type.js'; | ||
| /** Maps a database VARCHAR column to a JS `string`. */ | ||
| export class StringType extends Type { | ||
| getColumnType(prop, platform) { | ||
| return platform.getVarcharTypeDeclarationSQL(prop); | ||
| /** @internal */ | ||
| export class BaseStringType extends Type { | ||
| options; | ||
| constructor(options = {}) { | ||
| super(); | ||
| this.options = options; | ||
| // a defined `compareValues` replaces the inline `!==` comparator, so only provide it when normalization is configured | ||
| if (options.trim || options.case) { | ||
| this.compareValues = (a, b) => this.normalize(a) === this.normalize(b); | ||
| } | ||
| } | ||
| convertToDatabaseValue(value) { | ||
| return this.normalize(value); | ||
| } | ||
| compareAsType() { | ||
@@ -13,2 +22,23 @@ return 'string'; | ||
| } | ||
| normalize(value) { | ||
| if (value == null) { | ||
| return value; | ||
| } | ||
| if (this.options.trim) { | ||
| value = value.trim(); | ||
| } | ||
| if (this.options.case === 'upper') { | ||
| return value.toUpperCase(); | ||
| } | ||
| if (this.options.case === 'lower') { | ||
| return value.toLowerCase(); | ||
| } | ||
| return value; | ||
| } | ||
| } | ||
| /** Maps a database VARCHAR column to a JS `string`. */ | ||
| export class StringType extends BaseStringType { | ||
| getColumnType(prop, platform) { | ||
| return platform.getVarcharTypeDeclarationSQL(prop); | ||
| } | ||
| getDefaultLength(platform) { | ||
@@ -15,0 +45,0 @@ return platform.getDefaultVarcharLength(); |
@@ -1,9 +0,7 @@ | ||
| import { Type } from './Type.js'; | ||
| import { BaseStringType } from './StringType.js'; | ||
| import type { Platform } from '../platforms/Platform.js'; | ||
| import type { EntityProperty } from '../typings.js'; | ||
| /** Maps a database TEXT column (unbounded length) to a JS `string`. */ | ||
| export declare class TextType extends Type<string | null | undefined, string | null | undefined> { | ||
| export declare class TextType extends BaseStringType { | ||
| getColumnType(prop: EntityProperty, platform: Platform): string; | ||
| compareAsType(): string; | ||
| ensureComparable(): boolean; | ||
| } |
@@ -1,13 +0,7 @@ | ||
| import { Type } from './Type.js'; | ||
| import { BaseStringType } from './StringType.js'; | ||
| /** Maps a database TEXT column (unbounded length) to a JS `string`. */ | ||
| export class TextType extends Type { | ||
| export class TextType extends BaseStringType { | ||
| getColumnType(prop, platform) { | ||
| return platform.getTextTypeDeclarationSQL(prop); | ||
| } | ||
| compareAsType() { | ||
| return 'string'; | ||
| } | ||
| ensureComparable() { | ||
| return false; | ||
| } | ||
| } |
+1
-1
@@ -156,3 +156,3 @@ import { clone } from './clone.js'; | ||
| static PK_SEPARATOR = '~~~'; | ||
| static #ORM_VERSION = '7.2.0-dev.11'; | ||
| static #ORM_VERSION = '7.2.0-dev.12'; | ||
| /** | ||
@@ -159,0 +159,0 @@ * Checks if the argument is instance of `Object`. Returns false for arrays. |
1592166
0.17%33960
0.2%