import type { EL } from "../node/el"; import { LawInfo } from "./lawinfo"; import type { Loader } from "./loaders/common"; import type { WorkersPool } from "./workersPool"; interface CoreQueryCriteria { match: (item: TItem) => boolean | Promise; } type QueryCriteria = CoreQueryCriteria | CoreQueryCriteria["match"]; interface AsyncIterable { [Symbol.asyncIterator](): AsyncIterator; } declare const symbolFinalyzeQueryItem: unique symbol; declare const symbolDoNotFinalize: unique symbol; interface QueryItem { [symbolFinalyzeQueryItem]: () => void; [symbolDoNotFinalize]: boolean; } /** * Options for {@link Query}. * * {@link Query} のオプション項目 */ export interface QueryOptions { /** * Whether to show progress message. * * 進捗状況を表示するかどうか。 */ showProgress: boolean; } /** * The query object that represents a source list and a filtering criteria. * * フィルタ条件と検索元リストを表すクエリオブジェクト。 * * @example * A `Query` works as an async generator. * * `Query` は async generator として使用できます。 * * ```ts * const query = new Query(population, criteria); * for await (const item of query) { * console.log(item); * } * ``` */ export declare class Query implements AsyncIterable { population: AsyncIterable; criteria: CoreQueryCriteria | null; options: QueryOptions; /** * Instanciate a `Query`. * @param population - a source list * @param criteria - a filtering criteria * @param options - options */ constructor(population: AsyncIterable, criteria: QueryCriteria | null, options?: Partial); protected new(population: AsyncIterable, criteria: QueryCriteria | null, overrideOptions?: Partial): this; [Symbol.asyncIterator](): AsyncGenerator; /** * Apply a function for each filtered item. * * フィルタ後の要素ごとに関数を実行します。 * * @param func - a function to be called for each filtered item
要素ごとに実行される関数 * @param criteria - an additional criteria applied after filtering / 関数実行後に適用するフィルタ条件 * @param options - options which override the original ones / 上書きするオプション項目 * @returns - a new `Query` that yields items returned by `func`
`func` の返り値を列挙する新しい `Query` */ map(func: (item: TItem) => T | Promise, criteria?: QueryCriteria | null, options?: Partial): Query>; mapWorkers(workersPool: WorkersPool, criteria?: QueryCriteria | null, options?: Partial): Query>; /** * Apply a function for each filtered item and iterate the merged object with the returned and original object. * * フィルタ後の要素ごとに関数を実行し、返り値と元の要素のプロパティをマージしたオブジェクトを列挙します。 * * @param func - a function to be called for each filtered item
要素ごとに実行される関数 * @param criteria - an additional criteria applied after merge / マージ後に適用するフィルタ条件 * @param options - options which override the original ones / 上書きするオプション項目 * @returns - a new `Query` that yields merged objects
マージされたオブジェクトを列挙する新しい `Query` */ assign(func: (item: TItem) => T | Promise, criteria?: QueryCriteria | null, options?: Partial): Query; /** * Apply an additional filter. * * フィルタを追加します。 * * @param criteria - an additional criteria / 追加するフィルタ条件 * @param options - options which override the original ones / 上書きするオプション項目 * @returns - a new `Query` that applies `criteria` to the filtered items of the original `Query`
フィルタ後の項目を検索元とし、`criteria` を検索条件とする新しい `Query` */ filter(criteria: QueryCriteria | null, options?: Partial): this; /** * Yield while `func` returns `true`. * * `func` が `true` を返す間、列挙を続けます。 * * @param func - a function to be called for each filtered item. Returning `false` terminates the iteration.
要素ごとに実行される関数。`false`を返すと列挙を停止します。 * @param yieldLast - whether to return the item that caused `func` returned `false`
`func`が`false`を返す要因となった要素を出力するかどうか * @param options - options which override the original ones / 上書きするオプション項目 * @returns - a new `Query` that yields while `func` returns `true`
`func` が `true` を返す間列挙を続ける新しい `Query` */ while(func: (item: TItem) => boolean | Promise, yieldLast?: boolean, options?: Partial): this; /** * Skip specified count. * * 指定した件数スキップします。 * * @param count - count to skip
スキップする件数 * @param options - options which override the original ones / 上書きするオプション項目 * @returns - a new `Query` that yields after skipping specified count.
指定した件数のスキップ後列挙を続ける新しい `Query` */ skip(count: number, options?: Partial): this; /** * Yield until it reaches the maximum count. * * 出力の最大件数を設定します。 * * @param max - the maximum count
最大件数 * @param options - options which override the original ones / 上書きするオプション項目 * @returns - a new `Query` that yields until it reaches the maximum count.
最大件数に達するまで列挙を続ける新しい `Query` */ limit(max: number, options?: Partial): this; /** * Yield a property of each item. * * 特定のプロパティの内容を一つ抜き出して列挙します。 * * @param key - the key of a property to be picked
抜き出すプロパティのキー * @returns - a new `Query` that yields the picked property
抜き出したプロパティの内容を列挙する新しい `Query` */ property(key: K): Query>; /** * Pick properties of each item. * * 特定のプロパティ以外のプロパティを削除したオブジェクトを列挙します。 * * @param keys - the keys of properties to be picked
抜き出すプロパティのキー * @returns - a new `Query` that yields the objects with the picked properties
プロパティを抜き出した新しいオブジェクトの内容を列挙する新しい `Query` */ pick(...keys: K[]): Query>>; /** * Generate an array from the `Query`. Running this function will invoke the whole iteration process of the `Query`. * * `Query` から配列を生成します。この関数を実行すると `Query` の列挙を最後まで実行します。 * * @param options * * - `options.preserveCache `: whether to suggest the `Query` to preserve the cached data for each item, which normally will be cleared after yield (default: `false`)
`Query`にキャッシュされたデータを削除せずそのまま残すかどうかを指示します。 * * @returns - a `Promise` that resolves a generated array
生成された配列を返す `Promise` */ toArray(options?: { preserveCache: boolean; }): Promise; /** * Invoke `func` for each filtered item. Running this function will invoke the whole iteration process of the `Query`. * * 列挙された要素ごとに `func` を実行します。この関数を実行すると `Query` の列挙を最後まで実行します。 * * @param func - a function to be called for each item
要素ごとに実行される関数 */ forEach(func: (item: TItem) => unknown | Promise): Promise; } /** * Lawtext query の法令検索パラメータです。 */ export interface LawCriteriaArgs { /** 法令IDのマッチに用いる正規表現 */ LawID?: RegExp; /** 法令番号のマッチに用いる正規表現 */ LawNum?: RegExp; /** 法令名のマッチに用いる正規表現 */ LawTitle?: RegExp; /** 施行済み法令かどうか */ Enforced?: boolean; Path?: RegExp; XmlName?: RegExp; /** この法令が参照している法令の法令番号のマッチに用いる正規表現 */ ReferencingLawNum?: RegExp; /** この法令を参照している法令の法令番号のマッチに用いる正規表現 */ ReferencedLawNum?: RegExp; /** 法令XML文字列のマッチに用いる正規表現 */ xml?: RegExp; /** 法令XMLのDOMを受け取り、マッチしたかどうかを返す関数。 */ document?: (document: XMLDocument) => boolean | Promise; el?: (el: EL) => boolean | Promise; } export type LawCriteria = QueryCriteria | LawCriteriaArgs; export declare class BaseLawCriteria implements CoreQueryCriteria { args: LawCriteriaArgs; constructor(args: Partial); match(item: LawQueryItem): Promise; } /** * {@link LawQuery} で列挙される、法令を表すオブジェクト。 */ export declare class LawQueryItem extends LawInfo implements QueryItem { loader: Loader | null; static fromLawInfo(lawInfo: LawInfo, loader: Loader | null): LawQueryItem; protected static initialCache: () => { imageData: Uint8Array | null; xml: string | null; document: XMLDocument | null; el: EL | null; }; protected _cache: { imageData: Uint8Array | null; xml: string | null; document: XMLDocument | null; el: EL | null; }; /** * e-Gov 法令APIから法令XMLを取得します。 * @returns 法令XML */ getXML(): Promise; /** * e-Gov 法令APIから法令XMLを取得し、`XMLDocument` として返します。 * @returns 法令XMLの `XMLDocument` */ getDocument(): Promise; getEl(): Promise; [symbolFinalyzeQueryItem](): void; [symbolDoNotFinalize]: boolean; /** * 「法令名(法令番号)」の形式の文字列を返します。未施行の場合は文頭に「【未施行】」を付します。 * @returns 文字列 */ toString(): string; } /** * Lawtext query の法令検索を行う {@link Query} の派生クラス。ここに列挙されているもの以外のクラスメンバーについては {@link Query} を参照してください。 */ export declare class LawQuery extends Query { constructor(population: AsyncIterable, criteria: LawCriteria | null, options?: Partial); protected new(population: AsyncIterable, criteria: LawCriteria | null, overrideOptions?: Partial): this; static fromFetchInfo(loader: Loader, criteria: LawCriteria | null, options?: Partial): LawQuery; filter(criteria: LawCriteria | null): this; assign(func: (item: TItem) => T | Promise, criteria?: LawCriteria | null, options?: Partial): LawQuery; /** * 法令XMLのDOMを取得して追加したオブジェクトを列挙します。 * @param ensure - 法令XMLが取得できたもののみを列挙するかどうか(デフォルト: `true`) * @param options - 上書きするオプション項目 * @returns - 法令XMLのDOMを `document` プロパティとして追加したオブジェクトを列挙する新しい `Query` */ assignDocument(ensure?: TEnsure, options?: Partial): LawQuery; } export {};