Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export type {
ContentEntityType,
Items,
Link,
WithOptionalSys,
WithOptionalId,
} from './utils'

export type { WindowAPI } from './window.types'
15 changes: 11 additions & 4 deletions lib/types/space.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ import {
User,
TagVisibility,
} from './entities'
import { CollectionResponse, ContentEntityType, Link, WithOptionalSys, SearchQuery } from './utils'
import {
CollectionResponse,
ContentEntityType,
Link,
WithOptionalId,
SearchQuery,
WithId,
} from './utils'

type Snapshot<T> = {
sys: {
Expand All @@ -33,7 +40,7 @@ export interface SpaceAPI {
getCachedContentTypes: () => ContentType[]
getContentType: (id: string) => Promise<ContentType>
getContentTypes: () => Promise<CollectionResponse<ContentType>>
createContentType: (data: ContentType) => Promise<ContentType>
createContentType: (data: WithId<ContentType>) => Promise<ContentType>
updateContentType: (data: ContentType) => Promise<ContentType>
deleteContentType: (data: ContentType) => Promise<void>

Expand All @@ -44,7 +51,7 @@ export interface SpaceAPI {
) => Promise<CollectionResponse<Entry<Fields>>>
createEntry: <Fields>(
contentTypeId: string,
data: WithOptionalSys<Entry<Fields>>
data: WithOptionalId<Entry<Fields>>
) => Promise<Entry<Fields>>
updateEntry: <Fields>(data: Entry<Fields>) => Promise<Entry<Fields>>
publishEntry: <Fields>(data: Entry<Fields>) => Promise<Entry<Fields>>
Expand All @@ -60,7 +67,7 @@ export interface SpaceAPI {
getAssets: <Query extends SearchQuery = SearchQuery>(
query?: Query
) => Promise<CollectionResponse<Asset>>
createAsset: (data: WithOptionalSys<Asset>) => Promise<Asset>
createAsset: (data: WithOptionalId<Asset>) => Promise<Asset>
updateAsset: (data: Asset) => Promise<Asset>
deleteAsset: (data: Asset) => Promise<void>
publishAsset: (data: Asset) => Promise<Asset>
Expand Down
12 changes: 10 additions & 2 deletions lib/types/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
export type WithOptionalSys<Type extends { sys: unknown }> = Omit<Type, 'sys'> & {
sys?: Type['sys']
type SysWithId = {
id: string
}

export type WithOptionalId<Type extends { sys: unknown }> = Omit<Type, 'sys'> & {
sys?: Partial<Omit<Type['sys'], 'id'> & SysWithId>
}

export type WithId<Type extends { sys: unknown }> = Omit<Type, 'sys'> & {
sys: Partial<Omit<Type['sys'], 'id'>> & SysWithId
}

export interface Link<LinkType = string, Type = string> {
Expand Down