@tech4good/platform-data 0.1.0-alpha.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tech4good-platform-data-firestore.d.ts","sources":["../../firestore/timestamp.ts","../../firestore/public-api.ts"],"mappings":";;;;;;AAGA;AACA,iBAAgB,sBAAsB,QAAQ,SAAS,GAAG,aAAa;AAIvE;AACA,iBAAgB,oBAAoB,QAAQ,aAAa,GAAG,SAAS;AAyBrE;AACA,iBAAgB,mBAAmB;AACnC;AACA,iBAAgB,mBAAmB;;AClBnC;AACA,cAAa,kBAAkB,EAAA,cAAA,CAAA,SAAA;AAE/B;;;;AAIG;AACH,iBAAgB,yBAAyB,eAAc,WAAgB,iBAAgB,YAAiB,GAAG,eAAe;AAyD1H;;;;;AAKG;AACH,iBAAgB,sBAAsB,SAAS,MAAM,wCAAwC,aAAa;AAW1G;;;;;;AAMG;AACH,cACa,oBAAqB,YAAW,UAAU;AACrD,sCAAgC,SAAA;AAChC;AACA;AAQA,yDAAqD,UAAU;uDAMb,WAAgB,YAAY,YAAY,GAAG,UAAU;AAMvG,8DAAyD,WAAgB,YAAY,YAAY,GAAG,UAAU;;;AAA6B;AAQrI,sDAAkD,OAAO;oDASV,WAAgB,YAAY,YAAY,GAAG,OAAO;AAIjG,2CAAsC,WAAgB,YAAY,YAAY,GAAG,OAAO;wBAGpE,MAAM,kDAAkD,WAAW,WAAW,YAAY;AACnG;AAA4C,QAAG,OAAO;AAAI;;AAGrE,wBAAoB,aAAa;;kDAAgE,WAAW,GAAA,OAAA;gFAahC,OAAO,aAAa,WAAW,GAAA,OAAA;AAW3G,6DAAyD,WAAW,GAAA,OAAA;4FAaoB,OAAO;yCAxF1F,oBAAoB;6CAApB,oBAAoB;AA2FhC;AAaD;AACA,cACa,0BAA2B,YAAW,iBAAiB;AAClE;AACA;4BACwB,WAAW,YAAY,OAAO,qBAAqB,YAAY,GAAG,OAAO;yCAHtF,0BAA0B;6CAA1B,0BAA0B;AAMtC;;AAED;;;;;AAKG;AACH,iBAAgB,oBAAoB,kBAAkB,SAAS,GAAAA,EAAA,CAAA,oBAAA;;","names":["_angular_core"]}
@@ -0,0 +1,7 @@
1
+ import * as _angular_core from '@angular/core';
2
+
3
+ /** Opt in to the application's Material snackbar service for write feedback and undo. */
4
+ declare function provideMaterialDataFeedback(): _angular_core.EnvironmentProviders;
5
+
6
+ export { provideMaterialDataFeedback };
7
+ //# sourceMappingURL=tech4good-platform-data-material.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tech4good-platform-data-material.d.ts","sources":["../../material/public-api.ts"],"mappings":";;AAIA;AACA,iBAAgB,2BAA2B,IAAA,aAAA,CAAA,oBAAA;;","names":[]}
@@ -0,0 +1,236 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, Injector, Provider, ProviderToken } from '@angular/core';
3
+ import { Observable } from 'rxjs';
4
+ import * as _tech4good_platform_data from '@tech4good/platform-data';
5
+ import { DataEntity, BatchWriteService, BatchConfig, WriteOptions, DataAccess, QueryParams, QueryOptions, NewDataEntity, WriteBatchI, EntityDefinition } from '@tech4good/platform-data';
6
+ import * as _ngrx_signals_entities from '@ngrx/signals/entities';
7
+ import * as _ngrx_signals from '@ngrx/signals';
8
+
9
+ /** Optional browser persistence for mock data, scoped by collection and key prefix. */
10
+ interface MockPersistenceOptions {
11
+ /** Off by default; storage is also skipped when window is unavailable. */
12
+ enabled?: boolean;
13
+ /** Separate fixtures across apps; use a new prefix after an incompatible fixture change. */
14
+ keyPrefix?: string;
15
+ }
16
+ declare const MOCK_PERSISTENCE: InjectionToken<MockPersistenceOptions>;
17
+ /**
18
+ * Build an app-owned mock collection with selectors and optional localStorage
19
+ * persistence. init prefers valid saved records over seeds; replaceAll installs
20
+ * explicit records. Storage events synchronize other tabs, and injector
21
+ * destruction removes the event listener. This is mock backend state, not the
22
+ * frontend store populated by load/stream.
23
+ */
24
+ declare function withEntitiesForMockDB<T extends DataEntity>(collectionName: string): _ngrx_signals.SignalStoreFeature<_ngrx_signals.EmptyFeatureResult, {
25
+ state: {
26
+ entityMap: _ngrx_signals_entities.EntityMap<T>;
27
+ ids: _ngrx_signals_entities.EntityId[];
28
+ };
29
+ props: {
30
+ entities: i0.Signal<T[]>;
31
+ };
32
+ methods: {
33
+ handleStreamChanges: (entitiesToAdd: T[], entitiesToModify: T[], entitiesToRemove: string[]) => void;
34
+ selectEntity: (id: string) => T;
35
+ selectFirst: (queryParams: _tech4good_platform_data.QueryParams, queryOptions: _tech4good_platform_data.QueryOptions) => T;
36
+ selectEntities: (queryParams: _tech4good_platform_data.QueryParams, queryOptions: _tech4good_platform_data.QueryOptions) => T[];
37
+ init: (entities: T[]) => void;
38
+ add: (entity: T) => void;
39
+ update: (id: string, changes: Partial<T>) => void;
40
+ delete: (id: string) => void;
41
+ replaceAll: (entities: T[]) => void;
42
+ };
43
+ }>;
44
+
45
+ /**
46
+ * Storage surface consumed by MockDataService, separate from the frontend store.
47
+ * Implementations expose reactive snapshots and replace records on mutation so
48
+ * query streams can detect changes. All records must include DataEntity metadata.
49
+ */
50
+ interface MockCollection<T extends DataEntity = DataEntity> {
51
+ entityMap(): Record<string, T>;
52
+ /** Initialize defaults; persistence-aware stores may restore saved data instead. */
53
+ init(entities: T[]): void;
54
+ add(entity: T): void;
55
+ update(id: string, changes: Partial<T>): void;
56
+ /** Install exactly these records, without restoring older persisted data. */
57
+ replaceAll(entities: T[]): void;
58
+ }
59
+ type MockCollections = Record<string, MockCollection<any>>;
60
+ declare const MOCK_COLLECTIONS: InjectionToken<MockCollections>;
61
+ /**
62
+ * Small signal-backed collection with no persistence or injection requirement.
63
+ * Used for generated entities without a custom mock store and for direct seeds
64
+ * passed to provideMockData. Use withEntitiesForMockDB for opt-in persistence.
65
+ */
66
+ declare function createMockCollection<T extends DataEntity>(entities?: T[]): MockCollection<T>;
67
+ type MockOperation = {
68
+ kind: 'set' | 'update' | 'delete';
69
+ path: string;
70
+ value?: any;
71
+ };
72
+ /**
73
+ * In-memory DataAccess adapter for local development and tests. Reactive
74
+ * collections drive streams; configurable delays, errors and stalled reads
75
+ * exercise loading/failure UI. This does not enforce Firestore security rules.
76
+ */
77
+ declare class MockDataService implements DataAccess {
78
+ protected injector: Injector;
79
+ readonly DB: MockCollections;
80
+ GET_LATENCY_SIMULATION_DELAY: number;
81
+ PUT_LATENCY_SIMULATION_DELAY: number;
82
+ /**
83
+ * Collections that throw/reject on reads. Configure through provideMockData({
84
+ * failCollections: [...] }) or mutate db.failCollections during a test to
85
+ * exercise error → recovery: make a read fail, verify the error banner, clear
86
+ * failCollections, click Retry, then verify the successful state.
87
+ */
88
+ failCollections: string[];
89
+ /**
90
+ * Collections whose reads never emit/resolve, simulating perpetual loading.
91
+ * Configure through provideMockData({ stallCollections: [...] }) or mutate
92
+ * db.stallCollections before the next read/subscription to exercise loading UI.
93
+ */
94
+ stallCollections: string[];
95
+ failWriteCollections: string[];
96
+ constructor(injector: Injector);
97
+ createId(): string;
98
+ private collection;
99
+ private read;
100
+ /** Give each subscriber its own effect and release it when that subscription ends. */
101
+ private observe;
102
+ streamEntity<T>(name: string, id: string): Observable<T | null>;
103
+ streamEntities<T>(name: string, params?: QueryParams, options?: QueryOptions): Observable<T[]>;
104
+ streamEntitiesChanges<T>(name: string, params?: QueryParams, options?: QueryOptions): Observable<{
105
+ type: string;
106
+ docData: T;
107
+ }[]>;
108
+ getEntity<T>(name: string, id: string): Promise<T | null>;
109
+ getEntities<T>(name: string, params?: QueryParams, options?: QueryOptions): Promise<T[]>;
110
+ count(name: string, params?: QueryParams, options?: QueryOptions): Promise<number>;
111
+ aggregate<S extends Record<string, number>>(name: string, params: QueryParams, options: QueryOptions, spec: {
112
+ [K in keyof S]: [string] | [string, string];
113
+ }): Promise<{
114
+ [K in keyof S]: number | null;
115
+ }>;
116
+ addEntity<T extends NewDataEntity & {
117
+ __id: string;
118
+ }>(collectionName: string, entity: T, batch?: WriteBatchI): Promise<any>;
119
+ updateEntity<T extends object>(collectionName: string, id: string, changes: Partial<T>, batch?: WriteBatchI): Promise<any>;
120
+ removeEntity(collectionName: string, id: string, batch?: WriteBatchI): Promise<any>;
121
+ incrementEntityField(name: string, id: string, field: string, delta: number): Promise<void>;
122
+ /** Stage all operations, validate, then install synchronously. No partial batch on failure. */
123
+ commitOperations(operations: MockOperation[]): Promise<void>;
124
+ static ɵfac: i0.ɵɵFactoryDeclaration<MockDataService, never>;
125
+ static ɵprov: i0.ɵɵInjectableDeclaration<MockDataService>;
126
+ }
127
+ /** One-use batch that defers mutations until commitOperations validates the whole batch. */
128
+ declare class WriteBatchMock implements WriteBatchI {
129
+ private readonly db;
130
+ private operations;
131
+ private committed;
132
+ constructor(db: MockDataService);
133
+ private append;
134
+ set(ref: {
135
+ path: string;
136
+ }, value: any): this;
137
+ update(ref: {
138
+ path: string;
139
+ }, value: any): this;
140
+ delete(ref: {
141
+ path: string;
142
+ }): this;
143
+ commit(): Promise<void>;
144
+ }
145
+ /** Pair forward and inverse mock batches with the same feedback/rollback flow as Firestore. */
146
+ declare class MockBatchWriteService implements BatchWriteService {
147
+ private readonly feedback;
148
+ private readonly db;
149
+ batchWrite(fn: (config: BatchConfig) => void | Promise<unknown>, options?: WriteOptions): Promise<void>;
150
+ static ɵfac: i0.ɵɵFactoryDeclaration<MockBatchWriteService, never>;
151
+ static ɵprov: i0.ɵɵInjectableDeclaration<MockBatchWriteService>;
152
+ }
153
+
154
+ /** Per-provider fixture configuration and controls for simulated failures/delays. */
155
+ interface MockDataOptions<TCollections extends Record<string, DataEntity[]> = Record<string, DataEntity[]>> {
156
+ /** Raw seeds, or a factory that injects/initializes app-owned mock stores. */
157
+ collections?: TCollections | (() => MockCollections);
158
+ /**
159
+ * Set GET/PUT latency simulation delays to 0ms in tests instead of using an
160
+ * APP_INITIALIZER just to assign those properties. Stream delivery still
161
+ * follows Angular/RxJS scheduling; disabling latency does not make it synchronous.
162
+ */
163
+ disableLatency?: boolean;
164
+ /** Reads and subscriptions fail for these collections. */
165
+ failCollections?: string[];
166
+ /** Reads stay pending and subscriptions emit nothing for these collections. */
167
+ stallCollections?: string[];
168
+ /** Reject writes, including entire batches that touch these collections. */
169
+ failWriteCollections?: string[];
170
+ /** Used by withEntitiesForMockDB stores; raw in-memory seed collections do not persist. */
171
+ persistence?: MockPersistenceOptions;
172
+ }
173
+ /**
174
+ * Install the mock data adapter and matching batch service in an Angular injector.
175
+ * This is sufficient for data-only consumers; generated apps layer their local
176
+ * authentication/profile facade over the same mock infrastructure.
177
+ *
178
+ * @example
179
+ * providers: [provideMockData({ collections: { problems: [] }, disableLatency: true })]
180
+ */
181
+ declare function provideMockData<TCollections extends Record<string, DataEntity[]> = Record<string, DataEntity[]>>(options?: MockDataOptions<TCollections>): Provider[];
182
+
183
+ /** Mock-only wiring for one entity. Import this from development/test providers. */
184
+ interface EntityMock<T extends DataEntity, S extends MockCollection<T>> {
185
+ readonly entity: EntityDefinition<T>;
186
+ /** Inject the same store instance that app tests may inject directly. */
187
+ readonly store: ProviderToken<S>;
188
+ /** Defaults for initialization; a factory runs when the registry is created. */
189
+ readonly seeds: readonly T[] | (() => readonly T[]);
190
+ }
191
+ /**
192
+ * Declare mock wiring as an exported const in *.mock.ts. Import the definition
193
+ * directly from its relative *.model file so the generator can associate them.
194
+ * Providing a store retains its custom selectors/methods in the registry type.
195
+ * No store is instantiated and no seeds are installed at declaration time.
196
+ *
197
+ * @example
198
+ * export const problemMock = defineEntityMock(problemEntity, {
199
+ * store: ProblemMockDB, seeds: PROBLEM_DB,
200
+ * });
201
+ */
202
+ declare function defineEntityMock<T extends DataEntity, S extends MockCollection<NoInfer<T>>>(entity: EntityDefinition<T>, options: {
203
+ store: ProviderToken<S>;
204
+ seeds: readonly NoInfer<T>[] | (() => readonly NoInfer<T>[]);
205
+ }): EntityMock<T, S>;
206
+ /** Without a custom store, create an in-memory collection scoped to its Angular injector. */
207
+ declare function defineEntityMock<T extends DataEntity>(entity: EntityDefinition<T>, options: {
208
+ seeds: readonly NoInfer<T>[] | (() => readonly NoInfer<T>[]);
209
+ }): EntityMock<T, MockCollection<T>>;
210
+ type Definitions = Record<string, EntityMock<any, any>>;
211
+ /** Collection-name map retaining each definition's concrete injected store type. */
212
+ type MockRegistry<D extends Definitions> = {
213
+ [K in keyof D]: D[K] extends EntityMock<any, infer S> ? S : never;
214
+ };
215
+ /** Optional collection replacements; both collection names and seed records are type-checked. */
216
+ type MockSeedOverrides<D extends Definitions> = {
217
+ [K in keyof D]?: D[K] extends EntityMock<infer T, any> ? readonly T[] : never;
218
+ };
219
+ /**
220
+ * Inject and initialize every generated mock definition in the current injection
221
+ * context (for example, a service field initializer). Call once per mock facade.
222
+ * Custom stores may restore persisted data during init; seeds are their fallback.
223
+ * Unrelated injectors do not share a global mutable registry.
224
+ */
225
+ declare function createMockRegistry<D extends Definitions>(definitions: D): MockRegistry<D>;
226
+ /**
227
+ * Replace only the named collections after registry initialization. Unlike init,
228
+ * replaceAll bypasses persistence restoration, so explicit test seeds win even
229
+ * when they are an empty array. Omitted collections retain their initial data.
230
+ * Persistence-enabled custom stores may save these replacements to storage.
231
+ */
232
+ declare function seedMockRegistry<D extends Definitions>(registry: MockRegistry<D>, overrides: MockSeedOverrides<D>): void;
233
+
234
+ export { MockBatchWriteService as BatchWriteMockService, MOCK_COLLECTIONS, MOCK_PERSISTENCE, MockBatchWriteService, MockDataService, WriteBatchMock, createMockCollection, createMockRegistry, defineEntityMock, provideMockData, seedMockRegistry, withEntitiesForMockDB };
235
+ export type { EntityMock, MockCollection, MockCollections, MockDataOptions, MockPersistenceOptions, MockRegistry, MockSeedOverrides };
236
+ //# sourceMappingURL=tech4good-platform-data-testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tech4good-platform-data-testing.d.ts","sources":["../../testing/mock-entities.ts","../../testing/mock-data.ts","../../testing/entity-mocks.ts"],"mappings":";;;;;;;;AAMA;UACiB,sBAAsB;;;;;AAKtC;AACD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