Skip to content

Commit

Permalink
feat: Update types in the CDA library with taxonomy assets (#2349)
Browse files Browse the repository at this point in the history
* feat: Update types in the CDA library with taxonomy asset support
  • Loading branch information
momenzadehvida authored Oct 9, 2024
1 parent 5f4c6c3 commit fb3bcc2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/types/asset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ContentfulCollection } from './collection'
import { LocaleCode } from './locale'
import { AssetMetadata } from './metadata'
import { Metadata } from './metadata'
import { EntitySys } from './sys'
import { ChainModifiers } from './client'

Expand Down Expand Up @@ -53,7 +53,7 @@ export interface Asset<
: 'WITH_ALL_LOCALES' extends Modifiers
? { [FieldName in keyof AssetFields]: { [LocaleName in Locales]?: AssetFields[FieldName] } }
: AssetFields
metadata: AssetMetadata
metadata: Metadata
}

/**
Expand Down
2 changes: 0 additions & 2 deletions lib/types/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ export type Metadata = {
tags: { sys: TagLink }[]
concepts?: { sys: TaxonomyConceptLink }[]
}

export type AssetMetadata = Omit<Metadata, 'concepts'>
1 change: 1 addition & 0 deletions lib/types/query/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export type AssetsQueries<
> = AssetFieldsQueries<Fields> &
AssetFieldsFileQueries &
AssetFieldsFileDetailsQueries &
MetadataConceptsQueries &
SysQueries<Pick<AssetSys, 'createdAt' | 'updatedAt' | 'revision' | 'id' | 'type'>> &
MetadataTagsQueries &
FixedQueryOptions &
Expand Down
4 changes: 2 additions & 2 deletions lib/types/query/select.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FieldsType } from './util'
import { EntrySys } from '../entry'
import { AssetSys } from '../asset'
import { AssetMetadata, Metadata } from '../metadata'
import { Metadata } from '../metadata'

export type SelectFilterPaths<
Fields extends FieldsType,
Expand Down Expand Up @@ -51,6 +51,6 @@ export type AssetSelectFilter<Fields extends FieldsType> = {
| 'fields'
| SelectFilterPaths<Fields, 'fields'>
| 'metadata'
| SelectFilterPaths<AssetMetadata, 'metadata'>
| SelectFilterPaths<Metadata, 'metadata'>
)[]
}
17 changes: 13 additions & 4 deletions test/integration/getEntries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ describe('getEntries via client chain modifiers', () => {
include: 5,
'sys.id': entryWithResolvableLink,
})

assertLocalizedEntriesResponse(response)
})

Expand Down Expand Up @@ -395,7 +396,8 @@ describe('getEntries via client chain modifiers', () => {
'sys.id': entryWithResolvableLink,
})

assertCSMEntriesResponse(response)
const conceptsIncludedInMetadata = true
assertCSMEntriesResponse(response, conceptsIncludedInMetadata)
})

test('enforces entry.sys when query.select is defined', async () => {
Expand Down Expand Up @@ -503,10 +505,13 @@ function assertLocalizedEntriesResponse(response) {

expect(entry.fields.bestFriend['en-US'].fields).toBeDefined()
expect(entry.fields.bestFriend['en-US'].sys.type).toBe('Entry')
expect(entry.metadata).toEqual({ tags: [] })
expect(entry.metadata).toEqual({
tags: [],
concepts: [],
})
}

function assertCSMEntriesResponse(response) {
function assertCSMEntriesResponse(response, conceptsIncludedInMetadata = false) {
expect(response.includes).toBeDefined()
expect(response.includes!.Asset).toBeDefined()
expect(Object.keys(response.includes!.Asset!).length).toBeGreaterThan(0)
Expand All @@ -515,6 +520,10 @@ function assertCSMEntriesResponse(response) {

expect(entry.fields.bestFriend.fields).toBeDefined()
expect(entry.fields.bestFriend.sys.type).toBe('Entry')
expect(entry.metadata).toEqual({ tags: [] })

expect(entry.metadata).toEqual({
tags: [],
...(conceptsIncludedInMetadata && { concepts: [] }),
})
expect(response.sys?.contentSourceMapsLookup).toBeDefined()
}
11 changes: 8 additions & 3 deletions test/types/queries/asset-queries.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ type DefaultAssetQueries = AssetsQueries<AssetFields, undefined>

expectAssignable<DefaultAssetQueries>({
'metadata.tags.sys.id[all]': mocks.stringArrayValue,
})

expectNotAssignable<DefaultAssetQueries>({
'metadata.concepts.sys.id[all]': mocks.stringArrayValue,
})

Expand Down Expand Up @@ -45,8 +42,14 @@ expectAssignable<DefaultAssetQueries>({
'fields.file.url[exists]': mocks.booleanValue,
'fields.title[exists]': mocks.booleanValue,
'metadata.tags[exists]': mocks.booleanValue,
'metadata.concepts[exists]': mocks.booleanValue,
'sys.updatedAt[exists]': mocks.booleanValue,
})
expectAssignable<DefaultAssetQueries>({
'metadata.tags.sys.id[all]': mocks.stringArrayValue,
'metadata.concepts.sys.id[all]': mocks.stringArrayValue,
'metadata.concepts.descendants[in]': mocks.stringArrayValue,
})
expectNotAssignable<DefaultAssetQueries>({
'fields.unknownField[exists]': mocks.anyValue,
})
Expand Down Expand Up @@ -84,6 +87,7 @@ expectAssignable<DefaultAssetQueries>({
'fields.file.url[in]': mocks.stringArrayValue,
'fields.title[in]': mocks.stringArrayValue,
'metadata.tags.sys.id[in]': mocks.stringArrayValue,
'metadata.concepts.sys.id[in]': mocks.stringArrayValue,
'sys.updatedAt[in]': mocks.dateArrayValue,
})
expectNotAssignable<DefaultAssetQueries>({
Expand Down Expand Up @@ -154,6 +158,7 @@ expectAssignable<DefaultAssetQueries>({
'fields.file.url[nin]': mocks.stringArrayValue,
'fields.title[nin]': mocks.stringArrayValue,
'metadata.tags.sys.id[nin]': mocks.stringArrayValue,
'metadata.concepts.sys.id[nin]': mocks.stringArrayValue,
'sys.updatedAt[nin]': mocks.dateArrayValue,
})
expectNotAssignable<DefaultAssetQueries>({
Expand Down

0 comments on commit fb3bcc2

Please sign in to comment.