-
-
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.
- Loading branch information
1 parent
38f30c5
commit e626fad
Showing
12 changed files
with
179 additions
and
0 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
45 changes: 45 additions & 0 deletions
45
packages/cli/src/lib/services/collections/folders/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,45 @@ | ||
import { DirectusCollection } from '../base'; | ||
import pino from 'pino'; | ||
import { Inject, Service } from 'typedi'; | ||
import { FoldersDataLoader } from './data-loader'; | ||
import { FoldersDataClient } from './data-client'; | ||
import { FoldersIdMapperClient } from './id-mapper-client'; | ||
import { FoldersDataDiffer } from './data-differ'; | ||
import { getChildLogger } from '../../../helpers'; | ||
import { FOLDERS_COLLECTION } from './constants'; | ||
import { FoldersDataMapper } from './data-mapper'; | ||
import { LOGGER } from '../../../constants'; | ||
import { DirectusFolder } from './interfaces'; | ||
import { ConfigService } from '../../config'; | ||
import { MigrationClient } from '../../migration-client'; | ||
|
||
@Service() | ||
export class FoldersCollection extends DirectusCollection<DirectusFolder> { | ||
protected readonly enableCreate = true; | ||
protected readonly enableUpdate = true; | ||
protected readonly enableDelete = true; | ||
|
||
protected readonly preserveIds = true; | ||
|
||
constructor( | ||
@Inject(LOGGER) baseLogger: pino.Logger, | ||
dataDiffer: FoldersDataDiffer, | ||
dataLoader: FoldersDataLoader, | ||
dataClient: FoldersDataClient, | ||
dataMapper: FoldersDataMapper, | ||
idMapper: FoldersIdMapperClient, | ||
config: ConfigService, | ||
migrationClient: MigrationClient, | ||
) { | ||
super( | ||
getChildLogger(baseLogger, FOLDERS_COLLECTION), | ||
dataDiffer, | ||
dataLoader, | ||
dataClient, | ||
dataMapper, | ||
idMapper, | ||
migrationClient, | ||
config.getHooksConfig(FOLDERS_COLLECTION), | ||
); | ||
} | ||
} |
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 FOLDERS_COLLECTION = 'folders'; |
36 changes: 36 additions & 0 deletions
36
packages/cli/src/lib/services/collections/folders/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 { | ||
createFolder, | ||
deleteFolder, | ||
readFolders, | ||
updateFolder, | ||
} from '@directus/sdk'; | ||
import { Service } from 'typedi'; | ||
import { MigrationClient } from '../../migration-client'; | ||
import { DirectusFolder } from './interfaces'; | ||
|
||
@Service() | ||
export class FoldersDataClient extends DataClient<DirectusFolder> { | ||
constructor(migrationClient: MigrationClient) { | ||
super(migrationClient); | ||
} | ||
|
||
protected getDeleteCommand(itemId: string) { | ||
return deleteFolder(itemId); | ||
} | ||
|
||
protected getInsertCommand(item: WithoutIdAndSyncId<DirectusFolder>) { | ||
return createFolder(item); | ||
} | ||
|
||
protected getQueryCommand(query: Query<DirectusFolder>) { | ||
return readFolders(query); | ||
} | ||
|
||
protected getUpdateCommand( | ||
itemId: string, | ||
diffItem: Partial<WithoutIdAndSyncId<DirectusFolder>>, | ||
) { | ||
return updateFolder(itemId, diffItem); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/cli/src/lib/services/collections/folders/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 { FOLDERS_COLLECTION } from './constants'; | ||
import pino from 'pino'; | ||
import { FoldersDataLoader } from './data-loader'; | ||
import { FoldersDataClient } from './data-client'; | ||
import { FoldersIdMapperClient } from './id-mapper-client'; | ||
import { getChildLogger } from '../../../helpers'; | ||
import { FoldersDataMapper } from './data-mapper'; | ||
import { LOGGER } from '../../../constants'; | ||
import { DirectusFolder } from './interfaces'; | ||
|
||
@Service() | ||
export class FoldersDataDiffer extends DataDiffer<DirectusFolder> { | ||
constructor( | ||
@Inject(LOGGER) baseLogger: pino.Logger, | ||
dataLoader: FoldersDataLoader, | ||
dataClient: FoldersDataClient, | ||
dataMapper: FoldersDataMapper, | ||
idMapper: FoldersIdMapperClient, | ||
) { | ||
super( | ||
getChildLogger(baseLogger, FOLDERS_COLLECTION), | ||
dataLoader, | ||
dataClient, | ||
dataMapper, | ||
idMapper, | ||
); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/cli/src/lib/services/collections/folders/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 { FOLDERS_COLLECTION } from './constants'; | ||
import path from 'path'; | ||
import { DirectusFolder } from './interfaces'; | ||
import { ConfigService } from '../../config'; | ||
import { MigrationClient } from '../../migration-client'; | ||
|
||
@Service() | ||
export class FoldersDataLoader extends DataLoader<DirectusFolder> { | ||
constructor(config: ConfigService, migrationClient: MigrationClient) { | ||
const filePath = path.join( | ||
config.getCollectionsConfig().dumpPath, | ||
`${FOLDERS_COLLECTION}.json`, | ||
); | ||
const hooks = config.getHooksConfig(FOLDERS_COLLECTION); | ||
super(filePath, migrationClient, hooks); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/cli/src/lib/services/collections/folders/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,19 @@ | ||
import { DataMapper, IdMappers } from '../base'; | ||
|
||
import { Container, Inject, Service } from 'typedi'; | ||
import pino from 'pino'; | ||
import { getChildLogger } from '../../../helpers'; | ||
import { LOGGER } from '../../../constants'; | ||
import { FOLDERS_COLLECTION } from './constants'; | ||
import { DirectusFolder } from './interfaces'; | ||
import { FoldersIdMapperClient } from './id-mapper-client'; | ||
|
||
@Service() | ||
export class FoldersDataMapper extends DataMapper<DirectusFolder> { | ||
protected idMappers: IdMappers<DirectusFolder> = { | ||
parent: Container.get(FoldersIdMapperClient), | ||
}; | ||
constructor(@Inject(LOGGER) baseLogger: pino.Logger) { | ||
super(getChildLogger(baseLogger, FOLDERS_COLLECTION)); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/cli/src/lib/services/collections/folders/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 { FOLDERS_COLLECTION } from './constants'; | ||
import { MigrationClient } from '../../migration-client'; | ||
|
||
@Service() | ||
export class FoldersIdMapperClient extends IdMapperClient { | ||
constructor(migrationClient: MigrationClient) { | ||
super(migrationClient, FOLDERS_COLLECTION); | ||
} | ||
} |
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/folders/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 { DirectusFolder as BaseDirectusFolder } from '@directus/sdk'; | ||
import { BaseSchema } from '../base'; | ||
|
||
export type DirectusFolder = BaseDirectusFolder<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
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