Skip to content

Commit

Permalink
fix: ensure proper type association for nestedProperties in data type…
Browse files Browse the repository at this point in the history
… configuration

- Resolved incorrect handling of `nestedProperties` for non-object data types.
- Introduced `ObjectDataType` and `PrimitiveDataType` for improved type distinction.
- Updated `NestedPropertyCreate` and `NestedPropertyConfigCreate` to align with conditional `dataType` logic.
- Improved type safety and consistency in data type configurations.
  • Loading branch information
pacyL2K19 committed Nov 18, 2024
1 parent a95e728 commit fed95fe
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/collections/configure/types/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,32 @@ export type MultiTenancyConfigUpdate = {
autoTenantCreation?: boolean;
};

export type ObjectDataType = 'object' | 'object[]';

export type PrimitiveDataType = Exclude<DataType, ObjectDataType>;

export type NestedDataTypeConfig<T> =
| {
dataType: ObjectDataType;
/** only for object types */
nestedProperties?: NestedPropertyConfigCreate<T, ObjectDataType>[];
}
| {
dataType: PrimitiveDataType;
/** If not an object, or an array of objecs, this field should never be assigned. */
nestedProperties?: never;
};

export type NestedPropertyCreate<T = undefined> = T extends undefined
? {
name: string;
dataType: DataType;
description?: string;
nestedProperties?: NestedPropertyConfigCreate<T, DataType>[];
indexInverted?: boolean;
indexFilterable?: boolean;
indexSearchable?: boolean;
tokenization?: WeaviateNestedProperty['tokenization'];
}
} & NestedDataTypeConfig<T>
: {
[K in NonRefKeys<T>]: RequiresNested<DataType<T[K]>> extends true
? {
Expand Down Expand Up @@ -92,17 +107,15 @@ export type NestedPropertyConfigCreateBase = {
export type PropertyConfigCreate<T> = T extends undefined
? {
name: string;
dataType: DataType;
description?: string;
nestedProperties?: NestedPropertyConfigCreate<T, DataType>[];
indexInverted?: boolean;
indexFilterable?: boolean;
indexRangeFilters?: boolean;
indexSearchable?: boolean;
tokenization?: WeaviateProperty['tokenization'];
skipVectorization?: boolean;
vectorizePropertyName?: boolean;
}
} & NestedDataTypeConfig<T>
: {
[K in NonRefKeys<T>]: RequiresNested<DataType<T[K]>> extends true
? {
Expand Down

0 comments on commit fed95fe

Please sign in to comment.