( meta: EntityMetadata, expression: NonNullable<EntityPartitionBy['expression']>, quoteIdentifier: (id: string) => string, )
| 242 | * user owns identifier quoting inside a raw expression. |
| 243 | */ |
| 244 | const resolvePartitionExpression = ( |
| 245 | meta: EntityMetadata, |
| 246 | expression: NonNullable<EntityPartitionBy['expression']>, |
| 247 | quoteIdentifier: (id: string) => string, |
| 248 | ): string => { |
| 249 | if (typeof expression === 'function') { |
| 250 | return normalizeWhitespace(expression(meta.createSchemaColumnMappingObject())); |
| 251 | } |
| 252 | |
| 253 | if (Array.isArray(expression)) { |
| 254 | return (expression as readonly string[]).map(key => resolvePartitionKey(meta, key, quoteIdentifier)).join(', '); |
| 255 | } |
| 256 | |
| 257 | const trimmed = (expression as string).trim(); |
| 258 | const keys = splitCommaSeparatedIdentifiers(trimmed); |
| 259 | |
| 260 | if (keys) { |
| 261 | return keys.map(key => resolvePartitionKey(meta, key, quoteIdentifier)).join(', '); |
| 262 | } |
| 263 | |
| 264 | return trimmed; |
| 265 | }; |
| 266 | |
| 267 | const createPartitionDefinition = (type: EntityPartitionBy['type'], expression: string): string => |
| 268 | `${type.toLowerCase()} (${normalizeWhitespace(expression)})`; |
no test coverage detected