@almadar/server 1.4.5 → 2.0.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.
@@ -1,167 +0,0 @@
1
- import { OrbitalSchema, SnapshotDocument, SaveOptions, SaveResult, AppSummary, StatsView, ChangeSetDocument, ValidationResults, CategorizedRemovals, PageContentReduction } from '@almadar/core';
2
-
3
- /**
4
- * Firestore Serialization Utilities
5
- *
6
- * Handles the Firestore 20-level depth limit by serializing deeply nested
7
- * OrbitalSchema fields (orbitals, traits, services) to JSON strings.
8
- */
9
-
10
- /**
11
- * Convert OrbitalSchema to Firestore-safe format.
12
- *
13
- * Serializes orbitals, traits, and services to JSON strings to avoid
14
- * Firestore's 20-level nesting limit.
15
- */
16
- declare function toFirestoreFormat(schema: OrbitalSchema): Record<string, unknown>;
17
- /**
18
- * Convert Firestore document back to OrbitalSchema.
19
- *
20
- * Deserializes JSON strings back to arrays.
21
- */
22
- declare function fromFirestoreFormat(data: Record<string, unknown>): OrbitalSchema;
23
-
24
- /**
25
- * SnapshotStore - Firestore CRUD for schema snapshots
26
- *
27
- * Snapshots are full copies of the schema at a point in time,
28
- * stored in subcollection: users/{uid}/apps/{appId}/snapshots/{snapshotId}
29
- */
30
-
31
- declare class SnapshotStore {
32
- private appsCollection;
33
- constructor(appsCollection?: string);
34
- private getCollectionPath;
35
- private getAppDocPath;
36
- /** Create a snapshot of the current schema */
37
- create(uid: string, appId: string, schema: OrbitalSchema, reason: string): Promise<string>;
38
- /** Get all snapshots for an app (ordered by timestamp desc) */
39
- getAll(uid: string, appId: string): Promise<SnapshotDocument[]>;
40
- /** Get a specific snapshot by ID */
41
- get(uid: string, appId: string, snapshotId: string): Promise<SnapshotDocument | null>;
42
- /** Delete a snapshot */
43
- delete(uid: string, appId: string, snapshotId: string): Promise<boolean>;
44
- /** Get schema snapshot at a specific version */
45
- getByVersion(uid: string, appId: string, version: number): Promise<OrbitalSchema | null>;
46
- /** Get the schema from a snapshot (deserialized) */
47
- getSchemaFromSnapshot(snapshot: SnapshotDocument): OrbitalSchema;
48
- }
49
-
50
- /**
51
- * SchemaStore - Firestore CRUD for OrbitalSchema documents
52
- *
53
- * Handles schema get/save/create/delete/list with caching
54
- * and Firestore serialization.
55
- */
56
-
57
- declare class SchemaStore {
58
- private appsCollection;
59
- private schemaCache;
60
- private listCache;
61
- private protectionService;
62
- private snapshotStore;
63
- constructor(appsCollection?: string);
64
- /** Set snapshot store for auto-snapshot on destructive saves */
65
- setSnapshotStore(store: SnapshotStore): void;
66
- /** Get a schema by app ID */
67
- get(uid: string, appId: string): Promise<OrbitalSchema | null>;
68
- /**
69
- * Save a schema (create or full replace).
70
- *
71
- * Features:
72
- * - Detects destructive changes (removals)
73
- * - Requires confirmation for critical removals
74
- * - Auto-creates snapshots before destructive changes (if SnapshotStore attached)
75
- */
76
- save(uid: string, appId: string, schema: OrbitalSchema, options?: SaveOptions): Promise<SaveResult>;
77
- /** Create a new app with initial schema */
78
- create(uid: string, metadata: {
79
- name: string;
80
- description?: string;
81
- }): Promise<{
82
- appId: string;
83
- schema: OrbitalSchema;
84
- }>;
85
- /** Delete an app */
86
- delete(uid: string, appId: string): Promise<boolean>;
87
- /** List all apps for a user */
88
- list(uid: string): Promise<AppSummary[]>;
89
- /** Compute stats from OrbitalSchema */
90
- computeStats(schema: OrbitalSchema): StatsView;
91
- /** Invalidate caches for a specific app */
92
- invalidateCache(uid: string, appId: string): void;
93
- /** Clear all caches */
94
- clearCaches(): void;
95
- /** Get the collection path for an app */
96
- getAppDocPath(uid: string, appId: string): string;
97
- /** Expose apps collection name for subcollection stores */
98
- getAppsCollection(): string;
99
- }
100
-
101
- /**
102
- * ChangeSetStore - Firestore CRUD for schema changesets
103
- *
104
- * Changesets track changes made to the schema over time,
105
- * stored in subcollection: users/{uid}/apps/{appId}/changesets/{changeSetId}
106
- */
107
-
108
- declare class ChangeSetStore {
109
- private appsCollection;
110
- constructor(appsCollection?: string);
111
- private getCollectionPath;
112
- private getAppDocPath;
113
- /** Append a changeset to history */
114
- append(uid: string, appId: string, changeSet: ChangeSetDocument): Promise<void>;
115
- /** Get change history for an app (ordered by version desc) */
116
- getHistory(uid: string, appId: string): Promise<ChangeSetDocument[]>;
117
- /** Get a specific changeset by ID */
118
- get(uid: string, appId: string, changeSetId: string): Promise<ChangeSetDocument | null>;
119
- /** Update a changeset's status */
120
- updateStatus(uid: string, appId: string, changeSetId: string, status: 'applied' | 'reverted' | 'pending'): Promise<void>;
121
- /** Delete a changeset */
122
- delete(uid: string, appId: string, changeSetId: string): Promise<boolean>;
123
- }
124
-
125
- /**
126
- * ValidationStore - Firestore CRUD for validation results
127
- *
128
- * Validation results stored at: users/{uid}/apps/{appId}/validation/current
129
- */
130
-
131
- declare class ValidationStore {
132
- private appsCollection;
133
- constructor(appsCollection?: string);
134
- private getDocPath;
135
- private getAppDocPath;
136
- /** Save validation results */
137
- save(uid: string, appId: string, results: ValidationResults): Promise<void>;
138
- /** Get validation results */
139
- get(uid: string, appId: string): Promise<ValidationResults | null>;
140
- /** Clear validation results */
141
- clear(uid: string, appId: string): Promise<void>;
142
- }
143
-
144
- /**
145
- * SchemaProtectionService - Detects destructive schema changes
146
- *
147
- * Uses real diff functions from @almadar/core to detect and categorize
148
- * removals, page content reductions, and other destructive changes.
149
- */
150
-
151
- declare class SchemaProtectionService {
152
- /**
153
- * Compare two schemas and detect destructive changes.
154
- *
155
- * Returns categorized removals including page content reductions.
156
- */
157
- compareSchemas(before: OrbitalSchema, after: OrbitalSchema): {
158
- isDestructive: boolean;
159
- removals: CategorizedRemovals;
160
- };
161
- /** Check if critical removals require confirmation */
162
- requiresConfirmation(removals: CategorizedRemovals): boolean;
163
- /** Check for significant page content reductions */
164
- hasSignificantContentReduction(reductions: PageContentReduction[]): boolean;
165
- }
166
-
167
- export { ChangeSetStore, SchemaProtectionService, SchemaStore, SnapshotStore, ValidationStore, fromFirestoreFormat, toFirestoreFormat };
@@ -1,78 +0,0 @@
1
- /**
2
- * Query Filter Utilities
3
- *
4
- * Parses URL query parameters into Firestore-compatible filter objects.
5
- * Supports operator encoding in parameter names: field__operator=value
6
- *
7
- * @example
8
- * // URL: /api/tasks?status=active&date__gte=2025-01-01&tags__contains=urgent
9
- * const filters = parseQueryFilters(req.query);
10
- * // Returns:
11
- * // [
12
- * // { field: 'status', operator: '==', value: 'active' },
13
- * // { field: 'date', operator: '>=', value: '2025-01-01' },
14
- * // { field: 'tags', operator: 'array-contains', value: 'urgent' }
15
- * // ]
16
- *
17
- * @packageDocumentation
18
- */
19
- /**
20
- * Parsed filter ready for Firestore query
21
- */
22
- interface ParsedFilter {
23
- field: string;
24
- operator: FirestoreWhereFilterOp;
25
- value: unknown;
26
- }
27
- /**
28
- * Firestore where filter operators
29
- */
30
- type FirestoreWhereFilterOp = '==' | '!=' | '>' | '>=' | '<' | '<=' | 'array-contains' | 'array-contains-any' | 'in' | 'not-in';
31
- /**
32
- * Parse query parameters into Firestore-compatible filters.
33
- *
34
- * Supports operator encoding: field__operator=value
35
- *
36
- * @param query - Express req.query object
37
- * @returns Array of parsed filters ready for Firestore .where() calls
38
- *
39
- * @example
40
- * ```typescript
41
- * // In Express route handler:
42
- * const filters = parseQueryFilters(req.query);
43
- *
44
- * let query = db.collection('tasks');
45
- * for (const filter of filters) {
46
- * query = query.where(filter.field, filter.operator, filter.value);
47
- * }
48
- * ```
49
- */
50
- declare function parseQueryFilters(query: Record<string, unknown>): ParsedFilter[];
51
- /**
52
- * Build a Firestore query with filters applied.
53
- *
54
- * @param collection - Base Firestore collection reference or query
55
- * @param filters - Parsed filters from parseQueryFilters
56
- * @returns Query with all filters applied
57
- *
58
- * @example
59
- * ```typescript
60
- * const filters = parseQueryFilters(req.query);
61
- * const baseQuery = db.collection('tasks');
62
- * const filteredQuery = applyFiltersToQuery(baseQuery, filters);
63
- * const snapshot = await filteredQuery.get();
64
- * ```
65
- */
66
- declare function applyFiltersToQuery<T>(collection: FirebaseFirestore.Query<T>, filters: ParsedFilter[]): FirebaseFirestore.Query<T>;
67
- /**
68
- * Extract pagination parameters from query
69
- */
70
- interface PaginationParams {
71
- page: number;
72
- pageSize: number;
73
- sortBy?: string;
74
- sortOrder: 'asc' | 'desc';
75
- }
76
- declare function extractPaginationParams(query: Record<string, unknown>, defaults?: Partial<PaginationParams>): PaginationParams;
77
-
78
- export { type FirestoreWhereFilterOp, type PaginationParams, type ParsedFilter, applyFiltersToQuery, extractPaginationParams, parseQueryFilters };
@@ -1,39 +0,0 @@
1
- /**
2
- * State Sync WebSocket Handler
3
- *
4
- * Provides real-time state synchronization using Socket.IO.
5
- *
6
- * @packageDocumentation
7
- */
8
- interface Socket {
9
- data: {
10
- user: {
11
- uid: string;
12
- roles: string[];
13
- orgId?: string;
14
- };
15
- };
16
- handshake: {
17
- auth: {
18
- token: string;
19
- clientId: string;
20
- };
21
- };
22
- join: (room: string) => void;
23
- leave: (room: string) => void;
24
- on: (event: string, handler: (...args: unknown[]) => void) => void;
25
- emit: (event: string, ...args: unknown[]) => void;
26
- to: (room: string) => {
27
- emit: (event: string, ...args: unknown[]) => void;
28
- };
29
- }
30
- interface SocketServer {
31
- use: (middleware: (socket: Socket, next: (err?: Error) => void) => void) => void;
32
- on: (event: string, handler: (socket: Socket) => void) => void;
33
- }
34
- /**
35
- * Set up state sync WebSocket with Firebase Auth
36
- */
37
- declare function setupStateSyncWebSocket(io: SocketServer): void;
38
-
39
- export { setupStateSyncWebSocket };