@aiao/rxdb-angular 0.0.7 → 0.0.9

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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/fesm2022/aiao-rxdb-angular.mjs +423 -0
  3. package/fesm2022/aiao-rxdb-angular.mjs.map +1 -0
  4. package/package.json +26 -13
  5. package/types/aiao-rxdb-angular.d.ts +222 -0
  6. package/eslint.config.mjs +0 -58
  7. package/ng-package.json +0 -7
  8. package/project.json +0 -48
  9. package/src/InfiniteScrollingList.ts +0 -123
  10. package/src/devtools/devtools.html +0 -99
  11. package/src/devtools/devtools.interface.ts +0 -3
  12. package/src/devtools/devtools.scss +0 -49
  13. package/src/devtools/devtools.spec.ts +0 -30
  14. package/src/devtools/devtools.ts +0 -207
  15. package/src/devtools/entity-table-item.ts +0 -47
  16. package/src/devtools/entity-table-tools.html +0 -56
  17. package/src/devtools/entity-table-tools.scss +0 -8
  18. package/src/devtools/entity-table-tools.ts +0 -153
  19. package/src/devtools/event-tools.html +0 -15
  20. package/src/devtools/event-tools.scss +0 -18
  21. package/src/devtools/event-tools.ts +0 -45
  22. package/src/devtools/scroll-advanced-calc.service.ts +0 -41
  23. package/src/devtools/settings.html +0 -46
  24. package/src/devtools/settings.scss +0 -19
  25. package/src/devtools/settings.ts +0 -122
  26. package/src/hooks.ts +0 -307
  27. package/src/index.ts +0 -7
  28. package/src/rxdb-change-detector.directive.spec.ts +0 -94
  29. package/src/rxdb-change-detector.directive.ts +0 -35
  30. package/src/rxdb.provider.ts +0 -13
  31. package/src/rxdb.service.spec.ts +0 -31
  32. package/src/rxdb.service.ts +0 -35
  33. package/src/test-setup.ts +0 -14
  34. package/src/use-action.spec.ts +0 -88
  35. package/src/use-action.ts +0 -20
  36. package/src/use-state.spec.ts +0 -105
  37. package/src/use-state.ts +0 -28
  38. package/tsconfig.json +0 -33
  39. package/tsconfig.lib.json +0 -42
  40. package/tsconfig.lib.prod.json +0 -10
  41. package/tsconfig.spec.json +0 -23
  42. package/vite.config.mts +0 -55
