FakeLayerSource
An in-memory LayerSource.
This is a class exported by @mapcairn/core, checked against version 0.2.0.
Signature
import { FakeLayerSource } from "@mapcairn/core";
class FakeLayerSource implements LayerSource
Description
How to script it, per layer id: setFeatures for what load returns
(none means an empty error), fail to reject with network or
invalid, setDetail for what loadDetail returns, and hold to make
every load wait until the returned function is called. The last call for a
layer wins. requests and detailRequests record what was asked, with the
URL the real source would have requested, worked out by the core URL
helpers. A detail URL off the definition's declared origins is refused
with invalid, as the real source does. Aborts are honoured before and
after a hold.
identify is scripted apart from load, also per layer id, so a layer
can be both loaded and identified without one affecting the other:
setIdentified for what it finds (a layer it was not told about finds
nothing and resolves to an empty list, never empty), failIdentify to
reject with network or invalid, and holdIdentify(layerId) to make
that one layer's identifies wait until the returned function is called.
hold does not hold an identify, and holdIdentify does not hold a load.
identifyRequests records what was asked, with the URL the real source
would have requested. A tap that cannot be turned into an https URL is
refused with invalid and not recorded, as a real source refuses it.
setOversizeAnswer makes the provider's answer to a load or to a detail
load larger than the source's limit, so the fake refuses it with invalid
as a real source does; the other kind of answer is not affected, so
features can load while their detail is refused. The fake applies no limit
to an identify answer. A second holdIdentify for
a layer replaces the first, and releasing the first leaves the second in
place.
Properties
detailRequests
readonly detailRequests: RecordedLayerRequest<LayerDetailRequest>[];
Every loadDetail request, in order, with the URL a real source would have fetched.
identifyRequests
readonly identifyRequests: RecordedLayerRequest<LayerIdentifyRequest>[];
Every identify request that was accepted, in order, with the URL a real source would have fetched.
requests
readonly requests: RecordedLayerRequest<LayerLoadRequest>[];
Every load request, in order, with the URL a real source would have fetched.
Methods
fail
fail(layerId: string, error: "network" | "invalid"): void;
Makes load for a layer reject with a LayerError of this kind.
layerId(string)error("network" | "invalid")
failIdentify
failIdentify(layerId: string, error: "network" | "invalid"): void;
Makes identify for a layer reject with a LayerError of this kind.
layerId(string)error("network" | "invalid")
hold
hold(): () => void;
Makes every load wait until the returned function is called.
holdIdentify
holdIdentify(layerId: string): () => void;
Makes every identify of one layer wait until the returned function is called. Other layers' identifies, and every load, are not held.
layerId(string)
identify
identify(request: LayerIdentifyRequest): Promise<readonly LayerFeature[]>;
Answers from setIdentified, resolving to an empty list for a layer that was not scripted.
request(LayerIdentifyRequest)
load
load(request: LayerLoadRequest): Promise<readonly LayerFeature[]>;
Answers from setFeatures, or rejects as fail or hold scripts. A layer with no features scripted rejects as empty.
request(LayerLoadRequest)
loadDetail
loadDetail(request: LayerDetailRequest): Promise<readonly LayerFeature[]>;
Answers from setDetail. A detail URL outside the definition's declared origins is refused as invalid.
request(LayerDetailRequest)
setDetail
setDetail(layerId: string, shapes: readonly LayerFeature[]): void;
Makes loadDetail for a layer return these shapes.
layerId(string)shapes(readonly LayerFeature[])
setFeatures
setFeatures(layerId: string, features: readonly LayerFeature[]): void;
Makes load for a layer return these features.
layerId(string)features(readonly LayerFeature[])
setIdentified
setIdentified(layerId: string, features: readonly LayerFeature[]): void;
Makes identify for a layer find these features.
layerId(string)features(readonly LayerFeature[])
setOversizeAnswer
setOversizeAnswer(layerId: string, kind: "feed" | "detail"): void;
Makes the answer load ("feed") or loadDetail ("detail")
reads for a layer larger than the source's limit, so it rejects with
invalid.
layerId(string)kind("feed" | "detail")