Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: include typings in the release #699

Merged
merged 5 commits into from
May 11, 2021
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/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> {
andipaetzold marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: somewhere we use constant strings to address the Entity type, sometimes we use just string. Once types in CMA are fixed this can go back to a list of constant strings


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"]
}