MCPcopy
hub / github.com/fingerprintjs/fingerprintjs / loadSources

Function loadSources

src/utils/entropy_source.ts:124–158  ·  view source on GitHub ↗
(
  sources: TSources,
  sourceOptions: TSourceOptions,
  excludeSources: readonly TExclude[],
  loopReleaseInterval?: number,
)

Source from the content-addressed store, hash-verified

122 * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
123 */
124export function loadSources<TSourceOptions, TSources extends UnknownSources<TSourceOptions>, TExclude extends string>(
125 sources: TSources,
126 sourceOptions: TSourceOptions,
127 excludeSources: readonly TExclude[],
128 loopReleaseInterval?: number,
129): () => Promise<Omit<SourcesToComponents<TSources>, TExclude>> {
130 const includedSources = Object.keys(sources).filter((sourceKey) => excludes(excludeSources, sourceKey)) as Exclude<
131 keyof TSources,
132 TExclude
133 >[]
134 // Using `mapWithBreaks` allows asynchronous sources to complete between synchronous sources
135 // and measure the duration correctly
136 const sourceGettersPromise = suppressUnhandledRejectionWarning(
137 mapWithBreaks(includedSources, (sourceKey) => loadSource(sources[sourceKey], sourceOptions), loopReleaseInterval),
138 )
139
140 return async function getComponents() {
141 const sourceGetters = await sourceGettersPromise
142
143 const componentPromises = await mapWithBreaks(
144 sourceGetters,
145 (sourceGetter) => suppressUnhandledRejectionWarning(sourceGetter()),
146 loopReleaseInterval,
147 )
148
149 const componentArray = await Promise.all(componentPromises)
150 // Keeping the component keys order the same as the source keys order
151 const components = {} as Omit<SourcesToComponents<TSources>, TExclude>
152 for (let index = 0; index < includedSources.length; ++index) {
153 components[includedSources[index]] = componentArray[index] as Component<any>
154 }
155
156 return components
157 }
158}
159
160/**
161 * Modifies an entropy source by transforming its returned value with the given function.

Callers 3

confidence.test.tsFile · 0.90
loadBuiltinSourcesFunction · 0.90

Calls 4

excludesFunction · 0.90
mapWithBreaksFunction · 0.90
loadSourceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…