You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@annotator.apache.org by ge...@apache.org on 2022/11/23 21:38:22 UTC
[incubator-annotator] 02/02: Move refinedBy code into its own file
This is an automated email from the ASF dual-hosted git repository.
gerben pushed a commit to branch tweak-types
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git
commit 5875ed9564b7ff512915b66c443f4e8730111977
Author: Gerben <ge...@treora.com>
AuthorDate: Sun Nov 6 15:21:04 2022 +0100
Move refinedBy code into its own file
---
packages/selector/src/index.ts | 70 +-----------------------
packages/selector/src/{index.ts => refinable.ts} | 9 ---
2 files changed, 3 insertions(+), 76 deletions(-)
diff --git a/packages/selector/src/index.ts b/packages/selector/src/index.ts
index f75f6e1..2c15f8f 100644
--- a/packages/selector/src/index.ts
+++ b/packages/selector/src/index.ts
@@ -21,77 +21,13 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import type { Matcher, Selector } from './types.js';
-
-export type { Matcher, Selector } from './types.js';
export type {
+ Matcher,
+ Selector,
CssSelector,
RangeSelector,
TextPositionSelector,
TextQuoteSelector,
} from './types.js';
export * from './text/index.js';
-
-/**
- * A Refinable selector can have the `refinedBy` attribute, whose value must be
- * of the same type (possibly again refined, recursively).
- *
- * See {@link https://www.w3.org/TR/2017/REC-annotation-model-20170223/#refinement-of-selection
- * | §4.2.9 Refinement of Selection} in the Web Annotation Data Model.
- *
- * @example
- * Example value of type `Refinable<CssSelector, TextQuoteSelector>`:
- *
- * {
- * type: "CssSelector",
- * …,
- * refinedBy: {
- * type: "TextQuoteSelector",
- * …,
- * refinedBy: { … }, // again either a CssSelector or TextQuoteSelector
- * }
- * }
- */
-export type Refinable<T extends Selector> = T & { refinedBy?: Refinable<T> };
-
-/**
- * Wrap a matcher creation function so that it supports refinement of selection.
- *
- * See {@link https://www.w3.org/TR/2017/REC-annotation-model-20170223/#refinement-of-selection
- * | §4.2.9 Refinement of Selection} in the Web Annotation Data Model.
- *
- * @param matcherCreator - The function to wrap; it will be executed both for
- * {@link Selector}s passed to the returned wrapper function, and for any
- * refining Selector those might contain (and any refinement of that, etc.).
- *
- * @public
- */
-export function makeRefinable<
- TSelector extends Selector,
- TScope,
- // To enable refinement, the implementation’s Match object must be usable as a
- // Scope object itself.
- TMatch extends TScope
->(
- matcherCreator: (selector: Refinable<TSelector>) => Matcher<TScope, TMatch>,
-): (selector: Refinable<TSelector>) => Matcher<TScope, TMatch> {
- return function createMatcherWithRefinement(
- sourceSelector: Refinable<TSelector>,
- ): Matcher<TScope, TMatch> {
- const matcher = matcherCreator(sourceSelector);
-
- if (sourceSelector.refinedBy) {
- const refiningSelector = createMatcherWithRefinement(
- sourceSelector.refinedBy,
- );
-
- return async function* matchAll(scope) {
- for await (const match of matcher(scope)) {
- yield* refiningSelector(match);
- }
- };
- }
-
- return matcher;
- };
-}
+export * from './refinable.js';
diff --git a/packages/selector/src/index.ts b/packages/selector/src/refinable.ts
similarity index 93%
copy from packages/selector/src/index.ts
copy to packages/selector/src/refinable.ts
index f75f6e1..9bb1c1a 100644
--- a/packages/selector/src/index.ts
+++ b/packages/selector/src/refinable.ts
@@ -23,15 +23,6 @@
import type { Matcher, Selector } from './types.js';
-export type { Matcher, Selector } from './types.js';
-export type {
- CssSelector,
- RangeSelector,
- TextPositionSelector,
- TextQuoteSelector,
-} from './types.js';
-export * from './text/index.js';
-
/**
* A Refinable selector can have the `refinedBy` attribute, whose value must be
* of the same type (possibly again refined, recursively).