diff --git a/src/http/responses/collections.ts b/src/http/responses/collections.ts index 49297e2..83423d7 100644 --- a/src/http/responses/collections.ts +++ b/src/http/responses/collections.ts @@ -1,6 +1,6 @@ -import type { IconifyInfo } from '@iconify/types'; import type { FastifyReply, FastifyRequest } from 'fastify'; import { getPrefixes, iconSets } from '../../data/icon-sets'; +import type { APIv2CollectionsResponse } from '../../types/server/v2'; import { checkJSONPQuery, sendJSONResponse } from '../helpers/json'; import { filterPrefixesByPrefix } from '../helpers/prefixes'; @@ -18,7 +18,7 @@ export function generateCollectionsListResponse(query: FastifyRequest['query'], // Filter prefixes const prefixes = filterPrefixesByPrefix(getPrefixes('info'), q, false); - const response = Object.create(null) as Record; + const response = Object.create(null) as APIv2CollectionsResponse; for (let i = 0; i < prefixes.length; i++) { const prefix = prefixes[i]; diff --git a/src/http/responses/modified.ts b/src/http/responses/modified.ts index d03a721..2c27ab1 100644 --- a/src/http/responses/modified.ts +++ b/src/http/responses/modified.ts @@ -1,6 +1,6 @@ import type { FastifyReply, FastifyRequest } from 'fastify'; import { getPrefixes, iconSets } from '../../data/icon-sets'; -import type { LastModifiedAPIResponse } from '../../types/server/modified'; +import type { APIv3LastModifiedResponse } from '../../types/server/modified'; import { checkJSONPQuery, sendJSONResponse } from '../helpers/json'; import { filterPrefixesByPrefix } from '../helpers/prefixes'; @@ -21,7 +21,7 @@ export function generateLastModifiedResponse(query: FastifyRequest['query'], res // Generate result const lastModified = Object.create(null) as Record; - const response: LastModifiedAPIResponse = { + const response: APIv3LastModifiedResponse = { lastModified, }; let found = false; diff --git a/src/types/server/modified.ts b/src/types/server/modified.ts index 1a7333e..6a0a8f9 100644 --- a/src/types/server/modified.ts +++ b/src/types/server/modified.ts @@ -3,6 +3,6 @@ * * Key is prefix, value is last modification time number */ -export interface LastModifiedAPIResponse { +export interface APIv3LastModifiedResponse { lastModified: Record; } diff --git a/src/types/server/v2.ts b/src/types/server/v2.ts new file mode 100644 index 0000000..af9850e --- /dev/null +++ b/src/types/server/v2.ts @@ -0,0 +1,141 @@ +import type { IconifyInfo, IconifyJSON } from '@iconify/types'; + +/** + * Common stuff + */ +interface APIv2CommonParams { + // Pretty output, default = false + pretty?: boolean; +} + +/** + * Prefixes list + * + * Separated by ',' + * Ends with '-' = partial prefix: 'fa-' + * Does not end with '-' = full prefix: 'mdi' + */ +type PrefixesMatches = string; + +/** + * Search query string + * + * List of queries, split by whitespace. Must match all queries + * Entry starts with '-': exclude it + */ +type SearchQuery = string; + +/** + * /collections + */ +export interface APIv2CollectionsParams extends APIv2CommonParams { + // Useless + version?: 1; + + // Include hidden icon sets + hidden?: boolean; + + // Filter icon sets by prefixes + prefixes?: PrefixesMatches; +} + +export type APIv2CollectionsResponse = Record; + +/** + * /collection + */ +export interface APIv2CollectionParams extends APIv2CommonParams { + // Icon set prefix + prefix: string; + + // Include icon set info in response + info?: boolean; + + // Include aliases in response + aliases?: boolean; + + // Include characters in response + chars?: boolean; + + // Include hidden icons + hidden?: boolean; +} + +export interface APIv2CollectionResponse { + // Icon set prefix + prefix: string; + + // Number of icons (duplicate of info?.total) + total: number; + + // Icon set title, if available (duplicate of info?.name) + title?: string; + + // Icon set info + info?: IconifyInfo; + + // List of icons without categories + uncategorized?: string[]; + + // List of icons, sorted by category + categories?: Record; + + // List of hidden icons + hidden?: string[]; + + // List of aliases, key = alias, value = parent icon + aliases?: Record; + + // Characters, key = character, value = icon name + chars?: Record; + + // Themes + themes?: IconifyJSON['themes']; + prefixes?: IconifyJSON['prefixes']; + suffixes?: IconifyJSON['suffixes']; +} + +/** + * /search + */ +export interface APIv2SearchParams extends APIv2CommonParams { + // Search string + query: SearchQuery; + + // Maximum number of items in response + limit?: number; + + // Start index for results + start?: number; + + // Filter icon sets by prefixes + prefix?: string; // One prefix + collection?: string; // One prefix + prefixes?: PrefixesMatches; // Multiple prefixes or partial + + // Filter icon sets by category + category?: string; + + // Include similar keywords (partial matches for words), default = true + similar?: boolean; +} + +export interface APIv2SearchResponse { + // List of icons, including prefixes + icons: string[]; + + // Number of results. If same as `limit`, more results are available + total: number; + + // Number of results shown + limit: number; + + // Index of first result + start: number; + + // Info about icon sets + collections: Record; + + // Copy of request + request: APIv2SearchParams; +}