@aiao/rxdb-plugin-search-react 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Aiao Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * rxdb-plugin-search-react - React 集成层
3
+ *
4
+ * 提供 `useSearch()` hook,将 `@aiao/rxdb-plugin-search` 的 `SearchHandle` 适配为 React 状态消费接口。
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ export { useSearch } from './use-search.js';
9
+ export type { SearchSourceLike, UseSearchReturn } from './use-search.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ "use client";
2
+ import { useCallback as e, useEffect as t, useMemo as n, useRef as r, useState as i } from "react";
3
+ import { Subscription as a } from "rxjs";
4
+ //#region src/use-search.ts
5
+ function o(o, s) {
6
+ let c = s?.initialQuery ?? "", l = r(null), u = r(null);
7
+ l.current === null && (l.current = o.search(c, s));
8
+ let d = l.current, [f, p] = i(c), [m, h] = i([]), [g, _] = i("idle"), [v, y] = i(void 0), [b, x] = i(!1);
9
+ t(() => {
10
+ u.current !== null && (clearTimeout(u.current), u.current = null);
11
+ let e = new a();
12
+ return e.add(d.results$.subscribe((e) => h(e))), e.add(d.state$.subscribe((e) => _(e))), e.add(d.error$.subscribe((e) => y(e))), e.add(d.hasMore$.subscribe((e) => x(e))), () => {
13
+ e.unsubscribe(), u.current = setTimeout(() => {
14
+ d.destroy(), l.current = null, u.current = null;
15
+ }, 0);
16
+ };
17
+ }, []);
18
+ let S = e((e) => {
19
+ p(e), d.setQuery(e);
20
+ }, [d]), C = e(() => {
21
+ p(""), d.clear();
22
+ }, [d]), w = e(() => d.retry(), [d]), T = e(() => d.loadMore(), [d]);
23
+ return n(() => ({
24
+ query: f,
25
+ setQuery: S,
26
+ results: m,
27
+ state: g,
28
+ error: v,
29
+ hasMore: b,
30
+ loadMore: T,
31
+ clear: C,
32
+ retry: w
33
+ }), [
34
+ f,
35
+ S,
36
+ m,
37
+ g,
38
+ v,
39
+ b,
40
+ T,
41
+ C,
42
+ w
43
+ ]);
44
+ }
45
+ //#endregion
46
+ export { o as useSearch };
@@ -0,0 +1,50 @@
1
+ import { SearchExecutionError, SearchOptions, SearchResult, SearchSourceLike, SearchState } from '../packages/rxdb-plugin-search/src/index.ts';
2
+ /**
3
+ * React 集成 - rxdb-plugin-search
4
+ *
5
+ * 提供 `useSearch()`,将 `SearchHandle` 的 Observable 适配为 React state;
6
+ * 通过 `useEffect` 清理函数在组件卸载时自动释放 handle。
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ export type { SearchSourceLike };
11
+ /**
12
+ * {@link useSearch} 返回值。
13
+ *
14
+ * @public
15
+ */
16
+ export interface UseSearchReturn {
17
+ /** 当前查询词 */
18
+ query: string;
19
+ /** 写入查询词;触发插件防抖 */
20
+ setQuery: (q: string) => void;
21
+ /** 当前结果 */
22
+ results: readonly SearchResult[];
23
+ /** 当前状态 */
24
+ state: SearchState;
25
+ /** 最近一次执行错误 */
26
+ error: SearchExecutionError | undefined;
27
+ /** 是否还有下一页 */
28
+ hasMore: boolean;
29
+ /** 加载下一页;无更多时 no-op */
30
+ loadMore: () => Promise<void>;
31
+ /** 清空查询与结果并回到 idle */
32
+ clear: () => void;
33
+ /** 在 error 状态下重试 */
34
+ retry: () => void;
35
+ }
36
+ /**
37
+ * 将 `SearchHandle` 的响应式输出适配为 React hook。
38
+ *
39
+ * @example
40
+ * ```tsx
41
+ * const { query, setQuery, results, state } = useSearch(db, { debounce: 200 });
42
+ * return <input value={query} onChange={e => setQuery(e.target.value)} />;
43
+ * ```
44
+ *
45
+ * @param source - 暴露 `search()` 方法的数据源(`RxDB` / `RxCollection`)
46
+ * @param options - 单次调用级 {@link SearchOptions}
47
+ * @public
48
+ */
49
+ export declare function useSearch(source: SearchSourceLike, options?: SearchOptions): UseSearchReturn;
50
+ //# sourceMappingURL=use-search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-search.d.ts","sourceRoot":"","sources":["../src/use-search.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,oBAAoB,EAEpB,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACZ,MAAM,0BAA0B,CAAC;AAElC;;;;;;;GAOG;AAEH,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAEjC;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,YAAY;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,mBAAmB;IACnB,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,WAAW;IACX,OAAO,EAAE,SAAS,YAAY,EAAE,CAAC;IACjC,WAAW;IACX,KAAK,EAAE,WAAW,CAAC;IACnB,eAAe;IACf,KAAK,EAAE,oBAAoB,GAAG,SAAS,CAAC;IACxC,cAAc;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,uBAAuB;IACvB,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,sBAAsB;IACtB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,oBAAoB;IACpB,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,eAAe,CA0D5F"}
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@aiao/rxdb-plugin-search-react",
3
+ "version": "0.0.20",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "@aiao/source": "./src/index.ts",
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
17
+ "dependencies": {
18
+ "@aiao/rxdb-plugin-search": "0.0.20"
19
+ },
20
+ "peerDependencies": {
21
+ "@aiao/rxdb": "*",
22
+ "react": ">=18.0.0",
23
+ "rxjs": "^7.8.2",
24
+ "@aiao/rxdb-plugin-search": "0.0.20"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ }
29
+ }
package/project.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
3
+ "name": "rxdb-plugin-search-react",
4
+ "projectType": "library",
5
+ "sourceRoot": "packages/rxdb-plugin-search-react/src",
6
+ "tags": ["react-lib"],
7
+ "targets": {}
8
+ }
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ 'use client';
2
+
3
+ /**
4
+ * rxdb-plugin-search-react - React 集成层
5
+ *
6
+ * 提供 `useSearch()` hook,将 `@aiao/rxdb-plugin-search` 的 `SearchHandle` 适配为 React 状态消费接口。
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+
11
+ export { useSearch } from './use-search.js';
12
+ export type { SearchSourceLike, UseSearchReturn } from './use-search.js';
@@ -0,0 +1,151 @@
1
+ // @vitest-environment jsdom
2
+
3
+ import { act, renderHook } from '@testing-library/react';
4
+ import { StrictMode, createElement, type PropsWithChildren } from 'react';
5
+ import { BehaviorSubject } from 'rxjs';
6
+ import { afterEach, describe, expect, it, vi } from 'vitest';
7
+
8
+ import type { SearchExecutionError, SearchHandle, SearchResult, SearchState } from '@aiao/rxdb-plugin-search';
9
+
10
+ import { useSearch, type SearchSourceLike } from '../src/use-search.js';
11
+
12
+ const makeHandle = () => {
13
+ const results$ = new BehaviorSubject<SearchResult[]>([]);
14
+ const state$ = new BehaviorSubject<SearchState>('idle');
15
+ const error$ = new BehaviorSubject<SearchExecutionError | undefined>(undefined);
16
+ const hasMore$ = new BehaviorSubject<boolean>(false);
17
+ const destroyed = { value: false };
18
+ const setQuery = vi.fn();
19
+ const loadMore = vi.fn(async () => {
20
+ /* noop */
21
+ });
22
+ const clear = vi.fn();
23
+ const retry = vi.fn();
24
+
25
+ const handle: SearchHandle = {
26
+ results$,
27
+ state$,
28
+ error$,
29
+ hasMore$,
30
+ setQuery,
31
+ loadMore,
32
+ clear,
33
+ retry,
34
+ destroy: vi.fn(() => {
35
+ destroyed.value = true;
36
+ })
37
+ };
38
+ return { handle, results$, state$, error$, hasMore$, setQuery, loadMore, clear, retry, destroyed };
39
+ };
40
+
41
+ const makeSource = (handle: SearchHandle): SearchSourceLike & { searchSpy: ReturnType<typeof vi.fn> } => {
42
+ const searchSpy = vi.fn(() => handle);
43
+ return {
44
+ search: searchSpy,
45
+ searchSpy
46
+ };
47
+ };
48
+
49
+ afterEach(() => {
50
+ vi.useRealTimers();
51
+ });
52
+
53
+ describe('useSearch (React binding, T039)', () => {
54
+ it('initial render mirrors handle observables', () => {
55
+ const h = makeHandle();
56
+ const src = makeSource(h.handle);
57
+ const { result } = renderHook(() => useSearch(src));
58
+ expect(result.current.query).toBe('');
59
+ expect(result.current.results).toEqual([]);
60
+ expect(result.current.state).toBe('idle');
61
+ expect(result.current.hasMore).toBe(false);
62
+ expect(src.searchSpy).toHaveBeenCalledTimes(1);
63
+ });
64
+
65
+ it('setQuery forwards to handle.setQuery and updates local query state', () => {
66
+ const h = makeHandle();
67
+ const src = makeSource(h.handle);
68
+ const { result } = renderHook(() => useSearch(src));
69
+ act(() => result.current.setQuery('foo'));
70
+ expect(h.setQuery).toHaveBeenCalledWith('foo');
71
+ expect(result.current.query).toBe('foo');
72
+ });
73
+
74
+ it('handle observable updates propagate to hook state', () => {
75
+ const h = makeHandle();
76
+ const src = makeSource(h.handle);
77
+ const { result } = renderHook(() => useSearch(src));
78
+ const rows: SearchResult[] = [{ entity: 'A', collection: 'a', id: '1', rank: -1, matchedField: 'x', snippet: 's' }];
79
+ act(() => {
80
+ h.results$.next(rows);
81
+ h.state$.next('success');
82
+ h.hasMore$.next(true);
83
+ });
84
+ expect(result.current.results).toEqual(rows);
85
+ expect(result.current.state).toBe('success');
86
+ expect(result.current.hasMore).toBe(true);
87
+ });
88
+
89
+ it('unmount calls handle.destroy', () => {
90
+ vi.useFakeTimers();
91
+ const h = makeHandle();
92
+ const src = makeSource(h.handle);
93
+ const { unmount } = renderHook(() => useSearch(src));
94
+ unmount();
95
+ vi.runAllTimers();
96
+ expect(h.destroyed.value).toBe(true);
97
+ });
98
+
99
+ it('keeps the handle usable under React StrictMode double effects', () => {
100
+ vi.useFakeTimers();
101
+ const h = makeHandle();
102
+ const src = makeSource(h.handle);
103
+ const StrictWrapper = ({ children }: PropsWithChildren) => createElement(StrictMode, null, children);
104
+
105
+ const { result, unmount } = renderHook(() => useSearch(src), { wrapper: StrictWrapper });
106
+
107
+ act(() => {
108
+ vi.runAllTimers();
109
+ });
110
+ expect(h.destroyed.value).toBe(false);
111
+
112
+ act(() => result.current.setQuery('foo'));
113
+ expect(h.setQuery).toHaveBeenCalledWith('foo');
114
+ expect(result.current.query).toBe('foo');
115
+
116
+ unmount();
117
+ act(() => {
118
+ vi.runAllTimers();
119
+ });
120
+ expect(h.destroyed.value).toBe(true);
121
+ });
122
+
123
+ it('clear() resets query to empty and calls handle.clear', () => {
124
+ const h = makeHandle();
125
+ const src = makeSource(h.handle);
126
+ const { result } = renderHook(() => useSearch(src));
127
+ act(() => result.current.setQuery('foo'));
128
+ act(() => result.current.clear());
129
+ expect(h.clear).toHaveBeenCalledTimes(1);
130
+ expect(result.current.query).toBe('');
131
+ });
132
+
133
+ it('retry() and loadMore() forward to handle', async () => {
134
+ const h = makeHandle();
135
+ const src = makeSource(h.handle);
136
+ const { result } = renderHook(() => useSearch(src));
137
+ act(() => result.current.retry());
138
+ await act(async () => {
139
+ await result.current.loadMore();
140
+ });
141
+ expect(h.retry).toHaveBeenCalledTimes(1);
142
+ expect(h.loadMore).toHaveBeenCalledTimes(1);
143
+ });
144
+
145
+ it('passes initialQuery to source.search', () => {
146
+ const h = makeHandle();
147
+ const src = makeSource(h.handle);
148
+ renderHook(() => useSearch(src, { initialQuery: 'hi' }));
149
+ expect(src.searchSpy).toHaveBeenCalledWith('hi', { initialQuery: 'hi' });
150
+ });
151
+ });
@@ -0,0 +1,123 @@
1
+ 'use client';
2
+
3
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
+ import { Subscription } from 'rxjs';
5
+
6
+ import type {
7
+ SearchExecutionError,
8
+ SearchHandle,
9
+ SearchOptions,
10
+ SearchResult,
11
+ SearchSourceLike,
12
+ SearchState
13
+ } from '@aiao/rxdb-plugin-search';
14
+
15
+ /**
16
+ * React 集成 - rxdb-plugin-search
17
+ *
18
+ * 提供 `useSearch()`,将 `SearchHandle` 的 Observable 适配为 React state;
19
+ * 通过 `useEffect` 清理函数在组件卸载时自动释放 handle。
20
+ *
21
+ * @packageDocumentation
22
+ */
23
+
24
+ export type { SearchSourceLike };
25
+
26
+ /**
27
+ * {@link useSearch} 返回值。
28
+ *
29
+ * @public
30
+ */
31
+ export interface UseSearchReturn {
32
+ /** 当前查询词 */
33
+ query: string;
34
+ /** 写入查询词;触发插件防抖 */
35
+ setQuery: (q: string) => void;
36
+ /** 当前结果 */
37
+ results: readonly SearchResult[];
38
+ /** 当前状态 */
39
+ state: SearchState;
40
+ /** 最近一次执行错误 */
41
+ error: SearchExecutionError | undefined;
42
+ /** 是否还有下一页 */
43
+ hasMore: boolean;
44
+ /** 加载下一页;无更多时 no-op */
45
+ loadMore: () => Promise<void>;
46
+ /** 清空查询与结果并回到 idle */
47
+ clear: () => void;
48
+ /** 在 error 状态下重试 */
49
+ retry: () => void;
50
+ }
51
+
52
+ /**
53
+ * 将 `SearchHandle` 的响应式输出适配为 React hook。
54
+ *
55
+ * @example
56
+ * ```tsx
57
+ * const { query, setQuery, results, state } = useSearch(db, { debounce: 200 });
58
+ * return <input value={query} onChange={e => setQuery(e.target.value)} />;
59
+ * ```
60
+ *
61
+ * @param source - 暴露 `search()` 方法的数据源(`RxDB` / `RxCollection`)
62
+ * @param options - 单次调用级 {@link SearchOptions}
63
+ * @public
64
+ */
65
+ export function useSearch(source: SearchSourceLike, options?: SearchOptions): UseSearchReturn {
66
+ const initial = options?.initialQuery ?? '';
67
+ // 保持 handle 引用稳定:仅在 source 变化时重建
68
+ const handleRef = useRef<SearchHandle | null>(null);
69
+ const destroyTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
70
+ if (handleRef.current === null) {
71
+ handleRef.current = source.search(initial, options);
72
+ }
73
+ const handle = handleRef.current;
74
+
75
+ const [query, setQueryState] = useState<string>(initial);
76
+ const [results, setResults] = useState<readonly SearchResult[]>([]);
77
+ const [state, setState] = useState<SearchState>('idle');
78
+ const [error, setError] = useState<SearchExecutionError | undefined>(undefined);
79
+ const [hasMore, setHasMore] = useState<boolean>(false);
80
+
81
+ useEffect(() => {
82
+ if (destroyTimerRef.current !== null) {
83
+ clearTimeout(destroyTimerRef.current);
84
+ destroyTimerRef.current = null;
85
+ }
86
+
87
+ const subs = new Subscription();
88
+ subs.add(handle.results$.subscribe(r => setResults(r)));
89
+ subs.add(handle.state$.subscribe(s => setState(s)));
90
+ subs.add(handle.error$.subscribe(e => setError(e)));
91
+ subs.add(handle.hasMore$.subscribe(h => setHasMore(h)));
92
+ return () => {
93
+ subs.unsubscribe();
94
+ destroyTimerRef.current = setTimeout(() => {
95
+ handle.destroy();
96
+ handleRef.current = null;
97
+ destroyTimerRef.current = null;
98
+ }, 0);
99
+ };
100
+ // handle 生命周期由 ref 管理,仅挂载时订阅一次
101
+ }, []);
102
+
103
+ const setQuery = useCallback(
104
+ (q: string) => {
105
+ setQueryState(q);
106
+ handle.setQuery(q);
107
+ },
108
+ [handle]
109
+ );
110
+
111
+ const clear = useCallback(() => {
112
+ setQueryState('');
113
+ handle.clear();
114
+ }, [handle]);
115
+
116
+ const retry = useCallback(() => handle.retry(), [handle]);
117
+ const loadMore = useCallback(() => handle.loadMore(), [handle]);
118
+
119
+ return useMemo(
120
+ () => ({ query, setQuery, results, state, error, hasMore, loadMore, clear, retry }),
121
+ [query, setQuery, results, state, error, hasMore, loadMore, clear, retry]
122
+ );
123
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "files": [],
4
+ "include": [],
5
+ "references": [
6
+ {
7
+ "path": "./tsconfig.lib.json"
8
+ },
9
+ {
10
+ "path": "./tsconfig.spec.json"
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "dist",
4
+ "types": ["node", "vite/client"],
5
+ "rootDir": "src",
6
+ "jsx": "react-jsx",
7
+ "module": "esnext",
8
+ "moduleResolution": "bundler",
9
+ "tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo"
10
+ },
11
+ "exclude": [
12
+ "out-tsc",
13
+ "dist",
14
+ "**/*.spec.ts",
15
+ "**/*.test.ts",
16
+ "**/*.spec.tsx",
17
+ "**/*.test.tsx",
18
+ "vite.config.ts",
19
+ "vite.config.mts",
20
+ "vitest.config.ts",
21
+ "vitest.config.mts",
22
+ "eslint.config.js",
23
+ "eslint.config.cjs",
24
+ "eslint.config.mjs"
25
+ ],
26
+ "extends": "../../tsconfig.base.json",
27
+ "include": ["src/**/*.ts", "src/**/*.tsx"],
28
+ "references": [
29
+ {
30
+ "path": "../rxdb-plugin-search/tsconfig.lib.json"
31
+ },
32
+ {
33
+ "path": "../rxdb/tsconfig.lib.json"
34
+ }
35
+ ]
36
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./out-tsc/vitest",
4
+ "types": ["vitest/globals", "vitest/importMeta", "vite/client", "node", "vitest"],
5
+ "jsx": "react-jsx",
6
+ "module": "esnext",
7
+ "moduleResolution": "bundler"
8
+ },
9
+ "extends": "../../tsconfig.base.json",
10
+ "include": [
11
+ "vite.config.ts",
12
+ "vite.config.mts",
13
+ "vitest.config.ts",
14
+ "vitest.config.mts",
15
+ "src/**/*.test.ts",
16
+ "src/**/*.spec.ts",
17
+ "src/**/*.test.tsx",
18
+ "src/**/*.spec.tsx",
19
+ "src/**/*.d.ts"
20
+ ],
21
+ "references": [
22
+ {
23
+ "path": "./tsconfig.lib.json"
24
+ }
25
+ ]
26
+ }
@@ -0,0 +1,55 @@
1
+ /// <reference types='vitest' />
2
+ import { codecovVitePlugin } from '@codecov/vite-plugin';
3
+ import react from '@vitejs/plugin-react';
4
+ import * as path from 'path';
5
+ import { defineConfig } from 'vite';
6
+ import dts from 'vite-plugin-dts';
7
+
8
+ export default defineConfig(() => ({
9
+ root: import.meta.dirname,
10
+ cacheDir: '../../node_modules/.vite/packages/rxdb-plugin-search-react',
11
+ plugins: [
12
+ react(),
13
+ dts({ entryRoot: 'src', tsconfigPath: path.join(import.meta.dirname, 'tsconfig.lib.json') }),
14
+ ...(process.env.CI === 'true' && process.env.CODECOV_TOKEN ?
15
+ [
16
+ codecovVitePlugin({
17
+ enableBundleAnalysis: true,
18
+ telemetry: false,
19
+ bundleName: 'rxdb-plugin-search-react',
20
+ uploadToken: process.env.CODECOV_TOKEN
21
+ })
22
+ ]
23
+ : [])
24
+ ],
25
+ build: {
26
+ outDir: './dist',
27
+ emptyOutDir: true,
28
+ reportCompressedSize: true,
29
+ commonjsOptions: {
30
+ transformMixedEsModules: true
31
+ },
32
+ lib: {
33
+ entry: 'src/index.ts',
34
+ name: 'rxdb-plugin-search-react',
35
+ fileName: 'index',
36
+ formats: ['es' as const]
37
+ },
38
+ rollupOptions: {
39
+ external: [/^@aiao\//, 'react', 'react-dom', 'react/jsx-runtime', 'rxjs']
40
+ }
41
+ },
42
+ test: {
43
+ name: 'rxdb-plugin-search-react',
44
+ watch: false,
45
+ globals: true,
46
+ environment: 'jsdom',
47
+ include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
48
+ passWithNoTests: true,
49
+ reporters: ['default'],
50
+ coverage: {
51
+ reportsDirectory: './test-output/vitest/coverage',
52
+ provider: 'v8' as const
53
+ }
54
+ }
55
+ }));