-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle translations collection
- Loading branch information
1 parent
9a1a3a0
commit ad5a3a1
Showing
13 changed files
with
176 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/cli/src/lib/services/collections/translations/collection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { DirectusCollection } from '../base'; | ||
import pino from 'pino'; | ||
import { Inject, Service } from 'typedi'; | ||
import { TranslationsDataLoader } from './data-loader'; | ||
import { TranslationsDataClient } from './data-client'; | ||
import { TranslationsIdMapperClient } from './id-mapper-client'; | ||
import { TranslationsDataDiffer } from './data-differ'; | ||
import { getChildLogger } from '../../../helpers'; | ||
import { TRANSLATIONS_COLLECTION } from './constants'; | ||
import { TranslationsDataMapper } from './data-mapper'; | ||
import { LOGGER } from '../../../constants'; | ||
import { DirectusTranslation } from './interfaces'; | ||
import { ConfigService } from '../../config'; | ||
import { MigrationClient } from '../../migration-client'; | ||
|
||
@Service() | ||
export class TranslationsCollection extends DirectusCollection<DirectusTranslation> { | ||
protected readonly enableCreate = true; | ||
protected readonly enableUpdate = true; | ||
protected readonly enableDelete = true; | ||
|
||
constructor( | ||
@Inject(LOGGER) baseLogger: pino.Logger, | ||
dataDiffer: TranslationsDataDiffer, | ||
dataLoader: TranslationsDataLoader, | ||
dataClient: TranslationsDataClient, | ||
dataMapper: TranslationsDataMapper, | ||
idMapper: TranslationsIdMapperClient, | ||
config: ConfigService, | ||
migrationClient: MigrationClient, | ||
) { | ||
super( | ||
getChildLogger(baseLogger, TRANSLATIONS_COLLECTION), | ||
dataDiffer, | ||
dataLoader, | ||
dataClient, | ||
dataMapper, | ||
idMapper, | ||
migrationClient, | ||
config.getHooksConfig(TRANSLATIONS_COLLECTION), | ||
); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/cli/src/lib/services/collections/translations/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const TRANSLATIONS_COLLECTION = 'translations'; |
36 changes: 36 additions & 0 deletions
36
packages/cli/src/lib/services/collections/translations/data-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { DataClient, Query, WithoutIdAndSyncId } from '../base'; | ||
import { | ||
createTranslation, | ||
deleteTranslation, | ||
readTranslations, | ||
updateTranslation, | ||
} from '@directus/sdk'; | ||
import { Service } from 'typedi'; | ||
import { MigrationClient } from '../../migration-client'; | ||
import { DirectusTranslation } from './interfaces'; | ||
|
||
@Service() | ||
export class TranslationsDataClient extends DataClient<DirectusTranslation> { | ||
constructor(migrationClient: MigrationClient) { | ||
super(migrationClient); | ||
} | ||
|
||
protected getDeleteCommand(itemId: number) { | ||
return deleteTranslation(itemId); | ||
} | ||
|
||
protected getInsertCommand(item: WithoutIdAndSyncId<DirectusTranslation>) { | ||
return createTranslation(item); | ||
} | ||
|
||
protected getQueryCommand(query: Query<DirectusTranslation>) { | ||
return readTranslations(query); | ||
} | ||
|
||
protected getUpdateCommand( | ||
itemId: number, | ||
diffItem: Partial<WithoutIdAndSyncId<DirectusTranslation>>, | ||
) { | ||
return updateTranslation(itemId, diffItem); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/cli/src/lib/services/collections/translations/data-differ.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { DataDiffer } from '../base'; | ||
|
||
import { Inject, Service } from 'typedi'; | ||
import { TRANSLATIONS_COLLECTION } from './constants'; | ||
import pino from 'pino'; | ||
import { TranslationsDataLoader } from './data-loader'; | ||
import { TranslationsDataClient } from './data-client'; | ||
import { TranslationsIdMapperClient } from './id-mapper-client'; | ||
import { getChildLogger } from '../../../helpers'; | ||
import { TranslationsDataMapper } from './data-mapper'; | ||
import { LOGGER } from '../../../constants'; | ||
import { DirectusTranslation } from './interfaces'; | ||
|
||
@Service() | ||
export class TranslationsDataDiffer extends DataDiffer<DirectusTranslation> { | ||
constructor( | ||
@Inject(LOGGER) baseLogger: pino.Logger, | ||
dataLoader: TranslationsDataLoader, | ||
dataClient: TranslationsDataClient, | ||
dataMapper: TranslationsDataMapper, | ||
idMapper: TranslationsIdMapperClient, | ||
) { | ||
super( | ||
getChildLogger(baseLogger, TRANSLATIONS_COLLECTION), | ||
dataLoader, | ||
dataClient, | ||
dataMapper, | ||
idMapper, | ||
); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/cli/src/lib/services/collections/translations/data-loader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { DataLoader } from '../base'; | ||
|
||
import { Service } from 'typedi'; | ||
import { TRANSLATIONS_COLLECTION } from './constants'; | ||
import path from 'path'; | ||
import { DirectusTranslation } from './interfaces'; | ||
import { ConfigService } from '../../config'; | ||
import { MigrationClient } from '../../migration-client'; | ||
|
||
@Service() | ||
export class TranslationsDataLoader extends DataLoader<DirectusTranslation> { | ||
constructor(config: ConfigService, migrationClient: MigrationClient) { | ||
const filePath = path.join( | ||
config.getCollectionsConfig().dumpPath, | ||
`${TRANSLATIONS_COLLECTION}.json`, | ||
); | ||
const hooks = config.getHooksConfig(TRANSLATIONS_COLLECTION); | ||
super(filePath, migrationClient, hooks); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/cli/src/lib/services/collections/translations/data-mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { DataMapper } from '../base'; | ||
|
||
import { Inject, Service } from 'typedi'; | ||
import pino from 'pino'; | ||
import { getChildLogger } from '../../../helpers'; | ||
import { LOGGER } from '../../../constants'; | ||
import { TRANSLATIONS_COLLECTION } from './constants'; | ||
import { DirectusTranslation } from './interfaces'; | ||
|
||
@Service() | ||
export class TranslationsDataMapper extends DataMapper<DirectusTranslation> { | ||
constructor(@Inject(LOGGER) baseLogger: pino.Logger) { | ||
super(getChildLogger(baseLogger, TRANSLATIONS_COLLECTION)); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/cli/src/lib/services/collections/translations/id-mapper-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { IdMapperClient } from '../base'; | ||
import { Service } from 'typedi'; | ||
import { TRANSLATIONS_COLLECTION } from './constants'; | ||
import { MigrationClient } from '../../migration-client'; | ||
|
||
@Service() | ||
export class TranslationsIdMapperClient extends IdMapperClient { | ||
constructor(migrationClient: MigrationClient) { | ||
super(migrationClient, TRANSLATIONS_COLLECTION); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/cli/src/lib/services/collections/translations/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export * from './interfaces'; | ||
export * from './constants'; | ||
export * from './collection'; | ||
export * from './data-client'; | ||
export * from './data-differ'; | ||
export * from './data-mapper'; | ||
export * from './data-loader'; | ||
export * from './id-mapper-client'; |
4 changes: 4 additions & 0 deletions
4
packages/cli/src/lib/services/collections/translations/interfaces.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { DirectusTranslation as BaseDirectusTranslation } from '@directus/sdk'; | ||
import { BaseSchema } from '../base'; | ||
|
||
export type DirectusTranslation = BaseDirectusTranslation<BaseSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters