Skip to content

Commit

Permalink
chore: prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Jul 24, 2023
1 parent d96bd0a commit 043a844
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const sub = store.subscribe(
}

console.log('Result:', result)
}
},
)

// Later, to close subscription:
Expand Down
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="utf8" />
Expand Down
2 changes: 1 addition & 1 deletion src/browser/getDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const getDocuments: EnvImplementations['getDocuments'] = async function g
if (documentLimit && documents.length > documentLimit) {
reader.cancel('Reached document limit')
throw new Error(
`Error streaming dataset: Reached limit of ${documentLimit} documents. Try using the includeTypes option to reduce the amount of documents, or increase the limit.`
`Error streaming dataset: Reached limit of ${documentLimit} documents. Try using the includeTypes option to reduce the amount of documents, or increase the limit.`,
)
}
} while (!result.done)
Expand Down
4 changes: 2 additions & 2 deletions src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export function groqStore(config: Config): GroqStore {
if (config.token) {
if (!config.EventSource) {
throw new Error(
'When the `token` option is used the `EventSource` option must also be provided.'
'When the `token` option is used the `EventSource` option must also be provided.',
)
}
if (config.EventSource === window.EventSource)
throw new Error(
'When the `token` option is used the `EventSource` option must also be provided. ' +
'EventSource cannot be `window.EventSource`, as it does not support passing a token.'
'EventSource cannot be `window.EventSource`, as it does not support passing a token.',
)
}

Expand Down
4 changes: 2 additions & 2 deletions src/groqStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function groqStore(config: Config, envImplementations: EnvImplementations
documents = docs
executeThrottled()
},
envImplementations
envImplementations,
)
}

Expand Down Expand Up @@ -49,7 +49,7 @@ export function groqStore(config: Config, envImplementations: EnvImplementations
function subscribe<R = any>(
groqQuery: string,
params: Record<string, unknown>,
callback: (error: Error | undefined, result?: R) => void
callback: (error: Error | undefined, result?: R) => void,
): Subscription {
if (!config.listen) {
throw new Error('Cannot use `subscribe()` without `listen: true`')
Expand Down
16 changes: 8 additions & 8 deletions src/listen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ declare module 'event-source-polyfill' {
}

const isNativeBrowserEventSource = (
eventSource: EventSourceInstance
eventSource: EventSourceInstance,
): eventSource is InstanceType<typeof globalThis.EventSource> =>
typeof window !== 'undefined' &&
eventSource.addEventListener === window.EventSource.prototype.addEventListener

const isPolyfillEventSource = (
eventSource: EventSourceInstance
eventSource: EventSourceInstance,
): eventSource is InstanceType<typeof BrowserEventSource | typeof NodeEventSource> =>
!isNativeBrowserEventSource(eventSource)

const addEventSourceListener = (
eventSource: EventSourceInstance,
type: keyof SharedEventSourceEventMap,
listener: EventListener
listener: EventListener,
): void => {
if (isPolyfillEventSource(eventSource)) {
// Polyfilled event source does not accept option parameter
Expand Down Expand Up @@ -75,7 +75,7 @@ export function listen(
open: () => void
error: (err: Error) => void
next: (event: MutationEvent) => void
}
},
): Subscription {
const {projectId, dataset, token, includeTypes, requestTagPrefix} = config
const headers = token ? {Authorization: `Bearer ${token}`} : undefined
Expand All @@ -91,7 +91,7 @@ export function listen(
params: {includeTypes},
options,
}
: {query: '*', options}
: {query: '*', options},
)
const url = `https://${projectId}.api.sanity.io/v1/data/listen/${dataset}${searchParams}`
const es = new EventSourceImpl(url, {withCredentials: true, headers})
Expand All @@ -112,7 +112,7 @@ export function listen(
}

handlers.error(
new Error(data.message || data.error || `Listener returned HTTP ${data.statusCode}`)
new Error(data.message || data.error || `Listener returned HTTP ${data.statusCode}`),
)
})

Expand All @@ -122,8 +122,8 @@ export function listen(
const errorMessage = isErrorLike(err) ? ` (${err.message})` : ''
handlers.error(
new Error(
`Error establishing listener - check that the project ID and dataset are correct${hintSuffix}${errorMessage}`
)
`Error establishing listener - check that the project ID and dataset are correct${hintSuffix}${errorMessage}`,
),
)
})

Expand Down
2 changes: 1 addition & 1 deletion src/node/getDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const getDocuments: EnvImplementations['getDocuments'] = function getDocu

if (documentLimit && documents.length > documentLimit) {
reject(
new Error(`Error streaming dataset: Reached limit of ${documentLimit} documents`)
new Error(`Error streaming dataset: Reached limit of ${documentLimit} documents`),
)
response.destroy()
}
Expand Down
2 changes: 1 addition & 1 deletion src/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {applyPatch} from 'mendoza'

export function applyPatchWithoutRev(
doc: SanityDocument | null,
patch: unknown[]
patch: unknown[],
): SanityDocument | null {
const patchDoc = {...doc} as Omit<SanityDocument, '_rev'>
delete patchDoc._rev
Expand Down
4 changes: 2 additions & 2 deletions src/syncingDataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function noop() {
export function getSyncingDataset(
config: Config,
onNotifyUpdate: (docs: SanityDocument[]) => void,
{getDocuments, EventSource}: EnvImplementations
{getDocuments, EventSource}: EnvImplementations,
): Subscription & {loaded: Promise<void>} {
const {
projectId,
Expand Down Expand Up @@ -154,7 +154,7 @@ export function getSyncingDataset(

function applyBufferedMutations(
documents: SanityDocument[],
mutations: MutationEvent[]
mutations: MutationEvent[],
): SanityDocument[] {
// Group by document ID
const groups = new Map<string, MutationEvent[]>()
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface EnvImplementations {
options: Pick<
Config,
'projectId' | 'dataset' | 'token' | 'documentLimit' | 'includeTypes' | 'requestTagPrefix'
>
>,
) => Promise<SanityDocument[]>
}

Expand Down Expand Up @@ -91,7 +91,7 @@ export interface GroqStore {
subscribe: <R = any>(
groqQuery: string,
params: Record<string, unknown>,
callback: (err: Error | undefined, result?: R) => void
callback: (err: Error | undefined, result?: R) => void,
) => Subscription
close: () => Promise<void>
}
Expand Down
2 changes: 1 addition & 1 deletion test/allowList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ describe(
expect(await store.query(groq`count(*[_type == "product"])`)).toEqual(11)
})
},
{timeout: 30000}
{timeout: 30000},
)
2 changes: 1 addition & 1 deletion test/getDocuments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('getDocuments', () => {
expect(getDocuments).toBeCalledWith(
expect.objectContaining({
token: 'my-token',
})
}),
)
})
})
2 changes: 1 addition & 1 deletion test/limits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ describe(
}
})
},
{timeout: 30000}
{timeout: 30000},
)
6 changes: 3 additions & 3 deletions test/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ describe(
])

expect(await store.query(groq`*[_type == "vendor"][].title | order(@ asc) [3]`)).toEqual(
'Freia'
'Freia',
)
expect(new Set(await store.query(groq`array::unique(*._type)`))).toEqual(
new Set(['category', 'product', 'sanity.imageAsset', 'vendor'])
new Set(['category', 'product', 'sanity.imageAsset', 'vendor']),
)
})

Expand All @@ -57,7 +57,7 @@ describe(
])
})
},
{timeout: 30000}
{timeout: 30000},
)

describe('query without overlayDrafts', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/subscribe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe.runIf(config.token)(
default:
throw new Error(`Encountered more updates than expected (${numUpdates})`)
}
}
},
)

function runAssertions() {
Expand All @@ -203,5 +203,5 @@ describe.runIf(config.token)(
return waiter
})
},
{timeout: 15000}
{timeout: 15000},
)
2 changes: 1 addition & 1 deletion types/simple-get.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ declare module 'simple-get' {

function simpleGet(
options: Options,
callback: (err: Error | undefined, res: IncomingMessage) => void
callback: (err: Error | undefined, res: IncomingMessage) => void,
): void

export = simpleGet
Expand Down

0 comments on commit 043a844

Please sign in to comment.