Skip to content

Commit

Permalink
fix: include typings in the release (#699)
Browse files Browse the repository at this point in the history
* fix: include typings in the release

* chore: tweak space api types to adhere to cma.js

* refactor: Item -> Items

* revert: old tags api

* feat: export UserAPI
  • Loading branch information
shikaan authored May 11, 2021
1 parent afd5922 commit 16b15e2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 55 deletions.
2 changes: 1 addition & 1 deletion lib/types/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { NavigatorAPI } from './navigator.types'
import { EntryFieldInfo, FieldInfo } from './field.types'

/* User API */
interface UserAPI {
export interface UserAPI {
sys: {
id: string
type: string
Expand Down
62 changes: 27 additions & 35 deletions lib/types/entities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ContentEntitySys, ContentEntityType, Items, Link, Metadata } from './utils'

type TagVisibility = 'private' | 'public'
export type TagVisibility = 'private' | 'public'

export interface User {
/**
Expand Down Expand Up @@ -53,8 +53,8 @@ export interface Tag {
id: string
space: Link
environment: Link
createdBy: Link
updatedBy: Link
createdBy?: Link
updatedBy?: Link
createdAt: string
updatedAt: string
version: number
Expand Down Expand Up @@ -114,13 +114,15 @@ export interface Task {
sys: TaskSys
}

const enum PublicActionStatus {
Scheduled = 'scheduled',
Succeeded = 'succeeded',
Failed = 'failed',
Canceled = 'canceled',
export enum ScheduledActionStatuses {
scheduled = 'scheduled',
inProgress = 'inProgress',
succeeded = 'succeeded',
failed = 'failed',
canceled = 'canceled',
}

// WARNING: This is using 'keyof' which looks at the left hand name, not the right hand value
type PublicActionStatus = keyof typeof ScheduledActionStatuses
type ScheduledActionActionType = 'publish' | 'unpublish'

export interface ScheduledAction {
Expand All @@ -133,13 +135,7 @@ export interface ScheduledAction {
/** ISO 8601 string */
canceledAt?: string
canceledBy?: Link
space: {
sys: {
id: string
linkType: 'Space'
type: string
}
}
space: Link
status: PublicActionStatus
}
entity: {
Expand All @@ -149,44 +145,40 @@ export interface ScheduledAction {
type: string
}
}
environment: {
sys: {
id: string
linkType: 'Environment'
type: string
}
}
environment?: Link
scheduledFor: {
/** ISO 8601 string */
datetime: string
}
action: ScheduledActionActionType
}

export interface ContentTypeField {
disabled: boolean
export interface ContentTypeField extends Items {
id: string
localized: boolean
name: string
omitted: boolean
required: boolean
type: string
validations: Object[]
linkType?: string
localized: boolean
disabled?: boolean
omitted?: boolean
deleted?: boolean
items?: Items
apiName?: string
}

export interface ContentType {
sys: {
type: string
id: string
version?: number
space?: Link
environment?: Link
createdAt?: string
version: number
createdBy?: Link
updatedAt?: string
createdAt: string
updatedBy?: Link
updatedAt: string
space: Link
environment: Link
firstPublishedAt?: string
publishedCounter?: number
publishedVersion?: number
}
fields: ContentTypeField[]
name: string
Expand Down
2 changes: 2 additions & 0 deletions lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type {
ParametersAPI,
SharedEditorSDK,
SidebarExtensionSDK,
UserAPI,
} from './api.types'

export type { AppConfigAPI, AppState } from './app.types'
Expand All @@ -39,6 +40,7 @@ export type {
ScheduledAction,
SpaceMembership,
Tag,
TagVisibility,
Task,
} from './entities'

Expand Down
7 changes: 3 additions & 4 deletions lib/types/space.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import {
ContentType,
EditorInterface,
ScheduledAction,
SearchQuery,
Tag,
TagVisibility,
User,
TagVisibility,
} from './entities'
import { CollectionResponse, ContentEntityType, Link, WithOptionalSys } from './utils'
import { CollectionResponse, ContentEntityType, Link, WithOptionalSys, SearchQuery } from './utils'

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

Expand Down
28 changes: 14 additions & 14 deletions lib/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ export type WithOptionalSys<Type extends { sys: unknown }> = Omit<Type, 'sys'> &
sys?: Type['sys']
}

export interface Link<Type = string> {
export interface Link<LinkType = string, Type = string> {
sys: {
id: string
type: 'Link'
linkType: Type
type: Type
linkType: LinkType
}
}

Expand All @@ -18,7 +18,7 @@ export interface CollectionResponse<T> {
sys: { type: string }
}

export type ContentEntityType = 'Entry' | 'Asset'
export type ContentEntityType = 'Entry' | 'Asset' | string

export interface ContentEntitySys {
space: Link
Expand All @@ -27,22 +27,22 @@ export interface ContentEntitySys {
createdAt: string
updatedAt: string
environment: Link
publishedVersion: number
publishedVersion?: number
deletedVersion?: number
archivedVersion?: number
publishedAt: string
firstPublishedAt: string
createdBy: Link
updatedBy: Link
publishedCounter: number
publishedAt?: string
firstPublishedAt?: string
createdBy?: Link
updatedBy?: Link
publishedCounter?: number
version: number
publishedBy: Link
publishedBy?: Link
contentType: Link
}

export type Metadata = Partial<{
tags: Link<'Tag'>[]
}>
export type Metadata = {
tags: Link<'Tag', 'Link'>[]
}

export interface Items {
type: string
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"forceConsistentCasingInFileNames": true,
"declaration": true
},
"include": ["lib"],
"include": ["lib/**/*"],
"exclude": ["test"]
}

0 comments on commit 16b15e2

Please sign in to comment.