@@ -1,88 +0,0 @@
1
- import { provideZonelessChangeDetection } from '@angular/core';
2
- import { TestBed } from '@angular/core/testing';
3
- import { beforeEach, describe, expect, it, vi } from 'vitest';
4
- import { useAction } from './use-action';
5
-
6
- describe('useAction', () => {
7
- beforeEach(() => {
8
- TestBed.configureTestingModule({
9
- providers: [provideZonelessChangeDetection()]
10
- });
11
- });
12
- it('should create an action with isPending signal', () => {
13
- TestBed.runInInjectionContext(() => {
14
- const mockFn = vi.fn(async () => 'result');
15
- const action = useAction(mockFn);
16
-
17
- expect(action.isPending).toBeDefined();
18
- expect(action.execute).toBeDefined();
19
- expect(action.isPending()).toBe(false);
20
- });
21
- });
22
-
23
- it('should set isPending to true during execution', async () => {
24
- await TestBed.runInInjectionContext(async () => {
25
- let resolvePromise: (value: string) => void;
26
- const mockFn = vi.fn(
27
- () =>
28
- new Promise<string>(resolve => {
29
- resolvePromise = resolve;
30
- })
31
- );
32
- const action = useAction(mockFn);
33
-
34
- const executePromise = action.execute();
35
- expect(action.isPending()).toBe(true);
36
-
37
- resolvePromise!('result');
38
- await executePromise;
39
- expect(action.isPending()).toBe(false);
40
- });
41
- });
42
-
43
- it('should execute the promise function with options', async () => {
44
- await TestBed.runInInjectionContext(async () => {
45
- const mockFn = vi.fn(async (options?: { id: number }) => `result-${options?.id}`);
46
- const action = useAction(mockFn);
47
-
48
- const result = await action.execute({ id: 123 });
49
-
50
- expect(mockFn).toHaveBeenCalledWith({ id: 123 });
51
- expect(result).toBe('result-123');
52
- });
53
- });
54
-
55
- it('should reset isPending to false after success', async () => {
56
- await TestBed.runInInjectionContext(async () => {
57
- const mockFn = vi.fn(async () => 'success');
58
- const action = useAction(mockFn);
59
-
60
- await action.execute();
61
-
62
- expect(action.isPending()).toBe(false);
63
- });
64
- });
65
-
66
- it('should reset isPending to false after error', async () => {
67
- await TestBed.runInInjectionContext(async () => {
68
- const mockFn = vi.fn(async () => {
69
- throw new Error('test error');
70
- });
71
- const action = useAction(mockFn);
72
-
73
- await expect(action.execute()).rejects.toThrow('test error');
74
- expect(action.isPending()).toBe(false);
75
- });
76
- });
77
-
78
- it('should return the result from promise function', async () => {
79
- await TestBed.runInInjectionContext(async () => {
80
- const mockFn = vi.fn(async () => ({ data: 'test' }));
81
- const action = useAction(mockFn);
82
-
83
- const result = await action.execute();
84
-
85
- expect(result).toEqual({ data: 'test' });
86
- });
87
- });
88
- });
package/src/use-action.ts DELETED
@@ -1,20 +0,0 @@
1
- import { signal } from '@angular/core';
2
-
3
- const action = <Options = any, RT = any>(promiseFn: (options?: Options) => Promise<RT>) => {
4
- const isPending = signal<boolean>(false);
5
- return {
6
- isPending,
7
- execute: async (options?: Options) => {
8
- isPending.set(true);
9
- try {
10
- const d = await promiseFn(options);
11
- return d;
12
- } finally {
13
- isPending.set(false);
14
- }
15
- }
16
- };
17
- };
18
-
19
- export const useAction = <Options = any, RT = any>(promiseFn: (options?: Options) => Promise<RT>) =>
20
- action<Options, RT>(promiseFn);
@@ -1,105 +0,0 @@
1
- import { provideZonelessChangeDetection } from '@angular/core';
2
- import { TestBed } from '@angular/core/testing';
3
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
4
- import { useState } from './use-state';
5
-
6
- describe('useState', () => {
7
- const mockLocalStorage = (() => {
8
- let store: Record<string, string> = {};
9
- return {
10
- getItem: vi.fn((key: string) => store[key] || null),
11
- setItem: vi.fn((key: string, value: string) => {
12
- store[key] = value;
13
- }),
14
- clear: () => {
15
- store = {};
16
- }
17
- };
18
- })();
19
-
20
- beforeEach(() => {
21
- TestBed.configureTestingModule({
22
- providers: [provideZonelessChangeDetection()]
23
- });
24
- Object.defineProperty(globalThis, 'localStorage', {
25
- value: mockLocalStorage,
26
- writable: true
27
- });
28
- mockLocalStorage.clear();
29
- mockLocalStorage.getItem.mockClear();
30
- mockLocalStorage.setItem.mockClear();
31
- });
32
-
33
- afterEach(() => {
34
- TestBed.resetTestingModule();
35
- });
36
-
37
- it('should create a signal with initial value', () => {
38
- TestBed.runInInjectionContext(() => {
39
- const state = useState('test-namespace')('test-key');
40
- const testSignal = state.signal(42);
41
-
42
- expect(testSignal()).toBe(42);
43
- });
44
- });
45
-
46
- it('should load value from localStorage if exists', () => {
47
- mockLocalStorage.setItem('test-namespace:test-key', JSON.stringify(100));
48
-
49
- TestBed.runInInjectionContext(() => {
50
- const state = useState('test-namespace')('test-key');
51
- const testSignal = state.signal(42);
52
-
53
- expect(mockLocalStorage.getItem).toHaveBeenCalledWith('test-namespace:test-key');
54
- expect(testSignal()).toBe(100);
55
- });
56
- });
57
-
58
- it('should save value to localStorage on change', async () => {
59
- TestBed.runInInjectionContext(() => {
60
- const state = useState('test-namespace')('test-key');
61
- const testSignal = state.signal(42);
62
-
63
- testSignal.set(100);
64
-
65
- // Wait for effect to run
66
- TestBed.flushEffects();
67
-
68
- expect(mockLocalStorage.setItem).toHaveBeenCalledWith('test-namespace:test-key', JSON.stringify(100));
69
- });
70
- });
71
-
72
- it('should use namespace and name to construct storage key', () => {
73
- TestBed.runInInjectionContext(() => {
74
- const state = useState('my-app')('user-settings');
75
- state.signal({ theme: 'dark' });
76
-
77
- TestBed.flushEffects();
78
-
79
- expect(mockLocalStorage.setItem).toHaveBeenCalledWith('my-app:user-settings', JSON.stringify({ theme: 'dark' }));
80
- });
81
- });
82
-
83
- it('should handle objects and arrays', async () => {
84
- TestBed.runInInjectionContext(() => {
85
- const state = useState('test-namespace')('test-array');
86
- const testSignal = state.signal([1, 2, 3]);
87
-
88
- testSignal.set([4, 5, 6]);
89
-
90
- TestBed.flushEffects();
91
-
92
- expect(mockLocalStorage.setItem).toHaveBeenCalledWith('test-namespace:test-array', JSON.stringify([4, 5, 6]));
93
- });
94
- });
95
-
96
- it('should respect CreateSignalOptions', () => {
97
- TestBed.runInInjectionContext(() => {
98
- const equalFn = vi.fn((a: number, b: number) => a === b);
99
- const state = useState('test-namespace')('test-with-options');
100
- const testSignal = state.signal(42, { equal: equalFn });
101
-
102
- expect(testSignal()).toBe(42);
103
- });
104
- });
105
- });
package/src/use-state.ts DELETED
@@ -1,28 +0,0 @@
1
- import { IS_BROWSER } from '@aiao/utils';
2
- import { CreateSignalOptions, effect, signal as ngSignal, WritableSignal } from '@angular/core';
3
-
4
- function state(namespace: string) {
5
- return (name: string) => {
6
- const signal = <T>(initialValue: T, options?: CreateSignalOptions<T>): WritableSignal<T> => {
7
- if (IS_BROWSER) {
8
- const value = localStorage.getItem(`${namespace}:${name}`);
9
- if (value) {
10
- initialValue = JSON.parse(value);
11
- }
12
- }
13
- const a = ngSignal<T>(initialValue, options);
14
- effect(() => {
15
- if (IS_BROWSER) {
16
- localStorage.setItem(`${namespace}:${name}`, JSON.stringify(a()));
17
- }
18
- });
19
- return a;
20
- };
21
-
22
- return {
23
- signal
24
- };
25
- };
26
- }
27
-
28
- export const useState = (namespace: string) => state(namespace);
package/tsconfig.json DELETED
@@ -1,33 +0,0 @@
1
- {
2
- "angularCompilerOptions": {
3
- "enableI18nLegacyMessageIdFormat": false,
4
- "strictInjectionParameters": true,
5
- "strictInputAccessModifiers": true,
6
- "typeCheckHostBindings": true,
7
- "strictTemplates": true
8
- },
9
- "compilerOptions": {
10
- "skipLibCheck": true,
11
- "experimentalDecorators": true,
12
- "importHelpers": true,
13
- "target": "es2022",
14
- "moduleResolution": "bundler",
15
- "strict": true,
16
- "noImplicitOverride": true,
17
- "noPropertyAccessFromIndexSignature": true,
18
- "noImplicitReturns": true,
19
- "noFallthroughCasesInSwitch": true,
20
- "module": "preserve"
21
- },
22
- "extends": "../../tsconfig.angular.json",
23
- "files": [],
24
- "include": [],
25
- "references": [
26
- {
27
- "path": "./tsconfig.lib.json"
28
- },
29
- {
30
- "path": "./tsconfig.spec.json"
31
- }
32
- ]
33
- }
package/tsconfig.lib.json DELETED
@@ -1,42 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "../../dist/out-tsc",
4
- "declaration": true,
5
- "declarationMap": true,
6
- "sourceMap": true,
7
- "inlineSources": true,
8
- "module": "preserve",
9
- "moduleResolution": "bundler",
10
- "emitDeclarationOnly": false,
11
- "types": []
12
- },
13
- "exclude": [
14
- "src/**/*.spec.ts",
15
- "src/test-setup.ts",
16
- "jest.config.ts",
17
- "src/**/*.test.ts",
18
- "vite.config.ts",
19
- "vite.config.mts",
20
- "vitest.config.ts",
21
- "vitest.config.mts",
22
- "src/**/*.test.tsx",
23
- "src/**/*.spec.tsx",
24
- "src/**/*.test.js",
25
- "src/**/*.spec.js",
26
- "src/**/*.test.jsx",
27
- "src/**/*.spec.jsx"
28
- ],
29
- "extends": "./tsconfig.json",
30
- "include": ["src/**/*.ts"],
31
- "references": [
32
- {
33
- "path": "../rxdb-plugin-graph/tsconfig.lib.json"
34
- },
35
- {
36
- "path": "../utils/tsconfig.lib.json"
37
- },
38
- {
39
- "path": "../rxdb/tsconfig.lib.json"
40
- }
41
- ]
42
- }
@@ -1,10 +0,0 @@
1
- {
2
- "angularCompilerOptions": {
3
- "compilationMode": "partial"
4
- },
5
- "compilerOptions": {
6
- "declarationMap": false
7
- },
8
- "extends": "./tsconfig.lib.json",
9
- "include": ["src/**/*.ts"]
10
- }
@@ -1,23 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "../../dist/out-tsc",
4
- "types": ["node"]
5
- },
6
- "extends": "./tsconfig.json",
7
- "include": [
8
- "src/test-setup.ts",
9
- "vite.config.ts",
10
- "vite.config.mts",
11
- "vitest.config.ts",
12
- "vitest.config.mts",
13
- "src/**/*.test.ts",
14
- "src/**/*.spec.ts",
15
- "src/**/*.test.tsx",
16
- "src/**/*.spec.tsx",
17
- "src/**/*.test.js",
18
- "src/**/*.spec.js",
19
- "src/**/*.test.jsx",
20
- "src/**/*.spec.jsx",
21
- "src/**/*.d.ts"
22
- ]
23
- }
package/vite.config.mts DELETED
@@ -1,55 +0,0 @@
1
- /// <reference types='vitest' />
2
- import angular from '@analogjs/vite-plugin-angular';
3
- import { codecovVitePlugin } from '@codecov/vite-plugin';
4
- import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
5
- import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
6
- import * as path from 'path';
7
- import { fileURLToPath } from 'url';
8
- import { defineConfig } from 'vite';
9
-
10
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
-
12
- export default defineConfig({
13
- root: __dirname,
14
- cacheDir: '../../node_modules/.vite/packages/rxdb-angular',
15
- plugins: [
16
- angular(),
17
- nxViteTsPaths(),
18
- nxCopyAssetsPlugin(['*.md']),
19
- // Codecov Bundle Analysis - 仅在 CI 环境中启用
20
- ...(process.env['CI'] === 'true' && process.env['CODECOV_TOKEN'] ?
21
- [
22
- codecovVitePlugin({
23
- enableBundleAnalysis: true,
24
- telemetry: false,
25
- bundleName: 'rxdb-angular',
26
- uploadToken: process.env['CODECOV_TOKEN']
27
- })
28
- ]
29
- : [])
30
- ],
31
- // Uncomment this if you are using workers.
32
- // worker: {
33
- // plugins: [ nxViteTsPaths() ],
34
- // },
35
- test: {
36
- name: 'rxdb-angular',
37
- watch: false,
38
- globals: true,
39
- environment: 'happy-dom',
40
- passWithNoTests: true,
41
- testTimeout: 10000,
42
- hookTimeout: 10000,
43
- include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
44
- setupFiles: ['src/test-setup.ts'],
45
- reporters: ['default', 'junit'],
46
- outputFile: {
47
- junit: '../../coverage/packages/rxdb-angular/junit.xml'
48
- },
49
- coverage: {
50
- enabled: true,
51
- reportsDirectory: '../../coverage/packages/rxdb-angular',
52
- provider: 'v8' as const
53
- }
54
- }
55
- });