-
Notifications
You must be signed in to change notification settings - Fork 69
(EAI-923) universal tagging system #671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
beab0af
3483b83
eeb1781
9988271
721f3ae
9e7eb53
ba97cfd
721b332
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. export this from |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { mongoDbProducts, mongodbDrivers } from "./products"; | ||
import { mongoDbProgrammingLanguageIds } from "./programmingLanguages"; | ||
import { mongoDbTopics } from "./topics"; | ||
|
||
// Helpers for constructing the `MongoDbTag` union type | ||
const mongoDbProductIds = mongoDbProducts.map((product) => product.id); | ||
const mongoDbDriverIds = mongodbDrivers.map((driver) => driver.id); | ||
const mongoDbTopicIds = mongoDbTopics.map((topic) => topic.id); | ||
|
||
/** | ||
All possible MongoDB tags. Useful for tagging evaluations. | ||
*/ | ||
export type MongoDbTag = | ||
| (typeof mongoDbProgrammingLanguageIds)[number] | ||
| (typeof mongoDbProductIds)[number] | ||
| (typeof mongoDbDriverIds)[number] | ||
| (typeof mongoDbTopicIds)[number]; | ||
|
||
/** | ||
All possible MongoDB tags as enum. | ||
*/ | ||
export const mongoDbTags = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm confused by this. isn't this a record, not an enum? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typescript does support enums as a firstclass construct https://www.w3schools.com/typescript/typescript_enums.php consider also doing a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, its not an enum. I made some changes that simplify it a bit. |
||
// Add all programming language IDs | ||
...mongoDbProgrammingLanguageIds.reduce((acc, id) => { | ||
acc[id] = id; | ||
return acc; | ||
}, {} as Record<string, string>), | ||
|
||
// Add all product IDs | ||
...mongoDbProductIds.reduce((acc, id) => { | ||
acc[id] = id; | ||
return acc; | ||
}, {} as Record<string, string>), | ||
|
||
// Add all driver IDs | ||
...mongoDbDriverIds.reduce((acc, id) => { | ||
acc[id] = id; | ||
return acc; | ||
}, {} as Record<string, string>), | ||
|
||
// Add all topic IDs | ||
...mongoDbTopicIds.reduce((acc, id) => { | ||
acc[id] = id; | ||
return acc; | ||
}, {} as Record<string, string>), | ||
} as const; | ||
|
||
/** | ||
Validates an array of tag names against the MongoDbTags enum. | ||
|
||
@param tagNames - An array of strings representing tag names to validate | ||
@param custom - A boolean flag indicating whether custom tags are allowed | ||
@throws {Error} When non-custom tags are used that don't exist in MongoDbTags enum | ||
|
||
@remarks | ||
If custom is false, all tags must exist in the MongoDbTags enum. | ||
If any invalid tags are found, throws an error with the list of invalid tags | ||
and the allowed tags from MongoDbTags enum. | ||
*/ | ||
export const validateTags = (tagNames: string[], custom: boolean): void => { | ||
if (!custom) { | ||
// check if all tags are allowed using the enum MongoDbTags | ||
const invalidTags = tagNames.filter((tag) => !(tag in mongoDbTags)); | ||
if (invalidTags.length > 0) { | ||
throw new Error( | ||
`Invalid tags found: ${invalidTags.join( | ||
", " | ||
)} \nUse the "addCustomTags" transformation instead or use allowed tags: \n - ${Object.keys( | ||
mongoDbTags | ||
) | ||
.sort() | ||
.join("\n - ")}` | ||
); | ||
} | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls do this as a named export. in the PR #678, i added much of the metadata stuff.
it's exported as
mongodb-rag-core/mongoDbMetadata
.pls update the imports throught this PR accordingly.