@intlayer/backend 3.5.4 → 3.5.6
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/controllers/ai.controller.cjs +238 -0
- package/dist/cjs/controllers/ai.controller.cjs.map +1 -0
- package/dist/cjs/controllers/dictionary.controller.cjs +50 -17
- package/dist/cjs/controllers/dictionary.controller.cjs.map +1 -1
- package/dist/cjs/controllers/project.controller.cjs +2 -6
- package/dist/cjs/controllers/project.controller.cjs.map +1 -1
- package/dist/cjs/controllers/tag.controller.cjs +235 -0
- package/dist/cjs/controllers/tag.controller.cjs.map +1 -0
- package/dist/cjs/controllers/user.controller.cjs +1 -0
- package/dist/cjs/controllers/user.controller.cjs.map +1 -1
- package/dist/cjs/export.cjs.map +1 -1
- package/dist/cjs/index.cjs +4 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/middlewares/request.middleware.cjs +4 -0
- package/dist/cjs/middlewares/request.middleware.cjs.map +1 -1
- package/dist/cjs/models/tag.model.cjs +31 -0
- package/dist/cjs/models/tag.model.cjs.map +1 -0
- package/dist/cjs/routes/ai.routes.cjs +69 -0
- package/dist/cjs/routes/ai.routes.cjs.map +1 -0
- package/dist/cjs/routes/dictionary.routes.cjs +4 -4
- package/dist/cjs/routes/dictionary.routes.cjs.map +1 -1
- package/dist/cjs/routes/tags.routes.cjs +60 -0
- package/dist/cjs/routes/tags.routes.cjs.map +1 -0
- package/dist/cjs/schemas/dictionary.schema.cjs +31 -6
- package/dist/cjs/schemas/dictionary.schema.cjs.map +1 -1
- package/dist/cjs/schemas/project.schema.cjs +5 -0
- package/dist/cjs/schemas/project.schema.cjs.map +1 -1
- package/dist/cjs/schemas/tag.schema.cjs +64 -0
- package/dist/cjs/schemas/tag.schema.cjs.map +1 -0
- package/dist/cjs/services/dictionary.service.cjs +139 -27
- package/dist/cjs/services/dictionary.service.cjs.map +1 -1
- package/dist/cjs/services/project.service.cjs +14 -5
- package/dist/cjs/services/project.service.cjs.map +1 -1
- package/dist/cjs/services/tag.service.cjs +91 -0
- package/dist/cjs/services/tag.service.cjs.map +1 -0
- package/dist/cjs/types/dictionary.types.cjs.map +1 -1
- package/dist/cjs/types/project.types.cjs.map +1 -1
- package/dist/cjs/types/tag.types.cjs +17 -0
- package/dist/cjs/types/tag.types.cjs.map +1 -0
- package/dist/cjs/utils/auditDictionary/CJS_FORMAT.md +23 -0
- package/dist/cjs/utils/auditDictionary/JSON_FORMAT.md +26 -0
- package/dist/cjs/utils/auditDictionary/JSX_FORMAT.md +28 -0
- package/dist/cjs/utils/auditDictionary/MJS_FORMAT.md +23 -0
- package/dist/cjs/utils/auditDictionary/PROMPT.md +151 -0
- package/dist/cjs/utils/auditDictionary/TSX_FORMAT.md +28 -0
- package/dist/cjs/utils/auditDictionary/TS_FORMAT.md +22 -0
- package/dist/cjs/utils/auditDictionary/index.cjs +98 -0
- package/dist/cjs/utils/auditDictionary/index.cjs.map +1 -0
- package/dist/cjs/utils/auditDictionaryField/PROMPT.md +115 -0
- package/dist/cjs/utils/auditDictionaryField/index.cjs +81 -0
- package/dist/cjs/utils/auditDictionaryField/index.cjs.map +1 -0
- package/dist/cjs/utils/auditDictionaryMetadata/PROMPT.md +76 -0
- package/dist/cjs/utils/auditDictionaryMetadata/index.cjs +78 -0
- package/dist/cjs/utils/auditDictionaryMetadata/index.cjs.map +1 -0
- package/dist/cjs/utils/auditTag/PROMPT.md +34 -0
- package/dist/cjs/utils/auditTag/index.cjs +74 -0
- package/dist/cjs/utils/auditTag/index.cjs.map +1 -0
- package/dist/cjs/utils/ensureArrayQueryFilter.cjs +39 -0
- package/dist/cjs/utils/ensureArrayQueryFilter.cjs.map +1 -0
- package/dist/cjs/utils/ensureMongoDocumentToObject.cjs +35 -0
- package/dist/cjs/utils/ensureMongoDocumentToObject.cjs.map +1 -0
- package/dist/cjs/utils/errors/ErrorHandler.cjs +1 -1
- package/dist/cjs/utils/errors/ErrorHandler.cjs.map +1 -1
- package/dist/cjs/utils/errors/errorCodes.cjs +104 -0
- package/dist/cjs/utils/errors/errorCodes.cjs.map +1 -1
- package/dist/cjs/utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs +10 -11
- package/dist/cjs/utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs.map +1 -1
- package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs +6 -10
- package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs.map +1 -1
- package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs +6 -10
- package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs.map +1 -1
- package/dist/cjs/utils/filtersAndPagination/getTagFiltersAndPagination.cjs +51 -0
- package/dist/cjs/utils/filtersAndPagination/getTagFiltersAndPagination.cjs.map +1 -0
- package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs +2 -9
- package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs.map +1 -1
- package/dist/cjs/utils/mapper/dictionary.cjs +8 -4
- package/dist/cjs/utils/mapper/dictionary.cjs.map +1 -1
- package/dist/cjs/utils/mapper/organization.cjs +2 -4
- package/dist/cjs/utils/mapper/organization.cjs.map +1 -1
- package/dist/cjs/utils/mapper/project.cjs +2 -4
- package/dist/cjs/utils/mapper/project.cjs.map +1 -1
- package/dist/cjs/utils/mapper/tag.cjs +37 -0
- package/dist/cjs/utils/mapper/tag.cjs.map +1 -0
- package/dist/cjs/utils/mapper/user.cjs +2 -4
- package/dist/cjs/utils/mapper/user.cjs.map +1 -1
- package/dist/cjs/utils/removeObjectKeys.cjs +35 -0
- package/dist/cjs/utils/removeObjectKeys.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateProject.cjs +17 -10
- package/dist/cjs/utils/validation/validateProject.cjs.map +1 -1
- package/dist/cjs/utils/validation/validateTag.cjs +93 -0
- package/dist/cjs/utils/validation/validateTag.cjs.map +1 -0
- package/dist/esm/controllers/ai.controller.mjs +201 -0
- package/dist/esm/controllers/ai.controller.mjs.map +1 -0
- package/dist/esm/controllers/dictionary.controller.mjs +50 -17
- package/dist/esm/controllers/dictionary.controller.mjs.map +1 -1
- package/dist/esm/controllers/project.controller.mjs +2 -6
- package/dist/esm/controllers/project.controller.mjs.map +1 -1
- package/dist/esm/controllers/tag.controller.mjs +203 -0
- package/dist/esm/controllers/tag.controller.mjs.map +1 -0
- package/dist/esm/controllers/user.controller.mjs +1 -0
- package/dist/esm/controllers/user.controller.mjs.map +1 -1
- package/dist/esm/export.mjs.map +1 -1
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/middlewares/request.middleware.mjs +4 -0
- package/dist/esm/middlewares/request.middleware.mjs.map +1 -1
- package/dist/esm/models/tag.model.mjs +7 -0
- package/dist/esm/models/tag.model.mjs.map +1 -0
- package/dist/esm/routes/ai.routes.mjs +49 -0
- package/dist/esm/routes/ai.routes.mjs.map +1 -0
- package/dist/esm/routes/dictionary.routes.mjs +4 -4
- package/dist/esm/routes/dictionary.routes.mjs.map +1 -1
- package/dist/esm/routes/tags.routes.mjs +40 -0
- package/dist/esm/routes/tags.routes.mjs.map +1 -0
- package/dist/esm/schemas/dictionary.schema.mjs +31 -6
- package/dist/esm/schemas/dictionary.schema.mjs.map +1 -1
- package/dist/esm/schemas/project.schema.mjs +5 -0
- package/dist/esm/schemas/project.schema.mjs.map +1 -1
- package/dist/esm/schemas/tag.schema.mjs +45 -0
- package/dist/esm/schemas/tag.schema.mjs.map +1 -0
- package/dist/esm/services/dictionary.service.mjs +137 -27
- package/dist/esm/services/dictionary.service.mjs.map +1 -1
- package/dist/esm/services/project.service.mjs +14 -5
- package/dist/esm/services/project.service.mjs.map +1 -1
- package/dist/esm/services/tag.service.mjs +61 -0
- package/dist/esm/services/tag.service.mjs.map +1 -0
- package/dist/esm/types/tag.types.mjs +1 -0
- package/dist/esm/types/tag.types.mjs.map +1 -0
- package/dist/esm/utils/auditDictionary/CJS_FORMAT.md +23 -0
- package/dist/esm/utils/auditDictionary/JSON_FORMAT.md +26 -0
- package/dist/esm/utils/auditDictionary/JSX_FORMAT.md +28 -0
- package/dist/esm/utils/auditDictionary/MJS_FORMAT.md +23 -0
- package/dist/esm/utils/auditDictionary/PROMPT.md +151 -0
- package/dist/esm/utils/auditDictionary/TSX_FORMAT.md +28 -0
- package/dist/esm/utils/auditDictionary/TS_FORMAT.md +22 -0
- package/dist/esm/utils/auditDictionary/index.mjs +73 -0
- package/dist/esm/utils/auditDictionary/index.mjs.map +1 -0
- package/dist/esm/utils/auditDictionaryField/PROMPT.md +115 -0
- package/dist/esm/utils/auditDictionaryField/index.mjs +56 -0
- package/dist/esm/utils/auditDictionaryField/index.mjs.map +1 -0
- package/dist/esm/utils/auditDictionaryMetadata/PROMPT.md +76 -0
- package/dist/esm/utils/auditDictionaryMetadata/index.mjs +53 -0
- package/dist/esm/utils/auditDictionaryMetadata/index.mjs.map +1 -0
- package/dist/esm/utils/auditTag/PROMPT.md +34 -0
- package/dist/esm/utils/auditTag/index.mjs +49 -0
- package/dist/esm/utils/auditTag/index.mjs.map +1 -0
- package/dist/esm/utils/ensureArrayQueryFilter.mjs +15 -0
- package/dist/esm/utils/ensureArrayQueryFilter.mjs.map +1 -0
- package/dist/esm/utils/ensureMongoDocumentToObject.mjs +11 -0
- package/dist/esm/utils/ensureMongoDocumentToObject.mjs.map +1 -0
- package/dist/esm/utils/errors/ErrorHandler.mjs +1 -1
- package/dist/esm/utils/errors/ErrorHandler.mjs.map +1 -1
- package/dist/esm/utils/errors/errorCodes.mjs +104 -0
- package/dist/esm/utils/errors/errorCodes.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs +10 -11
- package/dist/esm/utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs +6 -10
- package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs +6 -10
- package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getTagFiltersAndPagination.mjs +29 -0
- package/dist/esm/utils/filtersAndPagination/getTagFiltersAndPagination.mjs.map +1 -0
- package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs +2 -9
- package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/mapper/dictionary.mjs +8 -4
- package/dist/esm/utils/mapper/dictionary.mjs.map +1 -1
- package/dist/esm/utils/mapper/organization.mjs +2 -4
- package/dist/esm/utils/mapper/organization.mjs.map +1 -1
- package/dist/esm/utils/mapper/project.mjs +2 -4
- package/dist/esm/utils/mapper/project.mjs.map +1 -1
- package/dist/esm/utils/mapper/tag.mjs +12 -0
- package/dist/esm/utils/mapper/tag.mjs.map +1 -0
- package/dist/esm/utils/mapper/user.mjs +2 -4
- package/dist/esm/utils/mapper/user.mjs.map +1 -1
- package/dist/esm/utils/removeObjectKeys.mjs +11 -0
- package/dist/esm/utils/removeObjectKeys.mjs.map +1 -0
- package/dist/esm/utils/validation/validateProject.mjs +17 -10
- package/dist/esm/utils/validation/validateProject.mjs.map +1 -1
- package/dist/esm/utils/validation/validateTag.mjs +65 -0
- package/dist/esm/utils/validation/validateTag.mjs.map +1 -0
- package/dist/types/controllers/ai.controller.d.ts +61 -0
- package/dist/types/controllers/ai.controller.d.ts.map +1 -0
- package/dist/types/controllers/dictionary.controller.d.ts +6 -3
- package/dist/types/controllers/dictionary.controller.d.ts.map +1 -1
- package/dist/types/controllers/project.controller.d.ts +2 -4
- package/dist/types/controllers/project.controller.d.ts.map +1 -1
- package/dist/types/controllers/tag.controller.d.ts +39 -0
- package/dist/types/controllers/tag.controller.d.ts.map +1 -0
- package/dist/types/controllers/user.controller.d.ts.map +1 -1
- package/dist/types/export.d.ts +3 -0
- package/dist/types/export.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/models/dictionary.model.d.ts +1 -0
- package/dist/types/models/dictionary.model.d.ts.map +1 -1
- package/dist/types/models/tag.model.d.ts +3 -0
- package/dist/types/models/tag.model.d.ts.map +1 -0
- package/dist/types/routes/ai.routes.d.ts +25 -0
- package/dist/types/routes/ai.routes.d.ts.map +1 -0
- package/dist/types/routes/dictionary.routes.d.ts +6 -2
- package/dist/types/routes/dictionary.routes.d.ts.map +1 -1
- package/dist/types/routes/tags.routes.d.ts +29 -0
- package/dist/types/routes/tags.routes.d.ts.map +1 -0
- package/dist/types/schemas/dictionary.schema.d.ts +1 -0
- package/dist/types/schemas/dictionary.schema.d.ts.map +1 -1
- package/dist/types/schemas/project.schema.d.ts.map +1 -1
- package/dist/types/schemas/tag.schema.d.ts +16 -0
- package/dist/types/schemas/tag.schema.d.ts.map +1 -0
- package/dist/types/services/dictionary.service.d.ts +10 -2
- package/dist/types/services/dictionary.service.d.ts.map +1 -1
- package/dist/types/services/project.service.d.ts.map +1 -1
- package/dist/types/services/tag.service.d.ts +45 -0
- package/dist/types/services/tag.service.d.ts.map +1 -0
- package/dist/types/types/dictionary.types.d.ts +14 -4
- package/dist/types/types/dictionary.types.d.ts.map +1 -1
- package/dist/types/types/project.types.d.ts +3 -0
- package/dist/types/types/project.types.d.ts.map +1 -1
- package/dist/types/types/tag.types.d.ts +26 -0
- package/dist/types/types/tag.types.d.ts.map +1 -0
- package/dist/types/utils/audit/index.d.ts +28 -0
- package/dist/types/utils/audit/index.d.ts.map +1 -0
- package/dist/types/utils/auditDictionary/index.d.ts +24 -0
- package/dist/types/utils/auditDictionary/index.d.ts.map +1 -0
- package/dist/types/utils/auditDictionaryField/index.d.ts +24 -0
- package/dist/types/utils/auditDictionaryField/index.d.ts.map +1 -0
- package/dist/types/utils/auditDictionaryMetadata/index.d.ts +21 -0
- package/dist/types/utils/auditDictionaryMetadata/index.d.ts.map +1 -0
- package/dist/types/utils/auditTag/index.d.ts +27 -0
- package/dist/types/utils/auditTag/index.d.ts.map +1 -0
- package/dist/types/utils/ensureArrayQueryFilter.d.ts +2 -0
- package/dist/types/utils/ensureArrayQueryFilter.d.ts.map +1 -0
- package/dist/types/utils/ensureMongoDocumentToObject.d.ts +8 -0
- package/dist/types/utils/ensureMongoDocumentToObject.d.ts.map +1 -0
- package/dist/types/utils/errors/ErrorHandler.d.ts.map +1 -1
- package/dist/types/utils/errors/errorCodes.d.ts +104 -0
- package/dist/types/utils/errors/errorCodes.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts +2 -0
- package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts +24 -0
- package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts.map +1 -0
- package/dist/types/utils/filtersAndPagination/getUserFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/mapper/dictionary.d.ts +1 -1
- package/dist/types/utils/mapper/dictionary.d.ts.map +1 -1
- package/dist/types/utils/mapper/organization.d.ts.map +1 -1
- package/dist/types/utils/mapper/project.d.ts.map +1 -1
- package/dist/types/utils/mapper/tag.d.ts +16 -0
- package/dist/types/utils/mapper/tag.d.ts.map +1 -0
- package/dist/types/utils/mapper/user.d.ts +2 -2
- package/dist/types/utils/mapper/user.d.ts.map +1 -1
- package/dist/types/utils/removeObjectKeys.d.ts +2 -0
- package/dist/types/utils/removeObjectKeys.d.ts.map +1 -0
- package/dist/types/utils/validation/validateProject.d.ts.map +1 -1
- package/dist/types/utils/validation/validateTag.d.ts +16 -0
- package/dist/types/utils/validation/validateTag.d.ts.map +1 -0
- package/package.json +6 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/dictionary.service.ts"],"sourcesContent":["import { DictionaryModel } from '@models/dictionary.model';\nimport { GenericError } from '@utils/errors';\nimport type { DictionaryFilters } from '@utils/filtersAndPagination/getDictionaryFiltersAndPagination';\nimport {\n type DictionaryFields,\n validateDictionary,\n} from '@utils/validation/validateDictionary';\nimport type { ObjectId } from 'mongoose';\nimport type {\n Dictionary,\n DictionaryData,\n DictionaryDocument,\n} from '@/types/dictionary.types';\n\n/**\n * Finds dictionaries based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of dictionaries matching the filters.\n */\nexport const findDictionaries = async (\n filters: DictionaryFilters,\n skip = 0,\n limit = 100\n): Promise<DictionaryDocument[]> =>\n await DictionaryModel.find(filters).skip(skip).limit(limit);\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryId - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\nexport const getDictionaryById = async (\n dictionaryId: string | ObjectId\n): Promise<DictionaryDocument> => {\n const dictionary = await DictionaryModel.findById(dictionaryId);\n\n if (!dictionary) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return dictionary;\n};\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryKey - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\nexport const getDictionaryByKey = async (\n dictionaryKey: string,\n projectId: string | ObjectId\n): Promise<DictionaryDocument> => {\n const dictionary = await DictionaryModel.findOne({\n key: dictionaryKey,\n projectIds: projectId,\n });\n\n if (!dictionary) {\n throw new GenericError('DICTIONARY_NOT_FOUND', {\n dictionaryKey,\n projectId,\n });\n }\n\n return dictionary;\n};\n\nexport const getDictionariesByKeys = async (\n dictionaryKey: string[],\n projectId: string | ObjectId\n): Promise<DictionaryDocument[]> => {\n const dictionaries = await DictionaryModel.find({\n key: dictionaryKey,\n projectIds: projectId,\n });\n\n return dictionaries;\n};\n\nexport const getDictionariesKeys = async (\n projectId: string | ObjectId\n): Promise<string[]> => {\n const dictionaries = await DictionaryModel.find({\n projectIds: projectId,\n }).select('key');\n\n return dictionaries.map((dictionary) => dictionary.key);\n};\n\n/**\n * Counts the total number of dictionaries that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of dictionaries.\n */\nexport const countDictionaries = async (\n filters: DictionaryFilters\n): Promise<number> => {\n const result = await DictionaryModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('DICTIONARY_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new dictionary in the database.\n * @param dictionary - The dictionary data to create.\n * @returns The created dictionary.\n */\nexport const createDictionary = async (\n dictionary: DictionaryData\n): Promise<DictionaryDocument> => {\n const errors = await validateDictionary(dictionary);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n errors,\n });\n }\n\n return await DictionaryModel.create(dictionary);\n};\n\ntype GetExistingDictionaryResult = {\n existingDictionariesKey: string[];\n newDictionariesKey: string[];\n};\n\n/**\n * Gets the existing dictionaries from the provided list of keys.\n * @param dictionariesKeys - List of dictionary keys to check.\n * @param projectId - The ID of the project to check the dictionaries against.\n * @returns The existing dictionaries and the new dictionaries.\n */\nexport const getExistingDictionaryKey = async (\n dictionariesKeys: string[],\n projectId: string | ObjectId\n): Promise<GetExistingDictionaryResult> => {\n // Fetch dictionaries from the database where the key is in the provided list\n const existingDictionaries = await DictionaryModel.find({\n key: { $in: dictionariesKeys },\n projectIds: projectId,\n });\n\n // Map existing dictionaries to a LocalDictionary object\n const existingDictionariesKey: string[] = [];\n const newDictionariesKey: string[] = [];\n\n for (const key of dictionariesKeys) {\n const isDictionaryExist = existingDictionaries.some(\n (dictionary) => dictionary.key === key\n );\n\n if (isDictionaryExist) {\n existingDictionariesKey.push(key);\n } else {\n newDictionariesKey.push(key);\n }\n }\n\n return { existingDictionariesKey, newDictionariesKey };\n};\n\n/**\n * Updates an existing dictionary in the database by its ID.\n * @param dictionaryId - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryById = async (\n dictionaryId: string | ObjectId,\n dictionary: Partial<Dictionary>\n): Promise<DictionaryDocument> => {\n const updatedKeys = Object.keys(dictionary) as DictionaryFields;\n const errors = validateDictionary(dictionary, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n dictionaryId,\n errors,\n });\n }\n\n const existingDictionary = await getDictionaryById(dictionaryId);\n\n const result = await DictionaryModel.updateOne(\n { _id: dictionaryId },\n { ...dictionary, content: [existingDictionary.content, dictionary.content] }\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryId });\n }\n\n return await getDictionaryById(dictionaryId);\n};\n\n/**\n * Updates an existing dictionary in the database by its key.\n * @param dictionaryKey - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryByKey = async (\n dictionaryKey: string,\n dictionary: Partial<Dictionary>,\n projectId: string | ObjectId\n): Promise<DictionaryDocument> => {\n const updatedKeys = Object.keys(dictionary) as DictionaryFields;\n const errors = validateDictionary(dictionary, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n dictionaryKey,\n projectId,\n errors,\n });\n }\n\n const existingDictionary = await getDictionaryByKey(dictionaryKey, projectId);\n\n const result = await DictionaryModel.updateOne(\n { key: dictionaryKey, projectIds: projectId },\n { ...dictionary, content: [existingDictionary.content, dictionary.content] }\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryKey });\n }\n\n return await getDictionaryByKey(dictionaryKey, projectId);\n};\n\n/**\n * Deletes a dictionary from the database by its ID.\n * @param dictionaryId - The ID of the dictionary to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteDictionaryById = async (\n dictionaryId: string\n): Promise<DictionaryDocument> => {\n const dictionary = await DictionaryModel.findByIdAndDelete(dictionaryId);\n\n if (!dictionary) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return dictionary;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAgC;AAChC,oBAA6B;AAE7B,gCAGO;AAeA,MAAM,mBAAmB,OAC9B,SACA,OAAO,GACP,QAAQ,QAER,MAAM,kCAAgB,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,KAAK;AAOrD,MAAM,oBAAoB,OAC/B,iBACgC;AAChC,QAAM,aAAa,MAAM,kCAAgB,SAAS,YAAY;AAE9D,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,2BAAa,wBAAwB,EAAE,aAAa,CAAC;AAAA,EACjE;AAEA,SAAO;AACT;AAOO,MAAM,qBAAqB,OAChC,eACA,cACgC;AAChC,QAAM,aAAa,MAAM,kCAAgB,QAAQ;AAAA,IAC/C,KAAK;AAAA,IACL,YAAY;AAAA,EACd,CAAC;AAED,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,2BAAa,wBAAwB;AAAA,MAC7C;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AAEO,MAAM,wBAAwB,OACnC,eACA,cACkC;AAClC,QAAM,eAAe,MAAM,kCAAgB,KAAK;AAAA,IAC9C,KAAK;AAAA,IACL,YAAY;AAAA,EACd,CAAC;AAED,SAAO;AACT;AAEO,MAAM,sBAAsB,OACjC,cACsB;AACtB,QAAM,eAAe,MAAM,kCAAgB,KAAK;AAAA,IAC9C,YAAY;AAAA,EACd,CAAC,EAAE,OAAO,KAAK;AAEf,SAAO,aAAa,IAAI,CAAC,eAAe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M,kCAAgB;AAAA,IACnC,EAAE,KAAK,aAAa;AAAA,IACpB,EAAE,GAAG,YAAY,SAAS,CAAC,mBAAmB,SAAS,WAAW,OAAO,EAAE;AAAA,EAC7E;AAEA,MAAI,OAAO,iBAAiB,GAAG;AAC7B,UAAM,IAAI,2BAAa,4BAA4B,EAAE,aAAa,CAAC;AAAA,EACrE;AAEA,SAAO,MAAM,kBAAkB,YAAY;AAC7C;AAQO,MAAM,wBAAwB,OACnC,eACA,YACA,cACgC;AAChC,QAAM,cAAc,OAAO,KAAK,UAAU;AAC1C,QAAM,aAAS,8CAAmB,YAAY,WAAW;AAEzD,MAAI,OAAO,KAAK,MAAM,EAAE,SAAS,GAAG;AAClC,UAAM,IAAI,2BAAa,6BAA6B;AAAA,MAClD;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,qBAAqB,MAAM,mBAAmB,eAAe,SAAS;AAE5E,QAAM,SAAS,MAAM,kCAAgB;AAAA,IACnC,EAAE,KAAK,eAAe,YAAY,UAAU;AAAA,IAC5C,EAAE,GAAG,YAAY,SAAS,CAAC,mBAAmB,SAAS,WAAW,OAAO,EAAE;AAAA,EAC7E;AAEA,MAAI,OAAO,iBAAiB,GAAG;AAC7B,UAAM,IAAI,2BAAa,4BAA4B,EAAE,cAAc,CAAC;AAAA,EACtE;AAEA,SAAO,MAAM,mBAAmB,eAAe,SAAS;AAC1D;AAOO,MAAM,uBAAuB,OAClC,iBACgC;AAChC,QAAM,aAAa,MAAM,kCAAgB,kBAAkB,YAAY;AAEvE,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,2BAAa,wBAAwB,EAAE,aAAa,CAAC;AAAA,EACjE;AAEA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/services/dictionary.service.ts"],"sourcesContent":["import { DictionaryModel } from '@models/dictionary.model';\nimport { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport { GenericError } from '@utils/errors';\nimport type { DictionaryFilters } from '@utils/filtersAndPagination/getDictionaryFiltersAndPagination';\nimport { removeObjectKeys } from '@utils/removeObjectKeys';\nimport {\n type DictionaryFields,\n validateDictionary,\n} from '@utils/validation/validateDictionary';\nimport { ObjectId } from 'mongoose';\nimport type {\n Dictionary,\n DictionaryData,\n DictionaryDocument,\n} from '@/types/dictionary.types';\nimport type { Project } from '@/types/project.types';\n\n/**\n * Finds dictionaries based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of dictionaries matching the filters.\n */\nexport const findDictionaries = async (\n filters: DictionaryFilters,\n skip = 0,\n limit = 100\n): Promise<DictionaryDocument[]> => {\n try {\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the filters\n { $match: filters },\n\n // Stage 2: Skip for pagination\n { $skip: skip },\n\n // Stage 3: Limit the number of documents\n { $limit: limit },\n\n // Stage 4: Add the 'availableVersions' field\n {\n $addFields: {\n availableVersions: {\n $map: {\n input: { $objectToArray: '$content' },\n as: 'version',\n in: '$$version.k',\n },\n },\n },\n },\n\n // (Optional) Stage 5: Project the fields you want to include/exclude\n // For example, to exclude the entire 'content' field and keep only 'availableVersions'\n // {\n // $project: {\n // content: 0 // Exclude the 'content' field\n // }\n // }\n ]);\n\n return dictionaries;\n } catch (error) {\n console.error('Error fetching dictionaries:', error);\n throw error;\n }\n};\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryId - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\n/**\n * Finds a dictionary by its ID and includes the 'availableVersions' field.\n * @param dictionaryId - The ID of the dictionary to find.\n * @returns The dictionary matching the ID with available versions.\n */\nexport const getDictionaryById = async (\n dictionaryId: string | ObjectId\n): Promise<DictionaryDocument> => {\n const dictionary = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the document by ID\n { $match: { _id: dictionaryId } },\n\n // Stage 2: Add the 'availableVersions' field\n {\n $addFields: {\n availableVersions: {\n $map: {\n input: { $objectToArray: '$content' },\n as: 'version',\n in: '$$version.k',\n },\n },\n },\n },\n ]);\n\n if (!dictionary.length) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return dictionary[0];\n};\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryKey - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\nexport const getDictionaryByKey = async (\n dictionaryKey: string,\n projectId: string | ObjectId\n): Promise<DictionaryDocument> => {\n const dictionaries = await getDictionariesByKeys([dictionaryKey], projectId);\n\n console.log('dictionaries', dictionaries);\n\n return dictionaries[0];\n};\n\nexport const getDictionariesByKeys = async (\n dictionaryKeys: string[],\n projectId: string | ObjectId\n): Promise<DictionaryDocument[]> => {\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the document by key\n { $match: { key: { $in: dictionaryKeys }, projectIds: projectId } },\n\n // Stage 2: Add the 'availableVersions' field\n {\n $addFields: {\n availableVersions: {\n $map: {\n input: { $objectToArray: '$content' },\n as: 'version',\n in: '$$version.k',\n },\n },\n },\n },\n ]);\n\n if (!dictionaries) {\n throw new GenericError('DICTIONARY_NOT_FOUND', {\n dictionaryKeys,\n projectId,\n });\n }\n\n return dictionaries;\n};\n\nexport const getDictionariesKeys = async (\n projectId: string | ObjectId\n): Promise<string[]> => {\n const dictionaries = await DictionaryModel.find({\n projectIds: projectId,\n }).select('key');\n\n return dictionaries.map((dictionary) => dictionary.key);\n};\n\nexport const getDictionariesByTags = async (\n tags: string[],\n projectId: string | Project['_id']\n): Promise<DictionaryDocument[]> => {\n const dictionaries = await DictionaryModel.aggregate<DictionaryDocument>([\n // Stage 1: Match the document by tags\n {\n $match: {\n tags: { $in: tags },\n projectIds: projectId,\n },\n },\n\n // Stage 2: Add the 'availableVersions' field\n {\n $addFields: {\n availableVersions: {\n $map: {\n input: { $objectToArray: '$content' },\n as: 'version',\n in: '$$version.k',\n },\n },\n },\n },\n ]);\n\n return dictionaries;\n};\n\n/**\n * Counts the total number of dictionaries that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of dictionaries.\n */\nexport const countDictionaries = async (\n filters: DictionaryFilters\n): Promise<number> => {\n const result = await DictionaryModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('DICTIONARY_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new dictionary in the database.\n * @param dictionary - The dictionary data to create.\n * @returns The created dictionary.\n */\nexport const createDictionary = async (\n dictionary: DictionaryData\n): Promise<DictionaryDocument> => {\n const errors = await validateDictionary(dictionary);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n errors,\n });\n }\n\n return await DictionaryModel.create(dictionary);\n};\n\ntype GetExistingDictionaryResult = {\n existingDictionariesKey: string[];\n newDictionariesKey: string[];\n};\n\n/**\n * Gets the existing dictionaries from the provided list of keys.\n * @param dictionariesKeys - List of dictionary keys to check.\n * @param projectId - The ID of the project to check the dictionaries against.\n * @returns The existing dictionaries and the new dictionaries.\n */\nexport const getExistingDictionaryKey = async (\n dictionariesKeys: string[],\n projectId: string | ObjectId\n): Promise<GetExistingDictionaryResult> => {\n // Fetch dictionaries from the database where the key is in the provided list\n const existingDictionaries = await DictionaryModel.find({\n key: { $in: dictionariesKeys },\n projectIds: projectId,\n });\n\n // Map existing dictionaries to a LocalDictionary object\n const existingDictionariesKey: string[] = [];\n const newDictionariesKey: string[] = [];\n\n for (const key of dictionariesKeys) {\n const isDictionaryExist = existingDictionaries.some(\n (dictionary) => dictionary.key === key\n );\n\n if (isDictionaryExist) {\n existingDictionariesKey.push(key);\n } else {\n newDictionariesKey.push(key);\n }\n }\n\n return { existingDictionariesKey, newDictionariesKey };\n};\n\n/**\n * Updates an existing dictionary in the database by its ID.\n * @param dictionaryId - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryById = async (\n dictionaryId: string | ObjectId,\n dictionary: Partial<Dictionary>\n): Promise<DictionaryDocument> => {\n const dictionaryObject = ensureMongoDocumentToObject(dictionary);\n const dictionaryToUpdate = removeObjectKeys(dictionaryObject, ['_id']);\n\n const updatedKeys = Object.keys(dictionaryToUpdate) as DictionaryFields;\n const errors = await validateDictionary(dictionaryToUpdate, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n dictionaryId,\n errors,\n });\n }\n\n const result = await DictionaryModel.updateOne(\n { _id: dictionaryId },\n dictionaryToUpdate\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryId });\n }\n\n const updatedDictionary = await getDictionaryById(dictionaryId);\n\n return updatedDictionary;\n};\n\n/**\n * Updates an existing dictionary in the database by its key.\n * @param dictionaryKey - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryByKey = async (\n dictionaryKey: string,\n dictionary: Partial<Dictionary>,\n projectId: string | ObjectId\n): Promise<DictionaryDocument> => {\n const dictionaryObject = ensureMongoDocumentToObject(dictionary);\n\n const dictionaryToUpdate = removeObjectKeys(dictionaryObject, ['_id']);\n\n const updatedKeys = Object.keys(dictionaryToUpdate) as DictionaryFields;\n const errors = await validateDictionary(dictionaryToUpdate, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n dictionaryKey,\n projectId,\n errors,\n });\n }\n\n const result = await DictionaryModel.updateOne(\n { key: dictionaryKey, projectIds: projectId },\n dictionaryToUpdate\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryKey });\n }\n\n const updatedDictionary = await getDictionaryByKey(dictionaryKey, projectId);\n\n return updatedDictionary;\n};\n\n/**\n * Deletes a dictionary from the database by its ID.\n * @param dictionaryId - The ID of the dictionary to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteDictionaryById = async (\n dictionaryId: string\n): Promise<DictionaryDocument> => {\n const dictionary = await DictionaryModel.findByIdAndDelete(dictionaryId);\n\n if (!dictionary) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return dictionary;\n};\n\nexport const incrementVersion = (dictionary: Dictionary): string => {\n const VERSION_PREFIX = 'v';\n const availableVersions = dictionary.availableVersions ?? [];\n\n // Get the current version from the version list, default to 'v1' if not present\n const currentVersion =\n availableVersions.length > 0\n ? availableVersions[availableVersions.length - 1]\n : 'v1';\n\n // Function to extract the numeric part of the version\n const getVersionNumber = (version: string): number => {\n const match = version.match(/^v(\\d+)$/);\n if (!match) {\n throw new Error(`Invalid version format: ${version}`);\n }\n return parseInt(match[1], 10);\n };\n\n // Start with the next version number\n let newNumber = getVersionNumber(currentVersion) + 1;\n let newVersion = `${VERSION_PREFIX}${newNumber}`;\n\n // Loop until a unique version is found\n while (availableVersions.includes(newVersion)) {\n newNumber += 1;\n newVersion = `${VERSION_PREFIX}${newNumber}`;\n }\n\n return newVersion;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAgC;AAChC,yCAA4C;AAC5C,oBAA6B;AAE7B,8BAAiC;AACjC,gCAGO;AAgBA,MAAM,mBAAmB,OAC9B,SACA,OAAO,GACP,QAAQ,QAC0B;AAClC,MAAI;AACF,UAAM,eAAe,MAAM,kCAAgB,UAA8B;AAAA;AAAA,MAEvE,EAAE,QAAQ,QAAQ;AAAA;AAAA,MAGlB,EAAE,OAAO,KAAK;AAAA;AAAA,MAGd,EAAE,QAAQ,MAAM;AAAA;AAAA,MAGhB;AAAA,QACE,YAAY;AAAA,UACV,mBAAmB;AAAA,YACjB,MAAM;AAAA,cACJ,OAAO,EAAE,gBAAgB,WAAW;AAA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
|
var import_project = require('./../models/project.model.cjs');
|
|
30
|
+
var import_ensureMongoDocumentToObject = require('./../utils/ensureMongoDocumentToObject.cjs');
|
|
30
31
|
var import_errors = require('./../utils/errors/index.cjs');
|
|
32
|
+
var import_removeObjectKeys = require('./../utils/removeObjectKeys.cjs');
|
|
31
33
|
var import_validateProject = require('./../utils/validation/validateProject.cjs');
|
|
32
34
|
const findProjects = async (filters, skip = 0, limit = 100) => await import_project.ProjectModel.find(filters).skip(skip).limit(limit);
|
|
33
35
|
const getProjectById = async (projectId) => {
|
|
@@ -55,10 +57,13 @@ const createProject = async (project) => {
|
|
|
55
57
|
return await import_project.ProjectModel.create(project);
|
|
56
58
|
};
|
|
57
59
|
const updateProjectById = async (projectId, project) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
const projectObject = (0, import_ensureMongoDocumentToObject.ensureMongoDocumentToObject)(project);
|
|
61
|
+
const projectToUpdate = (0, import_removeObjectKeys.removeObjectKeys)(projectObject, [
|
|
62
|
+
"_id",
|
|
63
|
+
"oAuth2Access",
|
|
64
|
+
"organizationId"
|
|
65
|
+
]);
|
|
66
|
+
const updatedKeys = Object.keys(projectToUpdate);
|
|
62
67
|
const errors = (0, import_validateProject.validateProject)(project, updatedKeys);
|
|
63
68
|
if (Object.keys(errors).length > 0) {
|
|
64
69
|
throw new import_errors.GenericError("PROJECT_INVALID_FIELDS", {
|
|
@@ -66,7 +71,11 @@ const updateProjectById = async (projectId, project) => {
|
|
|
66
71
|
errors
|
|
67
72
|
});
|
|
68
73
|
}
|
|
69
|
-
|
|
74
|
+
console.log("projectToUpdate", projectToUpdate);
|
|
75
|
+
const result = await import_project.ProjectModel.updateOne(
|
|
76
|
+
{ _id: projectId },
|
|
77
|
+
projectToUpdate
|
|
78
|
+
);
|
|
70
79
|
if (result.matchedCount === 0) {
|
|
71
80
|
throw new import_errors.GenericError("PROJECT_UPDATE_FAILED", { projectId });
|
|
72
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/project.service.ts"],"sourcesContent":["import { ProjectModel } from '@models/project.model';\nimport { GenericError } from '@utils/errors';\nimport type { ProjectFilters } from '@utils/filtersAndPagination/getProjectFiltersAndPagination';\nimport {\n type ProjectFields,\n validateProject,\n} from '@utils/validation/validateProject';\nimport type { ObjectId } from 'mongoose';\nimport type {\n Project,\n ProjectData,\n ProjectDocument,\n} from '@/types/project.types';\n\n/**\n * Finds projects based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of projects matching the filters.\n */\nexport const findProjects = async (\n filters: ProjectFilters,\n skip = 0,\n limit = 100\n): Promise<ProjectDocument[]> =>\n await ProjectModel.find(filters).skip(skip).limit(limit);\n\n/**\n * Finds a project by its ID.\n * @param projectId - The ID of the project to find.\n * @returns The project matching the ID.\n */\nexport const getProjectById = async (\n projectId: string | ObjectId\n): Promise<ProjectDocument> => {\n const project = await ProjectModel.findById(projectId);\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_DEFINED', { projectId });\n }\n\n return project;\n};\n\n/**\n * Counts the total number of projects that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of projects.\n */\nexport const countProjects = async (\n filters: ProjectFilters\n): Promise<number> => {\n const result = await ProjectModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('PROJECT_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new project in the database.\n * @param project - The project data to create.\n * @returns The created project.\n */\nexport const createProject = async (\n project: ProjectData\n): Promise<ProjectDocument> => {\n if ((project as Partial<Project>).oAuth2Access) {\n delete (project as Partial<Project>).oAuth2Access;\n }\n\n const errors = await validateProject(project, ['name']);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('PROJECT_INVALID_FIELDS', { errors });\n }\n\n return await ProjectModel.create(project);\n};\n\n/**\n * Updates an existing project in the database by its ID.\n * @param projectId - The ID of the project to update.\n * @param project - The updated project data.\n * @returns The updated project.\n */\nexport const updateProjectById = async (\n projectId: string | ObjectId,\n project: Partial<Project>\n): Promise<ProjectDocument> => {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/services/project.service.ts"],"sourcesContent":["import { ProjectModel } from '@models/project.model';\nimport { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport { GenericError } from '@utils/errors';\nimport type { ProjectFilters } from '@utils/filtersAndPagination/getProjectFiltersAndPagination';\nimport { removeObjectKeys } from '@utils/removeObjectKeys';\nimport {\n type ProjectFields,\n validateProject,\n} from '@utils/validation/validateProject';\nimport type { ObjectId } from 'mongoose';\nimport type {\n Project,\n ProjectData,\n ProjectDocument,\n} from '@/types/project.types';\n\n/**\n * Finds projects based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of projects matching the filters.\n */\nexport const findProjects = async (\n filters: ProjectFilters,\n skip = 0,\n limit = 100\n): Promise<ProjectDocument[]> =>\n await ProjectModel.find(filters).skip(skip).limit(limit);\n\n/**\n * Finds a project by its ID.\n * @param projectId - The ID of the project to find.\n * @returns The project matching the ID.\n */\nexport const getProjectById = async (\n projectId: string | ObjectId\n): Promise<ProjectDocument> => {\n const project = await ProjectModel.findById(projectId);\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_DEFINED', { projectId });\n }\n\n return project;\n};\n\n/**\n * Counts the total number of projects that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of projects.\n */\nexport const countProjects = async (\n filters: ProjectFilters\n): Promise<number> => {\n const result = await ProjectModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('PROJECT_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new project in the database.\n * @param project - The project data to create.\n * @returns The created project.\n */\nexport const createProject = async (\n project: ProjectData\n): Promise<ProjectDocument> => {\n if ((project as Partial<Project>).oAuth2Access) {\n delete (project as Partial<Project>).oAuth2Access;\n }\n\n const errors = await validateProject(project, ['name']);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('PROJECT_INVALID_FIELDS', { errors });\n }\n\n return await ProjectModel.create(project);\n};\n\n/**\n * Updates an existing project in the database by its ID.\n * @param projectId - The ID of the project to update.\n * @param project - The updated project data.\n * @returns The updated project.\n */\nexport const updateProjectById = async (\n projectId: string | ObjectId,\n project: Partial<Project>\n): Promise<ProjectDocument> => {\n const projectObject = ensureMongoDocumentToObject(project);\n const projectToUpdate = removeObjectKeys(projectObject, [\n '_id',\n 'oAuth2Access',\n 'organizationId',\n ]);\n\n const updatedKeys = Object.keys(projectToUpdate) as ProjectFields;\n\n const errors = validateProject(project, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('PROJECT_INVALID_FIELDS', {\n projectId,\n errors,\n });\n }\n\n console.log('projectToUpdate', projectToUpdate);\n\n const result = await ProjectModel.updateOne(\n { _id: projectId },\n projectToUpdate\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('PROJECT_UPDATE_FAILED', { projectId });\n }\n\n return await getProjectById(projectId);\n};\n\n/**\n * Deletes a project from the database by its ID.\n * @param projectId - The ID of the project to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteProjectById = async (\n projectId: string | ObjectId\n): Promise<ProjectDocument> => {\n const project = await ProjectModel.findByIdAndDelete(projectId);\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_DEFINED', { projectId });\n }\n\n return project;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA6B;AAC7B,yCAA4C;AAC5C,oBAA6B;AAE7B,8BAAiC;AACjC,6BAGO;AAeA,MAAM,eAAe,OAC1B,SACA,OAAO,GACP,QAAQ,QAER,MAAM,4BAAa,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,KAAK;AAOlD,MAAM,iBAAiB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AU,CAAC;AAAA,EAC/D;AAEA,SAAO,MAAM,eAAe,SAAS;AACvC;AAOO,MAAM,oBAAoB,OAC/B,cAC6B;AAC7B,QAAM,UAAU,MAAM,4BAAa,kBAAkB,SAAS;AAE9D,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,2BAAa,uBAAuB,EAAE,UAAU,CAAC;AAAA,EAC7D;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var tag_service_exports = {};
|
|
20
|
+
__export(tag_service_exports, {
|
|
21
|
+
countTags: () => countTags,
|
|
22
|
+
createTag: () => createTag,
|
|
23
|
+
deleteTagById: () => deleteTagById,
|
|
24
|
+
findTags: () => findTags,
|
|
25
|
+
getTagById: () => getTagById,
|
|
26
|
+
getTagsByKeys: () => getTagsByKeys,
|
|
27
|
+
updateTagById: () => updateTagById
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(tag_service_exports);
|
|
30
|
+
var import_tag = require('./../models/tag.model.cjs');
|
|
31
|
+
var import_errors = require('./../utils/errors/index.cjs');
|
|
32
|
+
var import_validateTag = require('./../utils/validation/validateTag.cjs');
|
|
33
|
+
const findTags = async (filters, skip = 0, limit = 100) => await import_tag.TagModel.find(filters).skip(skip).limit(limit);
|
|
34
|
+
const getTagById = async (tagId) => {
|
|
35
|
+
const tag = await import_tag.TagModel.findById(tagId);
|
|
36
|
+
if (!tag) {
|
|
37
|
+
throw new import_errors.GenericError("TAG_NOT_FOUND", { tagId });
|
|
38
|
+
}
|
|
39
|
+
return tag;
|
|
40
|
+
};
|
|
41
|
+
const getTagsByKeys = async (keys, organizationId) => {
|
|
42
|
+
const tags = await import_tag.TagModel.find({ key: { $in: keys }, organizationId });
|
|
43
|
+
return tags;
|
|
44
|
+
};
|
|
45
|
+
const countTags = async (filters) => {
|
|
46
|
+
const result = await import_tag.TagModel.countDocuments(filters);
|
|
47
|
+
if (typeof result === "undefined") {
|
|
48
|
+
throw new import_errors.GenericError("TAG_COUNT_FAILED", { filters });
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
const createTag = async (tag) => {
|
|
53
|
+
const errors = await (0, import_validateTag.validateTag)(tag, ["key"]);
|
|
54
|
+
if (Object.keys(errors).length > 0) {
|
|
55
|
+
throw new import_errors.GenericError("TAG_INVALID_FIELDS", { errors });
|
|
56
|
+
}
|
|
57
|
+
return await import_tag.TagModel.create(tag);
|
|
58
|
+
};
|
|
59
|
+
const updateTagById = async (tagId, tag) => {
|
|
60
|
+
const updatedKeys = Object.keys(tag);
|
|
61
|
+
const errors = (0, import_validateTag.validateTag)(tag, updatedKeys);
|
|
62
|
+
if (Object.keys(errors).length > 0) {
|
|
63
|
+
throw new import_errors.GenericError("TAG_INVALID_FIELDS", {
|
|
64
|
+
tagId,
|
|
65
|
+
errors
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const result = await import_tag.TagModel.updateOne({ _id: tagId }, tag);
|
|
69
|
+
if (result.matchedCount === 0) {
|
|
70
|
+
throw new import_errors.GenericError("TAG_UPDATE_FAILED", { tagId });
|
|
71
|
+
}
|
|
72
|
+
return await getTagById(tagId);
|
|
73
|
+
};
|
|
74
|
+
const deleteTagById = async (tagId) => {
|
|
75
|
+
const tag = await import_tag.TagModel.findByIdAndDelete(tagId);
|
|
76
|
+
if (!tag) {
|
|
77
|
+
throw new import_errors.GenericError("TAG_NOT_FOUND", { tagId });
|
|
78
|
+
}
|
|
79
|
+
return tag;
|
|
80
|
+
};
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
countTags,
|
|
84
|
+
createTag,
|
|
85
|
+
deleteTagById,
|
|
86
|
+
findTags,
|
|
87
|
+
getTagById,
|
|
88
|
+
getTagsByKeys,
|
|
89
|
+
updateTagById
|
|
90
|
+
});
|
|
91
|
+
//# sourceMappingURL=tag.service.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/tag.service.ts"],"sourcesContent":["import { TagModel } from '@models/tag.model';\nimport { GenericError } from '@utils/errors';\nimport type { TagFilters } from '@utils/filtersAndPagination/getTagFiltersAndPagination';\nimport { type TagFields, validateTag } from '@utils/validation/validateTag';\nimport type { ObjectId } from 'mongoose';\nimport { Organization } from '@/export';\nimport type { Tag, TagData, TagDocument } from '@/types/tag.types';\n\n/**\n * Finds tags based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of tags matching the filters.\n */\nexport const findTags = async (\n filters: TagFilters,\n skip = 0,\n limit = 100\n): Promise<TagDocument[]> =>\n await TagModel.find(filters).skip(skip).limit(limit);\n\n/**\n * Finds a tag by its ID.\n * @param tagId - The ID of the tag to find.\n * @returns The tag matching the ID.\n */\nexport const getTagById = async (\n tagId: string | ObjectId\n): Promise<TagDocument> => {\n const tag = await TagModel.findById(tagId);\n\n if (!tag) {\n throw new GenericError('TAG_NOT_FOUND', { tagId });\n }\n\n return tag;\n};\n\nexport const getTagsByKeys = async (\n keys: string[],\n organizationId: string | Organization['_id']\n): Promise<TagDocument[]> => {\n const tags = await TagModel.find({ key: { $in: keys }, organizationId });\n\n return tags;\n};\n\n/**\n * Counts the total number of tags that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of tags.\n */\nexport const countTags = async (filters: TagFilters): Promise<number> => {\n const result = await TagModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('TAG_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new tag in the database.\n * @param tag - The tag data to create.\n * @returns The created tag.\n */\nexport const createTag = async (tag: TagData): Promise<TagDocument> => {\n const errors = await validateTag(tag, ['key']);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('TAG_INVALID_FIELDS', { errors });\n }\n\n return await TagModel.create(tag);\n};\n\n/**\n * Updates an existing tag in the database by its ID.\n * @param tagId - The ID of the tag to update.\n * @param tag - The updated tag data.\n * @returns The updated tag.\n */\nexport const updateTagById = async (\n tagId: string | ObjectId,\n tag: Partial<Tag>\n): Promise<TagDocument> => {\n const updatedKeys = Object.keys(tag) as TagFields;\n\n const errors = validateTag(tag, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('TAG_INVALID_FIELDS', {\n tagId,\n errors,\n });\n }\n\n const result = await TagModel.updateOne({ _id: tagId }, tag);\n\n if (result.matchedCount === 0) {\n throw new GenericError('TAG_UPDATE_FAILED', { tagId });\n }\n\n return await getTagById(tagId);\n};\n\n/**\n * Deletes a tag from the database by its ID.\n * @param tagId - The ID of the tag to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteTagById = async (\n tagId: string | ObjectId\n): Promise<TagDocument> => {\n const tag = await TagModel.findByIdAndDelete(tagId);\n\n if (!tag) {\n throw new GenericError('TAG_NOT_FOUND', { tagId });\n }\n\n return tag;\n};\n"],"mappings":";;;;;;;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AAA,EACH;AAEA,QAAM,SAAS,MAAM,oBAAS,UAAU,EAAE,KAAK,MAAM,GAAG,GAAG;AAE3D,MAAI,OAAO,iBAAiB,GAAG;AAC7B,UAAM,IAAI,2BAAa,qBAAqB,EAAE,MAAM,CAAC;AAAA,EACvD;AAEA,SAAO,MAAM,WAAW,KAAK;AAC/B;AAOO,MAAM,gBAAgB,OAC3B,UACyB;AACzB,QAAM,MAAM,MAAM,oBAAS,kBAAkB,KAAK;AAElD,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,2BAAa,iBAAiB,EAAE,MAAM,CAAC;AAAA,EACnD;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/dictionary.types.ts"],"sourcesContent":["import type { DictionaryValue } from '@intlayer/core';\nimport type { Model, ObjectId, Document } from 'mongoose';\nimport type { Project } from './project.types';\nimport type { User } from './user.types';\n\nexport type DictionaryCreationData = {\n projectIds: (Project['_id'] | string)[];\n key: string;\n content?: DictionaryValue;\n title?: string;\n description?: string;\n
|
|
1
|
+
{"version":3,"sources":["../../../src/types/dictionary.types.ts"],"sourcesContent":["import type { DictionaryValue } from '@intlayer/core';\nimport type { Model, ObjectId, Document } from 'mongoose';\nimport type { Project } from './project.types';\nimport type { User } from './user.types';\n\nexport type DictionaryCreationData = {\n projectIds: (Project['_id'] | string)[];\n key: string;\n content?: DictionaryValue;\n title?: string;\n description?: string;\n tags?: string[];\n filePath?: string;\n};\n\nexport type VersionedContentEl = {\n name?: string;\n description?: string;\n content: DictionaryValue;\n};\n\nexport type ContentVersion = string;\nexport type VersionedContent = Record<string, VersionedContentEl>;\n\nexport type DictionaryData = {\n key: string;\n content: VersionedContent;\n projectIds: (Project['_id'] | string)[];\n creatorId: User['_id'];\n title?: string;\n description?: string;\n tags?: string[];\n filePath?: Record<string, string>;\n publishedVersion?: string | null;\n};\n\nexport type Dictionary = DictionaryData & {\n _id: ObjectId;\n createdAt: number;\n updatedAt: number;\n availableVersions?: string[];\n};\n\nexport type DictionaryAPI = Omit<Dictionary, 'filePath' | 'content'> & {\n content: DictionaryValue;\n filePath?: string;\n availableVersions?: string[];\n};\n\nexport type DictionaryDocument = Document<unknown, {}, Dictionary> & Dictionary;\nexport type DictionaryModelType = Model<Dictionary>;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/project.types.ts"],"sourcesContent":["import type { Model, ObjectId, Document } from 'mongoose';\nimport type { Organization } from './organization.types';\nimport type { User } from './user.types';\n\nexport type ProjectCreationData = {\n name: Project['name'];\n};\n\nexport type ProjectData = {\n organizationId: Organization['_id'];\n name: string;\n membersIds: User['_id'][];\n adminsIds: User['_id'][];\n creatorId: User['_id'];\n};\n\nexport type Rights = {\n read: boolean;\n write: boolean;\n admin: boolean;\n};\n\nexport type TokenRights = {\n dictionary: Rights;\n project: Rights;\n organization: Rights;\n};\n\nexport type AccessKeyData = {\n name: string;\n rights: TokenRights;\n expiresAt?: Date;\n};\n\nexport type OAuth2AccessData = AccessKeyData & {\n clientId: string;\n clientSecret: string;\n accessToken: string[];\n userId: User['_id'];\n};\n\nexport type OAuth2Access = OAuth2AccessData & {\n _id: ObjectId;\n createdAt: number;\n updatedAt: number;\n};\n\nexport type Project = ProjectData & {\n _id: ObjectId;\n createdAt: number;\n updatedAt: number;\n oAuth2Access: OAuth2Access[];\n};\n\nexport type ProjectAPI = Omit<Project, 'adminsIds'> & {\n adminsIds?: User['_id'][];\n};\n\nexport type ProjectDocument = Document<unknown, {}, Project> & Project;\n\nexport type ProjectModelType = Model<Project>;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/types/project.types.ts"],"sourcesContent":["import { Locales } from 'intlayer';\nimport type { Model, ObjectId, Document } from 'mongoose';\nimport type { Organization } from './organization.types';\nimport type { User } from './user.types';\n\nexport type ProjectCreationData = {\n name: Project['name'];\n};\n\nexport type ProjectData = {\n organizationId: Organization['_id'];\n name: string;\n membersIds: User['_id'][];\n adminsIds: User['_id'][];\n creatorId: User['_id'];\n defaultLocale?: Locales;\n locales?: Locales[];\n};\n\nexport type Rights = {\n read: boolean;\n write: boolean;\n admin: boolean;\n};\n\nexport type TokenRights = {\n dictionary: Rights;\n project: Rights;\n organization: Rights;\n};\n\nexport type AccessKeyData = {\n name: string;\n rights: TokenRights;\n expiresAt?: Date;\n};\n\nexport type OAuth2AccessData = AccessKeyData & {\n clientId: string;\n clientSecret: string;\n accessToken: string[];\n userId: User['_id'];\n};\n\nexport type OAuth2Access = OAuth2AccessData & {\n _id: ObjectId;\n createdAt: number;\n updatedAt: number;\n};\n\nexport type Project = ProjectData & {\n _id: ObjectId;\n createdAt: number;\n updatedAt: number;\n oAuth2Access: OAuth2Access[];\n};\n\nexport type ProjectAPI = Omit<Project, 'adminsIds'> & {\n adminsIds?: User['_id'][];\n};\n\nexport type ProjectDocument = Document<unknown, {}, Project> & Project;\n\nexport type ProjectModelType = Model<Project>;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var tag_types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(tag_types_exports);
|
|
17
|
+
//# sourceMappingURL=tag.types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/types/tag.types.ts"],"sourcesContent":["import type { ObjectId, Document, Model } from 'mongoose';\nimport { Organization } from './organization.types';\nimport { User } from './user.types';\n\nexport type TagCreationData = {\n key: string;\n name?: string;\n description?: string;\n instructions?: string;\n};\n\nexport type TagData = {\n key: string;\n name?: string;\n description?: string;\n instructions?: string;\n creatorId: User['_id'];\n organizationId: Organization['_id'];\n};\n\nexport type Tag = TagData & {\n _id: ObjectId;\n createdAt: number;\n updatedAt: number;\n};\n\nexport type TagAPI = Tag;\n\nexport type TagDocument = Document<unknown, {}, Tag> & Tag;\n\nexport type TagModelType = Model<Tag>;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
```javascript
|
|
2
|
+
const { t, enu } = require("intlayer");
|
|
3
|
+
|
|
4
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
5
|
+
module.exports = {
|
|
6
|
+
key: "my-key",
|
|
7
|
+
content: {
|
|
8
|
+
exampleText: t({
|
|
9
|
+
en: "Example of content in English",
|
|
10
|
+
fr: "Example de contenu en français",
|
|
11
|
+
es: "Ejemplo de contenido en español",
|
|
12
|
+
}),
|
|
13
|
+
numberOfCar: enu({
|
|
14
|
+
"<-1": "Less than minus one car",
|
|
15
|
+
"-1": "Minus one car",
|
|
16
|
+
0: "No cars",
|
|
17
|
+
1: "One car",
|
|
18
|
+
">5": "Some cars",
|
|
19
|
+
">19": "Many cars",
|
|
20
|
+
}),
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
```json
|
|
2
|
+
{
|
|
3
|
+
"key": "my-key",
|
|
4
|
+
"content": {
|
|
5
|
+
"profileText": {
|
|
6
|
+
"NodeType": "translation",
|
|
7
|
+
"translation": {
|
|
8
|
+
"en": "Manage profile",
|
|
9
|
+
"fr": "Gérer le profil",
|
|
10
|
+
"es": "Administrar perfil"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"numberOfCar": {
|
|
14
|
+
"NodeType": "enumeration",
|
|
15
|
+
"enumeration": {
|
|
16
|
+
"<-1": "Less than minus one car",
|
|
17
|
+
"-1": "Minus one car",
|
|
18
|
+
"0": "No cars",
|
|
19
|
+
"1": "One car",
|
|
20
|
+
">5": "Some cars",
|
|
21
|
+
">19": "Many cars"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
```tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { t, enu, type DeclarationContent } from "intlayer";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
key: "my-key",
|
|
7
|
+
content: {
|
|
8
|
+
exampleText: t({
|
|
9
|
+
en: "Example of content in English",
|
|
10
|
+
fr: "Example de contenu en français",
|
|
11
|
+
es: "Ejemplo de contenido en español",
|
|
12
|
+
}),
|
|
13
|
+
exampleOfReactNode: t({
|
|
14
|
+
en: <h1>Example of ReactNode in English</h1>,
|
|
15
|
+
fr: <h1>Example de ReactNode en français</h1>,
|
|
16
|
+
es: <h1>Ejemplo de ReactNode en español</h1>,
|
|
17
|
+
}),
|
|
18
|
+
numberOfCar: enu({
|
|
19
|
+
"<-1": "Less than minus one car",
|
|
20
|
+
"-1": "Minus one car",
|
|
21
|
+
"0": "No cars",
|
|
22
|
+
"1": "One car",
|
|
23
|
+
">5": "Some cars",
|
|
24
|
+
">19": "Many cars",
|
|
25
|
+
}),
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
```javascript
|
|
2
|
+
import { t, enu } from "intlayer";
|
|
3
|
+
|
|
4
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
5
|
+
export default {
|
|
6
|
+
key: "my-key",
|
|
7
|
+
content: {
|
|
8
|
+
exampleText: t({
|
|
9
|
+
en: "Example of content in English",
|
|
10
|
+
fr: "Example de contenu en français",
|
|
11
|
+
es: "Ejemplo de contenido en español",
|
|
12
|
+
}),
|
|
13
|
+
numberOfCar: enu({
|
|
14
|
+
"<-1": "Less than minus one car",
|
|
15
|
+
"-1": "Minus one car",
|
|
16
|
+
0: "No cars",
|
|
17
|
+
1: "One car",
|
|
18
|
+
">5": "Some cars",
|
|
19
|
+
">19": "Many cars",
|
|
20
|
+
}),
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
```
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
You are an expert in internationalization, copy writing and content management. Your task is to audit the content declaration files in the project and identify any potential issues or inconsistencies. Provide a detailed report of any issues found, including the file path, line number, and a brief explanation of the issue.
|
|
2
|
+
|
|
3
|
+
**Instructions:**
|
|
4
|
+
|
|
5
|
+
1. **File Location:**
|
|
6
|
+
|
|
7
|
+
- The content declaration files are located in the `{{filePath}}` directory relative to the project root.
|
|
8
|
+
|
|
9
|
+
2. **Locales:**
|
|
10
|
+
|
|
11
|
+
- Default locale: {{defaultLocale}}
|
|
12
|
+
- Required Locales: {{otherLocales}} (add the missing locales in `t({ ... })` function)
|
|
13
|
+
|
|
14
|
+
3. **Content Declaration Format:**
|
|
15
|
+
|
|
16
|
+
- Example format:
|
|
17
|
+
|
|
18
|
+
{{declarationsContentTemplate}}
|
|
19
|
+
|
|
20
|
+
4. **Audit Requirements:**
|
|
21
|
+
|
|
22
|
+
- **Consistency:** Ensure that all keys have translations for all specified locales.
|
|
23
|
+
- **Missing Content:** Identify any missing translations and specify the expected content.
|
|
24
|
+
- **Misplaced Content:** Detect if any translations are placed under incorrect keys.
|
|
25
|
+
- **Type Compliance:** Verify that the content types match the declarations (e.g., strings, string arrays).
|
|
26
|
+
|
|
27
|
+
5. **Modification Guidelines:**
|
|
28
|
+
|
|
29
|
+
- **Do Not Alter Structure:** If the file structure is correct, do not modify it. Only add, update, or remove content declarations as necessary.
|
|
30
|
+
- **Do Not Change a value type** If a key value is like `exampleKey: "exampleValue"`, avoid a maximum to not change the value type to `exampleKey: t({ en: "exampleValue" })`.
|
|
31
|
+
- **Return Only Final File Content:** Provide the updated file content without any additional comments or explanations.
|
|
32
|
+
- **Ensure No Translations are Missing:** If an element is a multilingual content and a translation is missing, add it. Including localized content as `es-MX` or `en-UK`.
|
|
33
|
+
- **Manage Localizations:** If the required languages contains similar languages, as `en` and `en-GB`, consider `en` as English US and `en-GB` as English UK, and insert or review both translations to maintain clarity and correctness.
|
|
34
|
+
- **Order Translations:** If the translations are not in the same order as the required languages list, consider reordering the translations to maintain clarity and correctness.
|
|
35
|
+
- **Escape Special Characters:** If the translations contain special characters, escape them using the appropriate escape sequence.
|
|
36
|
+
- **Respect the tags instructions:** If the tags instructions are provided, ensure that the audited file adheres to them.
|
|
37
|
+
|
|
38
|
+
6. **Example Scenario:**
|
|
39
|
+
|
|
40
|
+
- **Example 1:**
|
|
41
|
+
|
|
42
|
+
- **Input File:**
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { t, type DeclarationContent } from "intlayer";
|
|
46
|
+
|
|
47
|
+
export default {
|
|
48
|
+
key: "creative-work-structured-data",
|
|
49
|
+
content: {
|
|
50
|
+
audienceType: t({
|
|
51
|
+
en: "Developers, Content Managers",
|
|
52
|
+
fr: "Développeurs, Responsables de contenu",
|
|
53
|
+
es: "Desarrolladores, Gestores de Contenido",
|
|
54
|
+
}),
|
|
55
|
+
},
|
|
56
|
+
} satisfies DeclarationContent;
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
- **Expected Output (No Changes Needed):**
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { t, type DeclarationContent } from "intlayer";
|
|
63
|
+
|
|
64
|
+
export default {
|
|
65
|
+
key: "creative-work-structured-data",
|
|
66
|
+
content: {
|
|
67
|
+
audienceType: t({
|
|
68
|
+
en: "Developers, Content Managers",
|
|
69
|
+
fr: "Développeurs, Responsables de contenu",
|
|
70
|
+
es: "Desarrolladores, Gestores de Contenido",
|
|
71
|
+
}),
|
|
72
|
+
},
|
|
73
|
+
} satisfies DeclarationContent;
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- **Incorrect Output (Unwanted Structural Change):**
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { t, type DeclarationContent } from "intlayer";
|
|
80
|
+
|
|
81
|
+
export default {
|
|
82
|
+
key: "creative-work-structured-data",
|
|
83
|
+
content: {
|
|
84
|
+
audienceType: t({
|
|
85
|
+
en: "Developers, Content Managers",
|
|
86
|
+
fr: "Développeurs, Responsables de contenu",
|
|
87
|
+
es: "Desarrolladores, Gestores de Contenido",
|
|
88
|
+
}),
|
|
89
|
+
// Missing multilingual content for 'projectDescription'
|
|
90
|
+
projectDescription: t({
|
|
91
|
+
en: "This project involves structured data for creative work.",
|
|
92
|
+
fr: "Ce projet implique des données structurées pour le travail créatif.",
|
|
93
|
+
es: "Este proyecto involucra datos estructurados para trabajo creativo.",
|
|
94
|
+
}),
|
|
95
|
+
},
|
|
96
|
+
} satisfies DeclarationContent;
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
- **Clarification:** In this scenario, since the input file is already valid and complete, the expected output should be identical to the input without any additional fields or comments.
|
|
100
|
+
|
|
101
|
+
- **Example 2:**
|
|
102
|
+
|
|
103
|
+
- **Input File:**
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { t } from "react-intlayer";
|
|
107
|
+
|
|
108
|
+
const content = {
|
|
109
|
+
key: "creative-work-structured-data",
|
|
110
|
+
content: {
|
|
111
|
+
audienceType: t({
|
|
112
|
+
en: "Developers, Content Managers",
|
|
113
|
+
es: "Desarrolladores, Gestores de Contenido",
|
|
114
|
+
}),
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
- **Expected Output (No Changes Needed):**
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { t, type DeclarationContent } from "intlayer";
|
|
123
|
+
|
|
124
|
+
const content = {
|
|
125
|
+
key: "creative-work-structured-data",
|
|
126
|
+
content: {
|
|
127
|
+
audienceType: t({
|
|
128
|
+
en: "Developers, Content Managers",
|
|
129
|
+
fr: "Développeurs, Responsables de contenu",
|
|
130
|
+
es: "Desarrolladores, Gestores de Contenido",
|
|
131
|
+
}),
|
|
132
|
+
},
|
|
133
|
+
} satisfies DeclarationContent;
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
- **Clarification:** In this scenario:
|
|
137
|
+
- A missing translation for the `audienceType` key was added.
|
|
138
|
+
- The import of the `t` function was imported from `react-intlayer` instead of `intlayer`.
|
|
139
|
+
- A type `DeclarationContent` was added to the file to strengthen the content declaration.
|
|
140
|
+
|
|
141
|
+
**Tags Instructions:**
|
|
142
|
+
|
|
143
|
+
{{tagsInstructions}}
|
|
144
|
+
|
|
145
|
+
**File to Audit:**
|
|
146
|
+
|
|
147
|
+
{{fileContent}}
|
|
148
|
+
|
|
149
|
+
**Expected Response:**
|
|
150
|
+
|
|
151
|
+
After auditing, provide only the final content of the file as plain text without any Markdown or code block formatting. If no changes are needed, return the file content exactly as it is.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
```tsx
|
|
2
|
+
import React, { type ReactNode } from "react";
|
|
3
|
+
import { t, enu, type DeclarationContent } from "intlayer";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
key: "my-key",
|
|
7
|
+
content: {
|
|
8
|
+
exampleText: t({
|
|
9
|
+
en: "Example of content in English",
|
|
10
|
+
fr: "Example de contenu en français",
|
|
11
|
+
es: "Ejemplo de contenido en español",
|
|
12
|
+
}),
|
|
13
|
+
exampleOfReactNode: t<ReactNode>({
|
|
14
|
+
en: <h1>Example of ReactNode in English</h1>,
|
|
15
|
+
fr: <h1>Example de ReactNode en français</h1>,
|
|
16
|
+
es: <h1>Ejemplo de ReactNode en español</h1>,
|
|
17
|
+
}),
|
|
18
|
+
numberOfCar: enu({
|
|
19
|
+
"<-1": "Less than minus one car",
|
|
20
|
+
"-1": "Minus one car",
|
|
21
|
+
"0": "No cars",
|
|
22
|
+
"1": "One car",
|
|
23
|
+
">5": "Some cars",
|
|
24
|
+
">19": "Many cars",
|
|
25
|
+
}),
|
|
26
|
+
},
|
|
27
|
+
} satisfies DeclarationContent;
|
|
28
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
```typescript
|
|
2
|
+
import { t, enu, type DeclarationContent } from "intlayer";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: "my-key",
|
|
6
|
+
content: {
|
|
7
|
+
exampleText: t({
|
|
8
|
+
en: "Example of content in English",
|
|
9
|
+
fr: "Example de contenu en français",
|
|
10
|
+
es: "Ejemplo de contenido en español",
|
|
11
|
+
}),
|
|
12
|
+
numberOfCar: enu({
|
|
13
|
+
"<-1": "Less than minus one car",
|
|
14
|
+
"-1": "Minus one car",
|
|
15
|
+
"0": "No cars",
|
|
16
|
+
"1": "One car",
|
|
17
|
+
">5": "Some cars",
|
|
18
|
+
">19": "Many cars",
|
|
19
|
+
}),
|
|
20
|
+
},
|
|
21
|
+
} satisfies DeclarationContent;
|
|
22
|
+
```
|