From 6bf2616711ae27e1c70bc9a67703ca67c2614d0b Mon Sep 17 00:00:00 2001 From: Hunter Tunnicliff Date: Fri, 11 Oct 2024 15:59:59 -0700 Subject: [PATCH] Apply formatting --- biome.json => biome.jsonc | 7 +++ src/capabilities.ts | 4 +- src/client.ts | 90 +++++++++++++++++++-------------------- src/helpers.ts | 21 +++++---- src/request-drafts.ts | 18 ++++---- src/types/contracts.ts | 36 ++++++++-------- src/types/jmap-mail.ts | 22 +++++----- src/types/jmap.ts | 28 ++++++------ tsup.config.js | 4 +- 9 files changed, 117 insertions(+), 113 deletions(-) rename biome.json => biome.jsonc (78%) diff --git a/biome.json b/biome.jsonc similarity index 78% rename from biome.json rename to biome.jsonc index 3676aab..5ac3f4c 100644 --- a/biome.json +++ b/biome.jsonc @@ -22,6 +22,13 @@ "recommended": true, "style": { "noNonNullAssertion": "off" + }, + // Remove these once remedied: + "suspicious": { + "noExplicitAny": "warn" + }, + "complexity": { + "noBannedTypes": "warn" } } }, diff --git a/src/capabilities.ts b/src/capabilities.ts index 182e6a8..ff49f3d 100644 --- a/src/capabilities.ts +++ b/src/capabilities.ts @@ -11,7 +11,7 @@ export const knownCapabilities = { SearchSnippet: "urn:ietf:params:jmap:mail", Identity: "urn:ietf:params:jmap:submission", EmailSubmission: "urn:ietf:params:jmap:submission", - VacationResponse: "urn:ietf:params:jmap:vacationresponse", + VacationResponse: "urn:ietf:params:jmap:vacationresponse" }; /** @@ -25,7 +25,7 @@ const entityMatcher = /^(\w+)\//; */ export function getCapabilitiesForMethodCalls({ methodNames, - availableCapabilities, + availableCapabilities }: { methodNames: Iterable; availableCapabilities: ReadonlyMap; diff --git a/src/client.ts b/src/client.ts index 212e013..ee0f567 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,30 +1,30 @@ import { getCapabilitiesForMethodCalls, - knownCapabilities, + knownCapabilities } from "./capabilities.ts"; import { expandURITemplate, getErrorFromInvocation, - getResultsForMethodCalls, + getResultsForMethodCalls } from "./helpers.ts"; import { - WithRefValues, - WithoutRefValues, - buildRequestsFromDrafts, type DraftsProxy, type InvocationDraft, + type WithRefValues, + type WithoutRefValues, + buildRequestsFromDrafts } from "./request-drafts.ts"; -import { - type GetArgs, - type GetResponseData, - type LocalInvocation, - type Meta, - type Methods, - type ProxyAPI, - type RequestOptions, +import type { + GetArgs, + GetResponseData, + LocalInvocation, + Meta, + Methods, + ProxyAPI, + RequestOptions } from "./types/contracts.ts"; -import type * as JMAP from "./types/jmap.ts"; import type * as JMAPMail from "./types/jmap-mail.ts"; +import type * as JMAP from "./types/jmap.ts"; export type ClientConfig = { /** @@ -75,7 +75,7 @@ export class JamClient { this.capabilities = new Map([ ...Object.entries(config.customCapabilities ?? {}), - ...Object.entries(knownCapabilities), + ...Object.entries(knownCapabilities) ]); this.session = JamClient.loadSession(config.sessionUrl, this.authHeader); @@ -91,9 +91,9 @@ export class JamClient { return fetch(sessionUrl, { headers: { Authorization: authHeader, - Accept: "application/json", + Accept: "application/json" }, - cache: "no-cache", + cache: "no-cache" }).then((res) => res.json()); } @@ -111,7 +111,7 @@ export class JamClient { const { using = [], fetchInit, - createdIds: createdIdsInput, + createdIds: createdIdsInput } = options ?? {}; // Assemble method call @@ -122,12 +122,12 @@ export class JamClient { using: [ ...getCapabilitiesForMethodCalls({ methodNames: [method], - availableCapabilities: this.capabilities, + availableCapabilities: this.capabilities }), - ...using, + ...using ], methodCalls: [invocation], - createdIds: createdIdsInput, + createdIds: createdIdsInput }; // Ensure session is loaded (if not already) @@ -139,10 +139,10 @@ export class JamClient { headers: { Authorization: this.authHeader, Accept: "application/json", - "Content-Type": "application/json", + "Content-Type": "application/json" }, body: JSON.stringify(body), - ...fetchInit, + ...fetchInit }); // Handle 4xx-5xx errors @@ -160,7 +160,7 @@ export class JamClient { const { methodResponses: [methodResponse], sessionState, - createdIds, + createdIds } = (await response.json()) as JMAP.Response<[JMAP.Invocation]>; const error = getErrorFromInvocation(methodResponse); @@ -173,8 +173,8 @@ export class JamClient { { sessionState, createdIds, - response, - }, + response + } ]; } @@ -206,12 +206,12 @@ export class JamClient { using: [ ...getCapabilitiesForMethodCalls({ methodNames, - availableCapabilities: this.capabilities, + availableCapabilities: this.capabilities }), - ...using, + ...using ], methodCalls, - createdIds: createdIdsInput, + createdIds: createdIdsInput }; // Ensure session is loaded (if not already) @@ -223,10 +223,10 @@ export class JamClient { headers: { Authorization: this.authHeader, Accept: "application/json", - "Content-Type": "application/json", + "Content-Type": "application/json" }, body: JSON.stringify(body), - ...fetchInit, + ...fetchInit }); // Handle 4xx-5xx errors @@ -249,7 +249,7 @@ export class JamClient { const meta: Meta = { sessionState, createdIds, - response, + response }; const errors = methodResponses @@ -263,7 +263,7 @@ export class JamClient { return [ // @ts-expect-error TODO getResultsForMethodCalls(methodResponses, { returnErrors: false }), - meta, + meta ]; } @@ -285,7 +285,7 @@ export class JamClient { const { uploadUrl } = await this.session; const params: JMAP.BlobUploadParams = { - accountId, + accountId }; const url = expandURITemplate(uploadUrl, params); @@ -295,18 +295,17 @@ export class JamClient { method: "POST", headers: { Authorization: this.authHeader, - Accept: "application/json", + Accept: "application/json" }, body, - ...fetchInit, + ...fetchInit }); if (!response.ok) { if (response.headers.get("Content-Type")?.includes("json")) { throw (await response.json()) as JMAP.ProblemDetails; - } else { - throw await response.text(); } + throw await response.text(); } return (await response.json()) as JMAP.BlobUploadResponse; @@ -333,7 +332,7 @@ export class JamClient { accountId: options.accountId, blobId: options.blobId, type: options.mimeType, - name: options.fileName, + name: options.fileName }; const url = expandURITemplate(downloadUrl, params); @@ -342,17 +341,16 @@ export class JamClient { const response = await fetch(url, { method: "GET", headers: { - Authorization: this.authHeader, + Authorization: this.authHeader }, - ...fetchInit, + ...fetchInit }); if (!response.ok) { if (response.headers.get("Content-Type")?.includes("json")) { throw (await response.json()) as JMAP.ProblemDetails; - } else { - throw await response.text(); } + throw await response.text(); } return response; @@ -372,7 +370,7 @@ export class JamClient { const params: JMAP.EventSourceArguments = { types: options.types === "*" ? "*" : options.types.join(","), closeafter: options.closeafter ?? "no", - ping: `${options.ping}`, + ping: `${options.ping}` }; const { eventSourceUrl } = await this.session; @@ -411,9 +409,9 @@ export class JamClient { return this.request([method, args], options); }; - }, + } } - ), + ) }); } diff --git a/src/helpers.ts b/src/helpers.ts index 5acb541..8eca5ad 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -12,7 +12,7 @@ export function expandURITemplate( let expanded = template; for (const [key, value] of Object.entries(params)) { - const parameter = "{" + key + "}"; + const parameter = `{${key}}`; if (!expanded.includes(parameter)) { throw new Error(`Template "${template}" is missing parameter: ${key}`); } @@ -58,18 +58,17 @@ export function getResultsForMethodCalls( id, { data: null, - error: data as ProblemDetails, - }, - ]; - } else { - return [ - id, - { - data, - error: null, - }, + error: data as ProblemDetails + } ]; } + return [ + id, + { + data, + error: null + } + ]; }) ); } diff --git a/src/request-drafts.ts b/src/request-drafts.ts index 7b609ca..1c24eb9 100644 --- a/src/request-drafts.ts +++ b/src/request-drafts.ts @@ -1,9 +1,9 @@ import type { ExcludeValue, IncludeValue } from "./helpers.ts"; -import { LocalInvocation, Methods, Requests } from "./types/contracts.ts"; +import type { LocalInvocation, Methods, Requests } from "./types/contracts.ts"; import type { - Invocation, ExtendedJSONPointer, - ResultReference, + Invocation, + ResultReference } from "./types/jmap.ts"; /** @@ -43,8 +43,8 @@ export class InvocationDraft { return { [r]: { path, - invocation: this.#invocation, - }, + invocation: this.#invocation + } }; } @@ -92,8 +92,8 @@ export class InvocationDraft { { name: invocation[0], // Ref method resultOf: invocationToId.get(invocation)!, // Ref ID - path, - } satisfies ResultReference, + path + } satisfies ResultReference ]; } @@ -145,9 +145,9 @@ export function buildRequestsFromDrafts< return new InvocationDraft(invocation); }; - }, + } } - ), + ) }); // Create invocation drafts diff --git a/src/types/contracts.ts b/src/types/contracts.ts index 4ebde99..e5aff81 100644 --- a/src/types/contracts.ts +++ b/src/types/contracts.ts @@ -1,5 +1,20 @@ import type { Exact } from "type-fest"; import type { HasAllKeysOfRelated } from "../helpers.ts"; +import type { + Email, + EmailFilterCondition, + EmailImport, + EmailSubmission, + EmailSubmissionFilterCondition, + GetValueFromHeaderKey, + HeaderFieldKey, + Identity, + Mailbox, + MailboxFilterCondition, + SearchSnippet, + Thread, + VacationResponse +} from "./jmap-mail.ts"; import type { BlobCopyArguments, BlobCopyResponse, @@ -21,23 +36,8 @@ import type { QueryResponse, SetArguments, SetError, - SetResponse, + SetResponse } from "./jmap.ts"; -import type { - Email, - EmailFilterCondition, - EmailImport, - EmailSubmission, - EmailSubmissionFilterCondition, - GetValueFromHeaderKey, - HeaderFieldKey, - Identity, - Mailbox, - MailboxFilterCondition, - SearchSnippet, - Thread, - VacationResponse, -} from "./jmap-mail.ts"; export type Requests = { // Core ----------------------------------- @@ -297,8 +297,8 @@ export type GetEmailResponse = Args extends GetEmailArguments [Key in P]: Key extends HeaderFieldKey ? GetValueFromHeaderKey : Key extends keyof Email - ? Email[Key] - : never; + ? Email[Key] + : never; } : Email >; diff --git a/src/types/jmap-mail.ts b/src/types/jmap-mail.ts index d9071e5..35644aa 100644 --- a/src/types/jmap-mail.ts +++ b/src/types/jmap-mail.ts @@ -415,14 +415,14 @@ export type GetValueFromHeaderKey = ? HeaderParsedForm[Form] : Array : K extends `header:${string}:as${infer Form extends keyof HeaderParsedForm}` - ? HeaderParsedForm[Form] - : K extends `header:${string}:all` - ? string[] - : K extends `header:${infer Name extends string}` - ? Name extends `:${string}` | `${string}:` | `:${string}:` - ? never - : string - : never; + ? HeaderParsedForm[Form] + : K extends `header:${string}:all` + ? string[] + : K extends `header:${infer Name extends string}` + ? Name extends `:${string}` | `${string}:` | `:${string}:` + ? never + : string + : never; /** * [rfc8621 ยง 4.1.3](https://datatracker.ietf.org/doc/html/rfc8621#section-4.1.3) @@ -1101,7 +1101,7 @@ export enum DeliveryStatusDelivered { * information is available). The `smtpReply` property may * still change if a DSN arrives. */ - Unknown = "unknown", + Unknown = "unknown" } /** @@ -1120,7 +1120,7 @@ export enum DeliveryStatusDisplayed { * guarantee that the recipient has noticed, read, or * understood the content. */ - Yes = "yes", + Yes = "yes" } /** @@ -1177,7 +1177,7 @@ export enum UndoStatus { * The submission was canceled and will not be * delivered to any recipient. */ - Canceled = "canceled", + Canceled = "canceled" } // ================================= diff --git a/src/types/jmap.ts b/src/types/jmap.ts index 48d9a6d..628cb89 100644 --- a/src/types/jmap.ts +++ b/src/types/jmap.ts @@ -1,4 +1,4 @@ -import { Except } from "type-fest"; +import type { Except } from "type-fest"; import type { Obj } from "../helpers.ts"; /** @@ -352,7 +352,7 @@ export enum RequestErrorProblemType { * "limit" property MUST also be present on the "problem details" * object, containing the name of the limit being applied. */ - Limit = "urn:ietf:params:jmap:error:limit", + Limit = "urn:ietf:params:jmap:error:limit" } /** @@ -466,7 +466,7 @@ export enum MethodErrorType { * (as returned on the corresponding Account object in the * JMAP Session resource). */ - AccountReadOnly = "accountReadOnly", + AccountReadOnly = "accountReadOnly" } // ================================= @@ -547,7 +547,7 @@ export enum GetRequestErrorType { * the maximum number the server is willing to process in a single * method call. */ - RequestTooLarge = "requestTooLarge", + RequestTooLarge = "requestTooLarge" } /** @@ -623,7 +623,7 @@ export enum ChangesRequestErrorType { * produce an update to an intermediate state when there are too many * updates. The client MUST invalidate its `T` cache. */ - CannotCalculateChanges = "cannotCalculateChanges", + CannotCalculateChanges = "cannotCalculateChanges" } /** @@ -830,7 +830,7 @@ export enum SetErrorType { * (create; destroy). This is a singleton type, so you * cannot create another one or destroy the existing one. */ - Singleton = "singleton", + Singleton = "singleton" } export enum SetRequestErrorType { @@ -844,7 +844,7 @@ export enum SetRequestErrorType { * An `ifInState` argument was supplied, and it does * not match the current state. */ - StateMismatch = "stateMismatch", + StateMismatch = "stateMismatch" } /** @@ -950,7 +950,7 @@ export enum CopySetErrorType { * type "Id" MUST be included on the SetError object with the id of the * existing record. */ - AlreadyExists = "alreadyExists", + AlreadyExists = "alreadyExists" } export enum CopyRequestErrorType { @@ -970,7 +970,7 @@ export enum CopyRequestErrorType { * match the current state, or an `ifFromInState` argument was supplied * and it does not match the current state in the from account. */ - StateMismatch = "stateMismatch", + StateMismatch = "stateMismatch" } /** @@ -1127,7 +1127,7 @@ export enum QueryRequestErrorType { * search input, the client SHOULD suggest that the user simplify their * search. */ - UnsupportedFilter = "unsupportedFilter", + UnsupportedFilter = "unsupportedFilter" } /** @@ -1241,7 +1241,7 @@ export enum QueryChangesRequestErrorType { * client's state being too old. The client MUST invalidate its cache * of the query results. */ - CannotCalculateChanges = "cannotCalculateChanges", + CannotCalculateChanges = "cannotCalculateChanges" } export type QueryChangesAddedItem = { @@ -1270,7 +1270,7 @@ export enum FilterOperatorType { /** * None of the conditions must match for the filter to match. */ - Not = "NOT", + Not = "NOT" } export type FilterCondition = Except< @@ -1416,7 +1416,7 @@ export enum BlobCopySetErrorType { * The `fromAccountId` included with the request * does not correspond to a valid account. */ - FromAccountNotFound = "fromAccountNotFound", + FromAccountNotFound = "fromAccountNotFound" } // ================================= @@ -1575,5 +1575,5 @@ export enum EventSourceCloseAfterType { * The connection is persisted by the server as a standard * event-source resource. */ - No = "no", + No = "no" } diff --git a/tsup.config.js b/tsup.config.js index f15450e..16c7426 100644 --- a/tsup.config.js +++ b/tsup.config.js @@ -1,5 +1,5 @@ +import { execSync } from "node:child_process"; import { defineConfig } from "tsup"; -import { execSync } from "child_process"; export default defineConfig({ entry: ["src/index.ts"], @@ -12,5 +12,5 @@ export default defineConfig({ sourcemap: true, async onSuccess() { execSync("tsc"); - }, + } });