@tech4good/angular-schematics 21.3.0 → 21.4.0
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/.t4g/agent-memory.db +0 -0
- package/CHANGELOG.md +24 -0
- package/package.json +1 -1
- package/src/entity/index.js +42 -9
- package/src/entity/index.js.map +1 -1
- package/src/entity/index_spec.js +42 -8
- package/src/entity/index_spec.js.map +1 -1
- package/src/entity/schema.json +0 -5
- package/src/ng-add/files/.gitignore.template +1 -0
- package/src/ng-add/files/angular.json.template +3 -0
- package/src/ng-add/files/firestore.rules.spec.ts.template +88 -1
- package/src/ng-add/files/firestore.rules.template +9 -0
- package/src/ng-add/files/package.json.template +4 -2
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.spec.ts.template +3 -3
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.spec.ts.template +0 -1
- package/src/ng-add/files/src/app/app.component.html.template +1 -1
- package/src/ng-add/files/src/app/app.component.scss.template +9 -1
- package/src/ng-add/files/src/app/app.component.spec.ts.template +2 -2
- package/src/ng-add/files/src/app/auth-routing.spec.ts.template +1 -1
- package/src/ng-add/files/src/app/core/analytics/log.service.ts.template +1 -1
- package/src/ng-add/files/src/app/core/analytics/time-analytics.service.spec.ts.template +2 -2
- package/src/ng-add/files/src/app/core/firebase/cached-listeners.service.ts.template +53 -51
- package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +6 -0
- package/src/ng-add/files/src/app/core/firebase/simulate-load.spec.ts.template +2 -2
- package/src/ng-add/files/src/app/core/firebase/simulate-stream.spec.ts.template +14 -14
- package/src/ng-add/files/src/app/core/firebase/stream-multiplexer.ts.template +50 -48
- package/src/ng-add/files/src/app/core/logging/logging.service.spec.ts.template +118 -0
- package/src/ng-add/files/src/app/core/logging/logging.service.ts.template +168 -0
- package/src/ng-add/files/src/app/core/store/app.model.ts.template +3 -1
- package/src/ng-add/files/src/app/core/store/app.store.ts.template +11 -9
- package/src/ng-add/files/src/app/core/store/auth/auth.mock.ts.template +5 -4
- package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +13 -4
- package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +0 -4
- package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +0 -1
- package/src/ng-add/files/src/app/core/store/user-private/user-private.mock.ts.template +15 -0
- package/src/ng-add/files/src/app/core/store/user-private/user-private.model.ts.template +9 -0
- package/src/ng-add/files/src/app/core/store/user-private/user-private.store.ts.template +41 -0
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.spec.ts.template +0 -1
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +1 -1
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +3 -3
- package/src/ng-add/files/src/app/first-time/landing/landing.component.scss.template +1 -1
- package/src/ng-add/files/src/app/first-time/onboarding/onboarding.component.ts.template +3 -3
- package/src/ng-add/files/src/app/main/home/home.component.spec.ts.template +1 -1
- package/src/ng-add/files/src/app/main/home/home.component.ts.template +4 -4
- package/src/ng-add/files/src/app/shared/dev-status-bar/dev-status-bar.component.scss.template +1 -0
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.spec.ts.template +41 -5
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.ts.template +25 -2
- package/src/ng-add/files/src/environments/environment.test.ts.template +1 -1
- package/src/shared/statements-adder.d.ts +1 -0
- package/src/shared/statements-adder.js +8 -0
- package/src/shared/statements-adder.js.map +1 -1
- package/src/ng-add/files/src/app/core/firebase/query-logger.ts.template +0 -11
- package/tech4good-angular-schematics-21.0.0.tgz +0 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
import { LoggingService, getLogger } from './logging.service';
|
|
3
|
+
|
|
4
|
+
describe('LoggingService', () => {
|
|
5
|
+
let service: LoggingService;
|
|
6
|
+
let consoleLogSpy: jest.SpyInstance;
|
|
7
|
+
let consoleWarnSpy: jest.SpyInstance;
|
|
8
|
+
let consoleErrorSpy: jest.SpyInstance;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
localStorage.clear();
|
|
12
|
+
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
13
|
+
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
14
|
+
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
15
|
+
|
|
16
|
+
TestBed.configureTestingModule({
|
|
17
|
+
providers: [LoggingService],
|
|
18
|
+
});
|
|
19
|
+
service = TestBed.inject(LoggingService);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
jest.restoreAllMocks();
|
|
24
|
+
localStorage.clear();
|
|
25
|
+
if (typeof window !== 'undefined') {
|
|
26
|
+
delete (window as any).debugLogger;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should be created with logging disabled by default', () => {
|
|
31
|
+
expect(service).toBeTruthy();
|
|
32
|
+
expect(service.isEnabled()).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should register debugLogger on the window object', () => {
|
|
36
|
+
expect((window as any).debugLogger).toBe(service);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should enable logging and persist it to localStorage', () => {
|
|
40
|
+
service.enable();
|
|
41
|
+
expect(service.isEnabled()).toBe(true);
|
|
42
|
+
expect(localStorage.getItem('debug_logs')).toBe('true');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should disable logging and remove it from localStorage', () => {
|
|
46
|
+
service.enable();
|
|
47
|
+
service.disable();
|
|
48
|
+
expect(service.isEnabled()).toBe(false);
|
|
49
|
+
expect(localStorage.getItem('debug_logs')).toBeNull();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should toggle logging state correctly', () => {
|
|
53
|
+
service.toggle();
|
|
54
|
+
expect(service.isEnabled()).toBe(true);
|
|
55
|
+
service.toggle();
|
|
56
|
+
expect(service.isEnabled()).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should initialize state from localStorage if present', () => {
|
|
60
|
+
localStorage.setItem('debug_logs', 'true');
|
|
61
|
+
// Re-create the service to test constructor initialization
|
|
62
|
+
const newService = new LoggingService();
|
|
63
|
+
expect(newService.isEnabled()).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should not log to console if disabled', () => {
|
|
67
|
+
service.log('test log');
|
|
68
|
+
service.warn('test warn');
|
|
69
|
+
service.error('test error');
|
|
70
|
+
|
|
71
|
+
expect(consoleLogSpy).not.toHaveBeenCalled();
|
|
72
|
+
expect(consoleWarnSpy).not.toHaveBeenCalled();
|
|
73
|
+
expect(consoleErrorSpy).not.toHaveBeenCalled();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should log to console if enabled', () => {
|
|
77
|
+
service.enable();
|
|
78
|
+
service.log('test log', { foo: 'bar' });
|
|
79
|
+
service.warn('test warn');
|
|
80
|
+
service.error('test error');
|
|
81
|
+
|
|
82
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('test log', { foo: 'bar' });
|
|
83
|
+
expect(consoleWarnSpy).toHaveBeenCalledWith('test warn');
|
|
84
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('test error');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should support scoped loggers with namespaces', () => {
|
|
88
|
+
const queryLogger = getLogger('query');
|
|
89
|
+
const storeLogger = getLogger('store');
|
|
90
|
+
|
|
91
|
+
// 1. When disabled
|
|
92
|
+
queryLogger.log('query log');
|
|
93
|
+
expect(consoleLogSpy).not.toHaveBeenCalled();
|
|
94
|
+
|
|
95
|
+
// 2. Enabled generally (all namespaces)
|
|
96
|
+
service.enable('true');
|
|
97
|
+
queryLogger.log('query log');
|
|
98
|
+
storeLogger.log('store log');
|
|
99
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('query log');
|
|
100
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('store log');
|
|
101
|
+
consoleLogSpy.mockClear();
|
|
102
|
+
|
|
103
|
+
// 3. Enabled only for 'query'
|
|
104
|
+
service.enable('query');
|
|
105
|
+
queryLogger.log('query log');
|
|
106
|
+
storeLogger.log('store log');
|
|
107
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('query log');
|
|
108
|
+
expect(consoleLogSpy).not.toHaveBeenCalledWith('store log');
|
|
109
|
+
consoleLogSpy.mockClear();
|
|
110
|
+
|
|
111
|
+
// 4. Enabled for multiple specific namespaces
|
|
112
|
+
service.enable('query,store');
|
|
113
|
+
queryLogger.log('query log');
|
|
114
|
+
storeLogger.log('store log');
|
|
115
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('query log');
|
|
116
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('store log');
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { Injectable, signal } from '@angular/core';
|
|
2
|
+
import { environment } from '../../../environments/environment';
|
|
3
|
+
|
|
4
|
+
export let globalLogger: LoggingService | null = null;
|
|
5
|
+
|
|
6
|
+
export interface ScopedLogger {
|
|
7
|
+
log(message: string, ...args: unknown[]): void;
|
|
8
|
+
warn(message: string, ...args: unknown[]): void;
|
|
9
|
+
error(message: string, ...args: unknown[]): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getLogger(namespace: string): ScopedLogger {
|
|
13
|
+
return {
|
|
14
|
+
log: (message: string, ...args: unknown[]) => globalLogger?.logForNamespace(namespace, message, ...args),
|
|
15
|
+
warn: (message: string, ...args: unknown[]) => globalLogger?.warnForNamespace(namespace, message, ...args),
|
|
16
|
+
error: (message: string, ...args: unknown[]) => globalLogger?.errorForNamespace(namespace, message, ...args),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Service to handle toggleable debug logging across the application.
|
|
22
|
+
* Exposes methods to toggle logging and registers itself on `window.debugLogger`
|
|
23
|
+
* in browser contexts for easy console manipulation.
|
|
24
|
+
*
|
|
25
|
+
* Exposed to the browser console for dynamic runtime debugging.
|
|
26
|
+
* Commands you can run in your DevTools console:
|
|
27
|
+
* - Enable all logs: debugLogger.enable()
|
|
28
|
+
* - Enable specific: debugLogger.enable('query,store')
|
|
29
|
+
* - Disable logs: debugLogger.disable()
|
|
30
|
+
* - Toggle logs: debugLogger.toggle()
|
|
31
|
+
*/
|
|
32
|
+
@Injectable({
|
|
33
|
+
providedIn: 'root',
|
|
34
|
+
})
|
|
35
|
+
export class LoggingService {
|
|
36
|
+
private readonly enabled = signal<boolean>(false);
|
|
37
|
+
|
|
38
|
+
constructor() {
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
40
|
+
globalLogger = this;
|
|
41
|
+
if (typeof window !== 'undefined') {
|
|
42
|
+
try {
|
|
43
|
+
const debugLogsVal = window.localStorage.getItem('debug_logs');
|
|
44
|
+
const isEnabled = debugLogsVal !== null && debugLogsVal !== 'false';
|
|
45
|
+
this.enabled.set(isEnabled);
|
|
46
|
+
if (!environment.production) {
|
|
47
|
+
(window as unknown as Record<string, unknown>)['debugLogger'] = this;
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {
|
|
50
|
+
console.warn('LocalStorage is not accessible:', e);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private isNamespaceEnabled(namespace: string): boolean {
|
|
56
|
+
if (!this.enabled()) return false;
|
|
57
|
+
if (typeof window === 'undefined') return false;
|
|
58
|
+
try {
|
|
59
|
+
const filter = window.localStorage.getItem('debug_logs') || '';
|
|
60
|
+
if (filter === 'true' || filter === '*' || filter === '') return true;
|
|
61
|
+
const enabledNamespaces = filter.split(',').map((s) => s.trim());
|
|
62
|
+
return enabledNamespaces.includes(namespace);
|
|
63
|
+
} catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Enables logging output and persists the state. */
|
|
69
|
+
enable(namespaces = 'true'): void {
|
|
70
|
+
this.enabled.set(true);
|
|
71
|
+
if (typeof window !== 'undefined') {
|
|
72
|
+
try {
|
|
73
|
+
window.localStorage.setItem('debug_logs', namespaces);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.warn('Failed to save to LocalStorage:', e);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Disables logging output and clears the persisted state. */
|
|
81
|
+
disable(): void {
|
|
82
|
+
this.enabled.set(false);
|
|
83
|
+
if (typeof window !== 'undefined') {
|
|
84
|
+
try {
|
|
85
|
+
window.localStorage.removeItem('debug_logs');
|
|
86
|
+
} catch (e) {
|
|
87
|
+
console.warn('Failed to remove from LocalStorage:', e);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Toggles the logging state. */
|
|
93
|
+
toggle(): void {
|
|
94
|
+
if (this.enabled()) {
|
|
95
|
+
this.disable();
|
|
96
|
+
} else {
|
|
97
|
+
this.enable();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Returns whether logging is currently enabled. */
|
|
102
|
+
isEnabled(): boolean {
|
|
103
|
+
return this.enabled();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Logs standard message and arguments if logging is enabled globally. */
|
|
107
|
+
log(message: string, ...args: unknown[]): void {
|
|
108
|
+
if (this.enabled()) {
|
|
109
|
+
try {
|
|
110
|
+
const filter = typeof window !== 'undefined' ? window.localStorage.getItem('debug_logs') : null;
|
|
111
|
+
if (filter === 'true' || filter === '*' || filter === '' || filter === null) {
|
|
112
|
+
console.log(message, ...args);
|
|
113
|
+
}
|
|
114
|
+
} catch {
|
|
115
|
+
console.log(message, ...args);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Logs warning message and arguments if logging is enabled globally. */
|
|
121
|
+
warn(message: string, ...args: unknown[]): void {
|
|
122
|
+
if (this.enabled()) {
|
|
123
|
+
try {
|
|
124
|
+
const filter = typeof window !== 'undefined' ? window.localStorage.getItem('debug_logs') : null;
|
|
125
|
+
if (filter === 'true' || filter === '*' || filter === '' || filter === null) {
|
|
126
|
+
console.warn(message, ...args);
|
|
127
|
+
}
|
|
128
|
+
} catch {
|
|
129
|
+
console.warn(message, ...args);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Logs error message and arguments if logging is enabled globally. */
|
|
135
|
+
error(message: string, ...args: unknown[]): void {
|
|
136
|
+
if (this.enabled()) {
|
|
137
|
+
try {
|
|
138
|
+
const filter = typeof window !== 'undefined' ? window.localStorage.getItem('debug_logs') : null;
|
|
139
|
+
if (filter === 'true' || filter === '*' || filter === '' || filter === null) {
|
|
140
|
+
console.error(message, ...args);
|
|
141
|
+
}
|
|
142
|
+
} catch {
|
|
143
|
+
console.error(message, ...args);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Logs standard message for a specific namespace if enabled. */
|
|
149
|
+
logForNamespace(namespace: string, message: string, ...args: unknown[]): void {
|
|
150
|
+
if (this.isNamespaceEnabled(namespace)) {
|
|
151
|
+
console.log(message, ...args);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Logs warning message for a specific namespace if enabled. */
|
|
156
|
+
warnForNamespace(namespace: string, message: string, ...args: unknown[]): void {
|
|
157
|
+
if (this.isNamespaceEnabled(namespace)) {
|
|
158
|
+
console.warn(message, ...args);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Logs error message for a specific namespace if enabled. */
|
|
163
|
+
errorForNamespace(namespace: string, message: string, ...args: unknown[]): void {
|
|
164
|
+
if (this.isNamespaceEnabled(namespace)) {
|
|
165
|
+
console.error(message, ...args);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// Entity Models
|
|
2
2
|
import { User } from './user/user.model';
|
|
3
3
|
import { UserContext } from './user-context/user-context.model';
|
|
4
|
+
import { UserPrivate } from './user-private/user-private.model';
|
|
4
5
|
|
|
5
6
|
export type AnyEntity =
|
|
6
7
|
User |
|
|
7
|
-
UserContext
|
|
8
|
+
UserContext |
|
|
9
|
+
UserPrivate;
|
|
8
10
|
|
|
9
11
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
12
|
export type QueryParams = [string, string, any][];
|
|
@@ -4,12 +4,14 @@ import { patchState, signalStoreFeature, withMethods } from '@ngrx/signals';
|
|
|
4
4
|
import { removeEntities, removeEntity, setEntities, setEntity, updateEntity, withEntities, setAllEntities } from '@ngrx/signals/entities';
|
|
5
5
|
import { SelectEntityId } from '@ngrx/signals/entities';
|
|
6
6
|
import { CachedListenersService } from '../firebase/cached-listeners.service';
|
|
7
|
-
import { queryLog } from '../firebase/query-logger';
|
|
8
7
|
import { DATABASE_SERVICE, DatabaseService } from '../firebase/database.service';
|
|
9
8
|
import { AnyEntity, QueryOptions, QueryParams } from './app.model';
|
|
10
9
|
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
|
|
11
10
|
import { WriteBatchI } from './batch-write.service';
|
|
12
11
|
import { environment } from '../../../environments/environment';
|
|
12
|
+
import { LoggingService, getLogger } from '../logging/logging.service';
|
|
13
|
+
|
|
14
|
+
const queryLogger = getLogger('query');
|
|
13
15
|
|
|
14
16
|
const selectId: SelectEntityId<AnyEntity> = (entity) => entity.__id;
|
|
15
17
|
|
|
@@ -174,7 +176,7 @@ export function withEntitiesForMockDB<S extends AnyEntity>(collectionName: strin
|
|
|
174
176
|
export function withEntitiesAndDBMethods<S extends AnyEntity>(collectionName: string) {
|
|
175
177
|
return signalStoreFeature(
|
|
176
178
|
withEntitiesAndSelectMethods<S>(),
|
|
177
|
-
withMethods((store, cachedLoads = inject(CachedListenersService), db = inject(DATABASE_SERVICE), snackBar = inject(MatSnackBar)) => ({
|
|
179
|
+
withMethods((store, cachedLoads = inject(CachedListenersService), db = inject(DATABASE_SERVICE), snackBar = inject(MatSnackBar), logger = inject(LoggingService)) => ({
|
|
178
180
|
init(entities: S[]) {
|
|
179
181
|
patchState(store, setAllEntities<S>(entities, { selectId }));
|
|
180
182
|
},
|
|
@@ -318,7 +320,7 @@ export function withEntitiesAndDBMethods<S extends AnyEntity>(collectionName: st
|
|
|
318
320
|
|
|
319
321
|
if (field === '__id' && valuesToLoad.length === 1) {
|
|
320
322
|
const idToFetch = valuesToLoad[0];
|
|
321
|
-
|
|
323
|
+
queryLogger.log(`[Store] Optimized Load Triggered for collection '${collectionName}', fetching single ID using getDoc.`);
|
|
322
324
|
|
|
323
325
|
const entity = await db.getEntity<S>(collectionName, idToFetch);
|
|
324
326
|
|
|
@@ -343,7 +345,7 @@ export function withEntitiesAndDBMethods<S extends AnyEntity>(collectionName: st
|
|
|
343
345
|
// Map bucket index to the exact minimum time in that bucket and its values
|
|
344
346
|
const groupsByBucket: Map<number, { minTime: number, values: string[] }> = new Map();
|
|
345
347
|
|
|
346
|
-
|
|
348
|
+
queryLogger.log(`[Store] Optimized Load Triggered for collection '${collectionName}', tracking ${valuesToLoad.length} IDs.`);
|
|
347
349
|
|
|
348
350
|
valuesToLoad.forEach((val) => {
|
|
349
351
|
const time = cachedLoads.getEntityLoadTime(collectionName, field, val);
|
|
@@ -362,16 +364,16 @@ export function withEntitiesAndDBMethods<S extends AnyEntity>(collectionName: st
|
|
|
362
364
|
});
|
|
363
365
|
|
|
364
366
|
// 3. For each group, execute DB fetches
|
|
365
|
-
|
|
367
|
+
queryLogger.log(`[Store] Grouped ${valuesToLoad.length} IDs into ${groupsByBucket.size} time bucket(s).`);
|
|
366
368
|
await Promise.all(Array.from(groupsByBucket.entries()).map(async ([bucketIndex, group]) => {
|
|
367
369
|
const lastTime = group.minTime;
|
|
368
370
|
const groupValues = group.values;
|
|
369
|
-
|
|
371
|
+
queryLogger.log(`[Store] Bucket ${bucketIndex === -1 ? '(-1: Never Loaded)' : bucketIndex} (minTime: ${lastTime === -1 ? 'Never' : new Date(lastTime).toISOString()}) fetching ${groupValues.length} IDs.`);
|
|
370
372
|
// Chunk into 30s
|
|
371
373
|
for (let i = 0; i < groupValues.length; i += 30) {
|
|
372
374
|
const chunk = groupValues.slice(i, i + 30);
|
|
373
375
|
const batchedParams: QueryParams = [[field, 'in', chunk]];
|
|
374
|
-
|
|
376
|
+
queryLogger.log(`[Store] -> Fetching chunk of ${chunk.length} IDs...`);
|
|
375
377
|
|
|
376
378
|
// Fetch changed entities
|
|
377
379
|
let queryParamsWithTime: QueryParams;
|
|
@@ -386,7 +388,7 @@ export function withEntitiesAndDBMethods<S extends AnyEntity>(collectionName: st
|
|
|
386
388
|
}
|
|
387
389
|
const entitiesDelta: S[] = await db.getEntities(collectionName, queryParamsWithTime, {});
|
|
388
390
|
if (entitiesDelta.length > 0) {
|
|
389
|
-
|
|
391
|
+
queryLogger.log(`[Store] -> Loaded ${entitiesDelta.length} updated/new entities from chunk.`);
|
|
390
392
|
}
|
|
391
393
|
patchState(store, setEntities<S>(entitiesDelta, { selectId }));
|
|
392
394
|
|
|
@@ -403,7 +405,7 @@ export function withEntitiesAndDBMethods<S extends AnyEntity>(collectionName: st
|
|
|
403
405
|
}
|
|
404
406
|
const entitiesDeletedDelta: S[] = await db.getEntities(collectionName, deletedParamsWithTime, {});
|
|
405
407
|
if (entitiesDeletedDelta.length > 0) {
|
|
406
|
-
|
|
408
|
+
queryLogger.log(`[Store] -> Removed ${entitiesDeletedDelta.length} soft-deleted entities from chunk.`);
|
|
407
409
|
}
|
|
408
410
|
patchState(store, removeEntities(entitiesDeletedDelta.map(selectId) as string[]));
|
|
409
411
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { signalStore, patchState, withState, withMethods, withComputed } from '@ngrx/signals';
|
|
2
2
|
import { computed, inject, Injector } from '@angular/core';
|
|
3
3
|
import { UserMockDB, USER_DB } from '../user/user.mock';
|
|
4
|
+
import { USERPRIVATE_DB } from '../user-private/user-private.mock';
|
|
4
5
|
import { environment } from '../../../../environments/environment';
|
|
5
6
|
import { User } from '../user/user.model';
|
|
6
7
|
|
|
@@ -12,7 +13,7 @@ export const AuthMockDB = signalStore(
|
|
|
12
13
|
withState({
|
|
13
14
|
afUser: (initialUser ? {
|
|
14
15
|
uid: initialUser.uid || initialUser.__id,
|
|
15
|
-
email: initialUser.email,
|
|
16
|
+
email: initialUser.email || USERPRIVATE_DB.find((u) => u.__id === (initialUser.uid || initialUser.__id))?.email || '',
|
|
16
17
|
displayName: initialUser.displayName || initialUser.name,
|
|
17
18
|
photoURL: initialUser.photoURL,
|
|
18
19
|
} : null) as { uid: string; email: string; displayName: string; photoURL: string } | null,
|
|
@@ -33,7 +34,7 @@ export const AuthMockDB = signalStore(
|
|
|
33
34
|
login() {
|
|
34
35
|
const afUser = {
|
|
35
36
|
uid: USER_DB[0].__id,
|
|
36
|
-
email: USER_DB[0].email,
|
|
37
|
+
email: USERPRIVATE_DB.find((u) => u.__id === USER_DB[0].__id)?.email || '',
|
|
37
38
|
displayName: USER_DB[0].name,
|
|
38
39
|
photoURL: USER_DB[0].photoURL || '',
|
|
39
40
|
};
|
|
@@ -56,7 +57,7 @@ export const AuthLoggedInMockDB = signalStore(
|
|
|
56
57
|
withState({
|
|
57
58
|
afUser: {
|
|
58
59
|
uid: USER_DB[0].__id,
|
|
59
|
-
email: USER_DB[0].email,
|
|
60
|
+
email: USERPRIVATE_DB.find((u) => u.__id === USER_DB[0].__id)?.email || '',
|
|
60
61
|
displayName: USER_DB[0].name,
|
|
61
62
|
photoURL: USER_DB[0].photoURL || '',
|
|
62
63
|
} as { uid: string; email: string; displayName: string; photoURL: string } | null,
|
|
@@ -78,7 +79,7 @@ export const AuthLoggedInMockDB = signalStore(
|
|
|
78
79
|
patchState(store, {
|
|
79
80
|
afUser: {
|
|
80
81
|
uid: USER_DB[0].__id,
|
|
81
|
-
email: USER_DB[0].email,
|
|
82
|
+
email: USERPRIVATE_DB.find((u) => u.__id === USER_DB[0].__id)?.email || '',
|
|
82
83
|
displayName: USER_DB[0].name,
|
|
83
84
|
photoURL: USER_DB[0].photoURL || '',
|
|
84
85
|
},
|
|
@@ -79,11 +79,10 @@ export const AuthStore = signalStore(
|
|
|
79
79
|
patchState(store, { afUser });
|
|
80
80
|
const dbUser = userStore.selectEntity(afUser.uid);
|
|
81
81
|
|
|
82
|
-
if (!dbUser) {
|
|
82
|
+
if (!dbUser && !store.isLoadingLogin()) {
|
|
83
83
|
// afUser exists but dbUser doesn't exist yet, we should create it
|
|
84
84
|
const newUser = {
|
|
85
85
|
__id: afUser.uid,
|
|
86
|
-
email: afUser.email,
|
|
87
86
|
name: afUser.displayName || afUser.email,
|
|
88
87
|
photoURL: afUser.photoURL || null,
|
|
89
88
|
isAdmin: false,
|
|
@@ -92,6 +91,10 @@ export const AuthStore = signalStore(
|
|
|
92
91
|
};
|
|
93
92
|
try {
|
|
94
93
|
await db.addEntity('users', newUser);
|
|
94
|
+
await db.addEntity('userPrivates', {
|
|
95
|
+
__id: afUser.uid,
|
|
96
|
+
email: afUser.email,
|
|
97
|
+
});
|
|
95
98
|
} catch (e) {
|
|
96
99
|
console.error(`[AuthStore loadAuth] Error creating new user:`, e);
|
|
97
100
|
}
|
|
@@ -116,12 +119,15 @@ export const AuthStore = signalStore(
|
|
|
116
119
|
// update the user if there is already a dbUser
|
|
117
120
|
if (dbUser) {
|
|
118
121
|
const changes = {
|
|
119
|
-
email: afUser.email,
|
|
120
122
|
name: afUser.displayName || afUser.email,
|
|
121
123
|
photoURL: afUser.photoURL || null,
|
|
122
124
|
};
|
|
123
125
|
try {
|
|
124
126
|
await userStore.update(dbUser.__id, changes);
|
|
127
|
+
await db.addEntity('userPrivates', {
|
|
128
|
+
__id: dbUser.__id,
|
|
129
|
+
email: afUser.email,
|
|
130
|
+
});
|
|
125
131
|
|
|
126
132
|
if (!params || !params.doNotRoute) {
|
|
127
133
|
router.navigate(navLocation, { queryParamsHandling: 'preserve' });
|
|
@@ -133,7 +139,6 @@ export const AuthStore = signalStore(
|
|
|
133
139
|
} else {
|
|
134
140
|
const newUser = {
|
|
135
141
|
__id: afUser.uid,
|
|
136
|
-
email: afUser.email,
|
|
137
142
|
name: afUser.displayName || afUser.email,
|
|
138
143
|
photoURL: afUser.photoURL || null,
|
|
139
144
|
isAdmin: false,
|
|
@@ -142,6 +147,10 @@ export const AuthStore = signalStore(
|
|
|
142
147
|
};
|
|
143
148
|
try {
|
|
144
149
|
await userStore.add(newUser);
|
|
150
|
+
await db.addEntity('userPrivates', {
|
|
151
|
+
__id: afUser.uid,
|
|
152
|
+
email: afUser.email,
|
|
153
|
+
});
|
|
145
154
|
|
|
146
155
|
if (!params || !params.doNotRoute) {
|
|
147
156
|
router.navigate(navLocation, { queryParamsHandling: 'preserve' });
|
|
@@ -11,7 +11,6 @@ export const UserMockDB = signalStore(
|
|
|
11
11
|
export function createMockUser(overrides?: Partial<User>): User {
|
|
12
12
|
return {
|
|
13
13
|
__id: 'mock-user-id',
|
|
14
|
-
email: 'mock@example.com',
|
|
15
14
|
name: 'Mock User',
|
|
16
15
|
isAdmin: false,
|
|
17
16
|
accessState: AccessState.DONE,
|
|
@@ -26,7 +25,6 @@ export function createMockUser(overrides?: Partial<User>): User {
|
|
|
26
25
|
export const MOCK_USER_WAITING: User = {
|
|
27
26
|
__id: 'u1',
|
|
28
27
|
name: 'Alice Waiting',
|
|
29
|
-
email: 'alice@example.com',
|
|
30
28
|
accessState: AccessState.WAITING,
|
|
31
29
|
isAdmin: false,
|
|
32
30
|
consented: false,
|
|
@@ -38,7 +36,6 @@ export const MOCK_USER_WAITING: User = {
|
|
|
38
36
|
export const MOCK_USER_DONE: User = {
|
|
39
37
|
__id: 'u2',
|
|
40
38
|
name: 'Bob Done',
|
|
41
|
-
email: 'bob@example.com',
|
|
42
39
|
accessState: AccessState.DONE,
|
|
43
40
|
isAdmin: false,
|
|
44
41
|
consented: false,
|
|
@@ -55,7 +52,6 @@ export const MOCK_USER_LIST: User[] = [
|
|
|
55
52
|
export const USER_DB: User[] = [
|
|
56
53
|
{
|
|
57
54
|
__id: '1',
|
|
58
|
-
email: 'a@sample.com',
|
|
59
55
|
name: 'User A',
|
|
60
56
|
photoURL: 'http://loremflickr.com/100/100?lock=1',
|
|
61
57
|
isAdmin: true,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Timestamp } from '@angular/fire/firestore';
|
|
2
|
+
import { UserPrivate } from './user-private.model';
|
|
3
|
+
import { withEntitiesForMockDB } from '../app.store';
|
|
4
|
+
import { signalStore } from '@ngrx/signals';
|
|
5
|
+
|
|
6
|
+
export const UserPrivateMockDB = signalStore(
|
|
7
|
+
{ providedIn: 'root' },
|
|
8
|
+
withEntitiesForMockDB<UserPrivate>('userPrivates'),
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export const USERPRIVATE_DB: UserPrivate[] = [
|
|
12
|
+
{ __id: '1', email: 'a@sample.com' },
|
|
13
|
+
{ __id: 'u1', email: 'alice@example.com' },
|
|
14
|
+
{ __id: 'u2', email: 'bob@example.com' },
|
|
15
|
+
];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { inject, effect, WritableSignal } from '@angular/core';
|
|
2
|
+
import { signalStore, withState, withMethods } from '@ngrx/signals';
|
|
3
|
+
import { withEntities, removeEntity, updateEntity, setEntity, removeEntities, setEntities } from '@ngrx/signals/entities';
|
|
4
|
+
import { EntityLoadQuery, EntityStreamQuery, selectEntities, processLoadQueries, withEntitiesAndDBMethods } from '../app.store';
|
|
5
|
+
import { QueryParams, QueryOptions, AnyEntity } from '../app.model';
|
|
6
|
+
import { UserPrivate } from './user-private.model';
|
|
7
|
+
|
|
8
|
+
export class LoadUserPrivate extends EntityLoadQuery<UserPrivate> {
|
|
9
|
+
constructor(
|
|
10
|
+
store,
|
|
11
|
+
queryParams: QueryParams,
|
|
12
|
+
queryOptions: QueryOptions,
|
|
13
|
+
loadQueries?: (entity: UserPrivate) => EntityLoadQuery<AnyEntity>[],
|
|
14
|
+
) {
|
|
15
|
+
super('userPrivates', store, queryParams, queryOptions, loadQueries);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static create(store, queryParams: QueryParams, queryOptions: QueryOptions, loadQueries?: (entity: UserPrivate) => EntityLoadQuery<AnyEntity>[]): LoadUserPrivate {
|
|
19
|
+
return new LoadUserPrivate(store, queryParams, queryOptions, loadQueries);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class StreamUserPrivate extends EntityStreamQuery<UserPrivate> {
|
|
24
|
+
constructor(
|
|
25
|
+
store,
|
|
26
|
+
queryParams: QueryParams,
|
|
27
|
+
queryOptions: QueryOptions,
|
|
28
|
+
streamQueries?: (entity: UserPrivate) => EntityStreamQuery<AnyEntity>[],
|
|
29
|
+
) {
|
|
30
|
+
super('userPrivates', store, queryParams, queryOptions, streamQueries);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static create(store, queryParams: QueryParams, queryOptions: QueryOptions, streamQueries?: (entity: UserPrivate) => EntityStreamQuery<AnyEntity>[]): StreamUserPrivate {
|
|
34
|
+
return new StreamUserPrivate(store, queryParams, queryOptions, streamQueries);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const UserPrivateStore = signalStore(
|
|
39
|
+
{ providedIn: 'root' },
|
|
40
|
+
withEntitiesAndDBMethods<UserPrivate>('userPrivates'),
|
|
41
|
+
);
|
|
@@ -70,7 +70,7 @@ export class EarlyAccessComponent implements OnInit {
|
|
|
70
70
|
try {
|
|
71
71
|
const compareDate = user.joinedWaitlistAt || user._createdAt;
|
|
72
72
|
if (!compareDate) return '';
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
const posNum = await this.userStore.count([
|
|
75
75
|
['joinedWaitlistAt', '<=', compareDate],
|
|
76
76
|
['accessState', '==', AccessState.WAITING],
|
|
@@ -11,9 +11,9 @@ import { RotatingQuotesComponent } from '../rotating-quotes/rotating-quotes.comp
|
|
|
11
11
|
})
|
|
12
12
|
export class HeroComponent {
|
|
13
13
|
readonly sentences = [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
'First generic placeholder quote.',
|
|
15
|
+
'Second generic placeholder quote.',
|
|
16
|
+
'Third generic placeholder quote.',
|
|
17
17
|
];
|
|
18
18
|
isLoading = input<boolean>(false);
|
|
19
19
|
login = output<void>();
|
|
@@ -11,12 +11,12 @@ import { BatchWriteService, BATCH_WRITE_SERVICE } from 'src/app/core/store/batch
|
|
|
11
11
|
})
|
|
12
12
|
export class OnboardingComponent implements OnInit {
|
|
13
13
|
authStore = inject(AuthStore);
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
// --------------- INPUTS AND OUTPUTS ------------------
|
|
16
16
|
|
|
17
17
|
/** The currently signed in user. */
|
|
18
18
|
currentUser: Signal<User> = this.authStore.user;
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
// --------------- LOCAL UI STATE ----------------------
|
|
21
21
|
|
|
22
22
|
// --------------- COMPUTED DATA -----------------------
|
|
@@ -32,7 +32,7 @@ export class OnboardingComponent implements OnInit {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// --------------- LOAD AND CLEANUP --------------------
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
ngOnInit() {
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -7,7 +7,7 @@ import { FirebaseMockService } from 'src/app/core/firebase/firebase.mock.service
|
|
|
7
7
|
import { BatchWriteMockService } from 'src/app/core/store/batch-write.mock.service';
|
|
8
8
|
import { BATCH_WRITE_SERVICE } from 'src/app/core/store/batch-write.service';
|
|
9
9
|
|
|
10
|
-
/** Sets up the testing environment for HomeComponent using render
|
|
10
|
+
/** Sets up the testing environment for HomeComponent using render. */
|
|
11
11
|
async function setup() {
|
|
12
12
|
const user = userEvent.setup();
|
|
13
13
|
const checkedSpy = jest.fn();
|