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
132 changes: 62 additions & 70 deletions precomputer/generated/api-client.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
// Auto-generated by https://github.com/vladkens/apigen-ts
// Source: http://localhost:8000/api/schema/

type Headers = Record<string, string>
export type ApigenHeaders =
| Headers
| ((method: string, path: string) => Headers | Promise<Headers>)

export interface ApigenConfig {
baseUrl: string
headers: ApigenHeaders
headers: Record<string, string>
}

export interface ApigenRequest extends Omit<RequestInit, 'body'> {
Expand Down Expand Up @@ -68,12 +63,7 @@ export class ApiClient {
url.searchParams.append(k, Array.isArray(v) ? v.join(',') : (v as string))
}

const configHeaders =
typeof this.Config.headers === 'function' ?
await this.Config.headers(method, path)
: this.Config.headers

const headers = new Headers({ ...configHeaders, ...opts.headers })
const headers = new Headers({ ...this.Config.headers, ...opts.headers })
const ct = headers.get('content-type') ?? 'application/json'

let body: FormData | URLSearchParams | string | undefined = undefined
Expand Down Expand Up @@ -292,9 +282,7 @@ export class ApiClient {

schema = {
retrieve: (search: { format?: 'json' | 'yaml' }) => {
return this.Fetch<Record<string, unknown>>('get', '/api/schema/', {
search
})
return this.Fetch<object>('get', '/api/schema/', { search })
}
}
}
Expand All @@ -307,7 +295,9 @@ export type AuthorPerson = {
email_addresses: string[]
}

export type ClientErrorEnum = 'client_error'
export enum ClientErrorEnum {
Client_error = 'client_error'
}

export type ContainingSubseries = {
name: string
Expand All @@ -319,7 +309,10 @@ export type DocIdentifier = {
value: string
}

export type DocIdentifierTypeEnum = 'doi' | 'issn'
export enum DocIdentifierTypeEnum {
Doi = 'doi',
Issn = 'issn'
}

export type DocumentAuthor = {
person: number
Expand All @@ -332,9 +325,11 @@ export type Draft = {
rev?: string
stream?: string | null
title: string
group?: string
pages?: number | null
source_format?: SourceFormatEnum
authors: DocumentAuthor[]
consensus?: boolean | null
}

export type DraftWithAuthors = {
Expand Down Expand Up @@ -365,27 +360,40 @@ export type Error404 = {
attr: string | null
}

export type ErrorCode404Enum = 'not_found'
export enum ErrorCode404Enum {
Not_found = 'not_found'
}

export type ErrorResponse404 = {
type: ClientErrorEnum
errors: Error404[]
}

export type FormatsEnum = 'xml' | 'txt' | 'html' | 'htmlized' | 'pdf' | 'ps'
export enum FmtEnum {
Xml = 'xml',
Txt = 'txt',
Html = 'html',
Pdf = 'pdf',
Ps = 'ps',
Json = 'json',
Notprepped = 'notprepped'
}

export type FullDraft = {
id?: number
name: string
rev?: string
stream?: string | null
title: string
group?: string
abstract?: string
pages?: number | null
source_format?: SourceFormatEnum
authors: DocumentAuthor[]
shepherd?: string
intended_std_level?: string | null
consensus?: boolean | null
shepherd?: number
ad?: number | null
}

export type GetDraftAuthorsErrorResponse400 = ParseErrorResponse
Expand Down Expand Up @@ -551,11 +559,8 @@ export type NotifyRfcPublishedError =
| NotifyRfcPublishedStreamErrorComponent
| NotifyRfcPublishedAbstractErrorComponent
| NotifyRfcPublishedPagesErrorComponent
| NotifyRfcPublishedWordsErrorComponent
| NotifyRfcPublishedFormalLanguagesErrorComponent
| NotifyRfcPublishedStdLevelErrorComponent
| NotifyRfcPublishedAdErrorComponent
| NotifyRfcPublishedNoteErrorComponent
| NotifyRfcPublishedObsoletesErrorComponent
| NotifyRfcPublishedUpdatesErrorComponent
| NotifyRfcPublishedSubseriesErrorComponent
Expand All @@ -565,12 +570,6 @@ export type NotifyRfcPublishedErrorResponse400 =
| NotifyRfcPublishedValidationError
| ParseErrorResponse

export type NotifyRfcPublishedFormalLanguagesErrorComponent = {
attr: 'formal_languages'
code: 'does_not_exist' | 'incorrect_type' | 'not_a_list' | 'null'
detail: string
}

export type NotifyRfcPublishedGroupErrorComponent = {
attr: 'group'
code: 'does_not_exist' | 'invalid' | 'null'
Expand All @@ -583,16 +582,6 @@ export type NotifyRfcPublishedNonFieldErrorsErrorComponent = {
detail: string
}

export type NotifyRfcPublishedNoteErrorComponent = {
attr: 'note'
code:
| 'invalid'
| 'null'
| 'null_characters_not_allowed'
| 'surrogate_characters_not_allowed'
detail: string
}

export type NotifyRfcPublishedObsoletesErrorComponent = {
attr: 'obsoletes'
code: 'does_not_exist' | 'invalid' | 'not_a_list' | 'null'
Expand Down Expand Up @@ -670,12 +659,6 @@ export type NotifyRfcPublishedValidationError = {
errors: NotifyRfcPublishedError[]
}

export type NotifyRfcPublishedWordsErrorComponent = {
attr: 'words'
code: 'invalid' | 'max_string_length' | 'max_value' | 'min_value'
detail: string
}

export type OriginalStream = {
rfc_number?: number | null
stream?: string
Expand All @@ -701,7 +684,9 @@ export type ParseError = {
attr: string | null
}

export type ParseErrorCodeEnum = 'parse_error'
export enum ParseErrorCodeEnum {
Parse_error = 'parse_error'
}

export type ParseErrorResponse = {
type: ClientErrorEnum
Expand Down Expand Up @@ -1046,12 +1031,11 @@ export type Rfc = {
updates?: RelatedRfc[]
updated_by?: ReverseRelatedRfc[]
subseries?: ContainingSubseries[]
see_also?: string[]
draft?: RelatedDraft
abstract?: string
formats: FormatsEnum[]
formats?: RfcFormat[]
keywords?: string[]
errata?: string[]
has_errata?: boolean
text: string | null
}

Expand Down Expand Up @@ -1082,6 +1066,11 @@ export type RfcFileRequest = {
replace?: boolean
}

export type RfcFormat = {
fmt: FmtEnum
name: string
}

export type RfcMetadata = {
number: number
title: string
Expand All @@ -1098,12 +1087,11 @@ export type RfcMetadata = {
updates?: RelatedRfc[]
updated_by?: ReverseRelatedRfc[]
subseries?: ContainingSubseries[]
see_also?: string[]
draft?: RelatedDraft
abstract?: string
formats: FormatsEnum[]
formats?: RfcFormat[]
keywords?: string[]
errata?: string[]
has_errata?: boolean
}

export type RfcPubRequest = {
Expand All @@ -1117,11 +1105,8 @@ export type RfcPubRequest = {
stream: string
abstract?: string
pages?: number | null
words?: number | null
formal_languages?: string[]
std_level: string
ad?: number | null
note?: string
obsoletes?: (number | null)[]
updates?: (number | null)[]
subseries: string[]
Expand All @@ -1141,18 +1126,24 @@ export type SchemaRetrieveErrorResponse400 = ParseErrorResponse

export type SearchPersonErrorResponse400 = ParseErrorResponse

export type SlugEnum =
| 'bcp'
| 'ds'
| 'exp'
| 'hist'
| 'inf'
| 'not-issued'
| 'ps'
| 'std'
| 'unkn'
export enum SlugEnum {
Bcp = 'bcp',
Ds = 'ds',
Exp = 'exp',
Hist = 'hist',
Inf = 'inf',
Not_issued = 'not-issued',
Ps = 'ps',
Std = 'std',
Unkn = 'unkn'
}

export type SourceFormatEnum = 'unknown' | 'xml-v2' | 'xml-v3' | 'txt'
export enum SourceFormatEnum {
Unknown = 'unknown',
Xml_v2 = 'xml-v2',
Xml_v3 = 'xml-v3',
Txt = 'txt'
}

export type StreamName = {
slug: string
Expand Down Expand Up @@ -1186,12 +1177,11 @@ export type SubseriesContent = {
updates?: RelatedRfc[]
updated_by?: ReverseRelatedRfc[]
subseries?: ContainingSubseries[]
see_also?: string[]
draft?: RelatedDraft
abstract?: string
formats: FormatsEnum[]
formats?: RfcFormat[]
keywords?: string[]
errata?: string[]
has_errata?: boolean
}

export type SubseriesDoc = {
Expand Down Expand Up @@ -1253,4 +1243,6 @@ export type UploadRfcFilesValidationError = {
errors: UploadRfcFilesError[]
}

export type ValidationErrorEnum = 'validation_error'
export enum ValidationErrorEnum {
Validation_error = 'validation_error'
}
2 changes: 1 addition & 1 deletion precomputer/src/tasks/rfc-pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const rfcBucketPdfToRfcDocument = async (
}

console.log(
`[RFC ${rfcNumber}] uploaded ${textDetails.text.totalPages} pages of a PDF`
`[RFC ${rfcNumber}] screenshotted ${textDetails.text.totalPages} pages of a PDF`
)

const response: RfcBucketHtmlDocument = {
Expand Down
12 changes: 6 additions & 6 deletions precomputer/src/utilities/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export const getRfcCommonCached = async (
/** Convert `Rfc` to `RfcCommon` */
export const rfcToRfcCommon = (rfc: Rfc): RfcCommon => {
return {
formats: rfc.formats,
formats: rfc.formats?.map((format): RfcCommon["formats"][number] => format.fmt) ?? [],
subseries: parseSubseries(rfc.subseries),
number: rfc.number,
abstract: rfc.abstract,
Expand All @@ -251,18 +251,18 @@ export const rfcToRfcCommon = (rfc: Rfc): RfcCommon => {
obsoleted_by: rfc.obsoleted_by,
updates: rfc.updates,
updated_by: rfc.updated_by,
see_also: rfc.see_also,
see_also: undefined,
draft: parseDraft(rfc.draft),
keywords: rfc.keywords,
errata: rfc.errata,
errata: undefined,
title: rfc.title
}
}

/** Convert `RfcMetadata` to `RfcCommon` */
export const rfcMetadataToRfcCommon = (rfcMetadata: RfcMetadata): RfcCommon => {
return {
formats: rfcMetadata.formats,
formats: rfcMetadata.formats?.map((format): RfcCommon["formats"][number] => format.fmt) ?? [],
number: rfcMetadata.number,
abstract: rfcMetadata.abstract,
published: rfcMetadata.published,
Expand All @@ -282,10 +282,10 @@ export const rfcMetadataToRfcCommon = (rfcMetadata: RfcMetadata): RfcCommon => {
updated_by: rfcMetadata.updated_by,
subseries: parseSubseries(rfcMetadata.subseries),
draft: parseDraft(rfcMetadata.draft),
see_also: rfcMetadata.see_also,
see_also: undefined,
updates: rfcMetadata.updates,
keywords: rfcMetadata.keywords,
errata: rfcMetadata.errata,
errata: undefined,
title: rfcMetadata.title
}
}
Expand Down
8 changes: 6 additions & 2 deletions precomputer/src/utilities/rfc-converters-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,17 @@ export const formatFormat = (
case 'xml':
return 'XML'
case 'html':
return 'HTML'
case 'htmlized':
return 'HTMLIZED'
return 'HTML'
case 'pdf':
return 'PDF'
case 'ps':
return 'PS'
case 'json':
return 'JSON'
case 'notprepped':
return 'NOTPREPPED'

}
throw Error(`Unexpected format "${format}"`)
}
Expand Down
8 changes: 6 additions & 2 deletions precomputer/src/utilities/rfc-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const RfcJsonFormatSchema = z.union([
z.literal('PDF'),
z.literal('PS'),
z.literal('XML'),
z.literal('JSON'),
z.literal('NOTPREPPED'),
z.literal('') // FIXME: should this exist?
])

Expand Down Expand Up @@ -125,12 +127,14 @@ const formatRfcFormatAsRfcJsonFormat = (
return 'XML'
case 'html':
return 'HTML'
case 'htmlized':
return 'HTML'
case 'pdf':
return 'PDF'
case 'ps':
return 'PS'
case 'json':
return 'JSON'
case 'notprepped':
return 'NOTPREPPED'
}
assertNever(format)
}
Expand Down
Loading