@almadar/server 1.4.5 → 2.0.1

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 (83) hide show
  1. package/LICENSE +21 -72
  2. package/README.md +25 -0
  3. package/dist/deepagent/__tests__/memory.test.d.ts +6 -0
  4. package/dist/deepagent/__tests__/memory.test.d.ts.map +1 -0
  5. package/dist/deepagent/__tests__/session.test.d.ts +6 -0
  6. package/dist/deepagent/__tests__/session.test.d.ts.map +1 -0
  7. package/dist/deepagent/__tests__/skill-agent.test.d.ts +6 -0
  8. package/dist/deepagent/__tests__/skill-agent.test.d.ts.map +1 -0
  9. package/dist/deepagent/memory.d.ts +4 -7
  10. package/dist/deepagent/memory.d.ts.map +1 -0
  11. package/dist/deepagent/session.d.ts +4 -7
  12. package/dist/deepagent/session.d.ts.map +1 -0
  13. package/dist/deepagent/skill-agent.d.ts +6 -8
  14. package/dist/deepagent/skill-agent.d.ts.map +1 -0
  15. package/dist/index.d.ts +30 -36
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +435 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/lib/db.d.ts +36 -0
  20. package/dist/lib/db.d.ts.map +1 -0
  21. package/dist/lib/debugRouter.d.ts +20 -0
  22. package/dist/lib/debugRouter.d.ts.map +1 -0
  23. package/dist/lib/env.d.ts +16 -0
  24. package/dist/lib/env.d.ts.map +1 -0
  25. package/dist/lib/eventBus.d.ts +46 -0
  26. package/dist/lib/eventBus.d.ts.map +1 -0
  27. package/dist/lib/eventBusTransport.d.ts +143 -0
  28. package/dist/lib/eventBusTransport.d.ts.map +1 -0
  29. package/dist/lib/eventPersistence.d.ts +151 -0
  30. package/dist/lib/eventPersistence.d.ts.map +1 -0
  31. package/dist/lib/index.d.ts +6 -4
  32. package/dist/lib/index.d.ts.map +1 -0
  33. package/dist/lib/logger.d.ts +7 -0
  34. package/dist/lib/logger.d.ts.map +1 -0
  35. package/dist/lib/serviceDiscovery.d.ts +168 -0
  36. package/dist/lib/serviceDiscovery.d.ts.map +1 -0
  37. package/dist/lib/websocket.d.ts +41 -0
  38. package/dist/lib/websocket.d.ts.map +1 -0
  39. package/dist/middleware/__tests__/multi-user.test.d.ts +6 -0
  40. package/dist/middleware/__tests__/multi-user.test.d.ts.map +1 -0
  41. package/dist/middleware/authenticateFirebase.d.ts +4 -0
  42. package/dist/middleware/authenticateFirebase.d.ts.map +1 -0
  43. package/dist/middleware/errorHandler.d.ts +53 -0
  44. package/dist/middleware/errorHandler.d.ts.map +1 -0
  45. package/dist/middleware/index.d.ts +4 -71
  46. package/dist/middleware/index.d.ts.map +1 -0
  47. package/dist/middleware/multi-user.d.ts +4 -7
  48. package/dist/middleware/multi-user.d.ts.map +1 -0
  49. package/dist/middleware/validation.d.ts +15 -0
  50. package/dist/middleware/validation.d.ts.map +1 -0
  51. package/dist/routes/__tests__/observability.test.d.ts +6 -0
  52. package/dist/routes/__tests__/observability.test.d.ts.map +1 -0
  53. package/dist/services/DataService.d.ts +69 -0
  54. package/dist/services/DataService.d.ts.map +1 -0
  55. package/dist/{index-D8fohXsO.d.ts → services/MockDataService.d.ts} +9 -78
  56. package/dist/services/MockDataService.d.ts.map +1 -0
  57. package/dist/services/index.d.ts +8 -2
  58. package/dist/services/index.d.ts.map +1 -0
  59. package/dist/stores/ChangeSetStore.d.ts +24 -0
  60. package/dist/stores/ChangeSetStore.d.ts.map +1 -0
  61. package/dist/stores/SchemaProtectionService.d.ts +23 -0
  62. package/dist/stores/SchemaProtectionService.d.ts.map +1 -0
  63. package/dist/stores/SchemaStore.d.ts +52 -0
  64. package/dist/stores/SchemaStore.d.ts.map +1 -0
  65. package/dist/stores/SnapshotStore.d.ts +26 -0
  66. package/dist/stores/SnapshotStore.d.ts.map +1 -0
  67. package/dist/stores/ValidationStore.d.ts +19 -0
  68. package/dist/stores/ValidationStore.d.ts.map +1 -0
  69. package/dist/stores/firestoreFormat.d.ts +21 -0
  70. package/dist/stores/firestoreFormat.d.ts.map +1 -0
  71. package/dist/stores/index.d.ts +10 -163
  72. package/dist/stores/index.d.ts.map +1 -0
  73. package/dist/utils/index.d.ts +4 -73
  74. package/dist/utils/index.d.ts.map +1 -0
  75. package/dist/utils/queryFilters.d.ts +77 -0
  76. package/dist/utils/queryFilters.d.ts.map +1 -0
  77. package/dist/websocket/__tests__/state-sync.test.d.ts +6 -0
  78. package/dist/websocket/__tests__/state-sync.test.d.ts.map +1 -0
  79. package/dist/websocket/state-sync.d.ts +3 -3
  80. package/dist/websocket/state-sync.d.ts.map +1 -0
  81. package/package.json +9 -13
  82. package/dist/index-B64ll_cY.d.ts +0 -149
  83. package/dist/routes/observability.d.ts +0 -12
@@ -0,0 +1,19 @@
1
+ /**
2
+ * ValidationStore - Firestore CRUD for validation results
3
+ *
4
+ * Validation results stored at: users/{uid}/apps/{appId}/validation/current
5
+ */
6
+ import type { ValidationResults } from '@almadar/core';
7
+ export declare class ValidationStore {
8
+ private appsCollection;
9
+ constructor(appsCollection?: string);
10
+ private getDocPath;
11
+ private getAppDocPath;
12
+ /** Save validation results */
13
+ save(uid: string, appId: string, results: ValidationResults): Promise<void>;
14
+ /** Get validation results */
15
+ get(uid: string, appId: string): Promise<ValidationResults | null>;
16
+ /** Clear validation results */
17
+ clear(uid: string, appId: string): Promise<void>;
18
+ }
19
+ //# sourceMappingURL=ValidationStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidationStore.d.ts","sourceRoot":"","sources":["../../src/stores/ValidationStore.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAkB,MAAM,eAAe,CAAC;AAMvE,qBAAa,eAAe;IAC1B,OAAO,CAAC,cAAc,CAAS;gBAEnB,cAAc,SAAS;IAInC,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,aAAa;IAIrB,8BAA8B;IACxB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBjF,6BAA6B;IACvB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAYxE,+BAA+B;IACzB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAUvD"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Firestore Serialization Utilities
3
+ *
4
+ * Handles the Firestore 20-level depth limit by serializing deeply nested
5
+ * OrbitalSchema fields (orbitals, traits, services) to JSON strings.
6
+ */
7
+ import type { OrbitalSchema } from '@almadar/core';
8
+ /**
9
+ * Convert OrbitalSchema to Firestore-safe format.
10
+ *
11
+ * Serializes orbitals, traits, and services to JSON strings to avoid
12
+ * Firestore's 20-level nesting limit.
13
+ */
14
+ export declare function toFirestoreFormat(schema: OrbitalSchema): Record<string, unknown>;
15
+ /**
16
+ * Convert Firestore document back to OrbitalSchema.
17
+ *
18
+ * Deserializes JSON strings back to arrays.
19
+ */
20
+ export declare function fromFirestoreFormat(data: Record<string, unknown>): OrbitalSchema;
21
+ //# sourceMappingURL=firestoreFormat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firestoreFormat.d.ts","sourceRoot":"","sources":["../../src/stores/firestoreFormat.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA0BhF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,CAsChF"}
@@ -1,167 +1,14 @@
1
- import { OrbitalSchema, SnapshotDocument, SaveOptions, SaveResult, AppSummary, StatsView, ChangeSetDocument, ValidationResults, CategorizedRemovals, PageContentReduction } from '@almadar/core';
2
-
3
1
  /**
4
- * Firestore Serialization Utilities
2
+ * Stores barrel export
5
3
  *
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
4
+ * Firestore-backed stores for OrbitalSchema, snapshots, changesets, and validation.
146
5
  *
147
- * Uses real diff functions from @almadar/core to detect and categorize
148
- * removals, page content reductions, and other destructive changes.
6
+ * @packageDocumentation
149
7
  */
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 };
8
+ export { toFirestoreFormat, fromFirestoreFormat } from './firestoreFormat.js';
9
+ export { SchemaStore } from './SchemaStore.js';
10
+ export { SnapshotStore } from './SnapshotStore.js';
11
+ export { ChangeSetStore } from './ChangeSetStore.js';
12
+ export { ValidationStore } from './ValidationStore.js';
13
+ export { SchemaProtectionService } from './SchemaProtectionService.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stores/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC"}
@@ -1,78 +1,9 @@
1
1
  /**
2
- * Query Filter Utilities
2
+ * Server Utilities
3
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
- * // ]
4
+ * Reusable utility functions for Express routes and handlers.
16
5
  *
17
6
  * @packageDocumentation
18
7
  */
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 };
8
+ export * from './queryFilters.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,77 @@
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
+ export interface ParsedFilter {
23
+ field: string;
24
+ operator: FirestoreWhereFilterOp;
25
+ value: unknown;
26
+ }
27
+ /**
28
+ * Firestore where filter operators
29
+ */
30
+ export 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
+ export 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
+ export declare function applyFiltersToQuery<T>(collection: FirebaseFirestore.Query<T>, filters: ParsedFilter[]): FirebaseFirestore.Query<T>;
67
+ /**
68
+ * Extract pagination parameters from query
69
+ */
70
+ export interface PaginationParams {
71
+ page: number;
72
+ pageSize: number;
73
+ sortBy?: string;
74
+ sortOrder: 'asc' | 'desc';
75
+ }
76
+ export declare function extractPaginationParams(query: Record<string, unknown>, defaults?: Partial<PaginationParams>): PaginationParams;
77
+ //# sourceMappingURL=queryFilters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryFilters.d.ts","sourceRoot":"","sources":["../../src/utils/queryFilters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,sBAAsB,CAAC;IACjC,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAC9B,IAAI,GACJ,IAAI,GACJ,GAAG,GACH,IAAI,GACJ,GAAG,GACH,IAAI,GACJ,gBAAgB,GAChB,oBAAoB,GACpB,IAAI,GACJ,QAAQ,CAAC;AAsCb;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,YAAY,EAAE,CA0ChB;AAoCD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,UAAU,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,EACtC,OAAO,EAAE,YAAY,EAAE,GACtB,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAY5B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,KAAK,GAAG,MAAM,CAAC;CAC3B;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,QAAQ,GAAE,OAAO,CAAC,gBAAgB,CAAM,GACvC,gBAAgB,CAOlB"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @fileoverview Unit tests for state sync WebSocket handler
3
+ * @module @almadar/server/websocket/state-sync.test
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=state-sync.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-sync.test.d.ts","sourceRoot":"","sources":["../../../src/websocket/__tests__/state-sync.test.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -34,6 +34,6 @@ interface SocketServer {
34
34
  /**
35
35
  * Set up state sync WebSocket with Firebase Auth
36
36
  */
37
- declare function setupStateSyncWebSocket(io: SocketServer): void;
38
-
39
- export { setupStateSyncWebSocket };
37
+ export declare function setupStateSyncWebSocket(io: SocketServer): void;
38
+ export {};
39
+ //# sourceMappingURL=state-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-sync.d.ts","sourceRoot":"","sources":["../../src/websocket/state-sync.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,UAAU,MAAM;IACd,IAAI,EAAE;QAAE,IAAI,EAAE;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,EAAE,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IACjE,SAAS,EAAE;QAAE,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IACzD,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,KAAK,IAAI,CAAC;IACnE,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAClD,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK;QAAE,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;KAAE,CAAC;CAC7E;AAED,UAAU,YAAY;IACpB,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,CAAC;IACjF,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,KAAK,IAAI,CAAC;CAChE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAmE9D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/server",
3
- "version": "1.4.5",
3
+ "version": "2.0.1",
4
4
  "description": "Shared server infrastructure for Almadar applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -39,23 +39,18 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
+ "@almadar/agent": ">=2.0.1",
43
+ "@almadar/core": ">=2.0.0",
42
44
  "@faker-js/faker": "^9.3.0",
43
45
  "cors": "^2.8.5",
44
46
  "dotenv": "^16.4.0",
47
+ "firebase-admin": "^12.0.0",
45
48
  "helmet": "^8.0.0",
46
49
  "ws": "^8.18.0",
47
- "zod": "^3.24.0",
48
- "@almadar/agent": "1.6.4",
49
- "@almadar/core": "1.0.18"
50
+ "zod": "^3.24.0"
50
51
  },
51
52
  "peerDependencies": {
52
- "express": "^4.0.0",
53
- "firebase-admin": "^12.0.0"
54
- },
55
- "peerDependenciesMeta": {
56
- "firebase-admin": {
57
- "optional": true
58
- }
53
+ "express": "^4.0.0"
59
54
  },
60
55
  "devDependencies": {
61
56
  "@types/cors": "^2.8.17",
@@ -71,7 +66,7 @@
71
66
  "repository": {
72
67
  "type": "git",
73
68
  "url": "https://github.com/almadar-io/almadar.git",
74
- "directory": "packages/almadar-server"
69
+ "directory": "docs/packages/server"
75
70
  },
76
71
  "license": "MIT",
77
72
  "keywords": [
@@ -80,8 +75,9 @@
80
75
  "express",
81
76
  "middleware"
82
77
  ],
78
+ "homepage": "https://github.com/almadar-io/almadar#readme",
83
79
  "scripts": {
84
- "build": "NODE_OPTIONS='--max-old-space-size=4096' tsup",
80
+ "build": "tsup && tsc --declaration --emitDeclarationOnly --outDir dist --rootDir src --skipLibCheck || true",
85
81
  "build:watch": "tsup --watch",
86
82
  "lint": "eslint src/",
87
83
  "typecheck": "tsc --noEmit",
@@ -1,149 +0,0 @@
1
- import admin from 'firebase-admin';
2
- import { WebSocketServer } from 'ws';
3
- import { Server } from 'http';
4
-
5
- declare const env: {
6
- NODE_ENV: "development" | "production" | "test";
7
- PORT: number;
8
- CORS_ORIGIN: string | string[];
9
- API_PREFIX: string;
10
- USE_MOCK_DATA: boolean;
11
- DATABASE_URL?: string | undefined;
12
- FIREBASE_PROJECT_ID?: string | undefined;
13
- FIREBASE_CLIENT_EMAIL?: string | undefined;
14
- FIREBASE_PRIVATE_KEY?: string | undefined;
15
- FIREBASE_SERVICE_ACCOUNT_PATH?: string | undefined;
16
- FIRESTORE_EMULATOR_HOST?: string | undefined;
17
- FIREBASE_AUTH_EMULATOR_HOST?: string | undefined;
18
- MOCK_SEED?: number | undefined;
19
- };
20
-
21
- declare const logger: {
22
- debug: (message: string, meta?: unknown) => void;
23
- info: (message: string, meta?: unknown) => void;
24
- warn: (message: string, meta?: unknown) => void;
25
- error: (message: string, meta?: unknown) => void;
26
- };
27
-
28
- /**
29
- * Server EventBus - Singleton for server-side cross-trait communication
30
- *
31
- * This EventBus enables:
32
- * - Server-side trait event emission after CRUD operations
33
- * - Server-side trait listeners responding to events
34
- * - Cross-client event broadcast via WebSocket
35
- *
36
- * @packageDocumentation
37
- */
38
- type EventHandler = (payload: unknown, meta?: Record<string, unknown>) => void;
39
- interface EventLogEntry {
40
- event: string;
41
- payload: unknown;
42
- timestamp: number;
43
- listenerCount: number;
44
- wildcardListenerCount: number;
45
- }
46
- /**
47
- * Simple EventBus implementation for server-side events
48
- */
49
- declare class EventBus {
50
- private handlers;
51
- private debug;
52
- private eventLog;
53
- constructor(options?: {
54
- debug?: boolean;
55
- });
56
- on(event: string, handler: EventHandler): () => void;
57
- off(event: string, handler: EventHandler): void;
58
- emit(event: string, payload?: unknown, meta?: Record<string, unknown>): void;
59
- getRecentEvents(limit?: number): EventLogEntry[];
60
- clearEventLog(): void;
61
- getListenerCounts(): Record<string, number>;
62
- clear(): void;
63
- }
64
- /**
65
- * Singleton EventBus instance for server-side event communication.
66
- */
67
- declare const serverEventBus: EventBus;
68
- /**
69
- * Type-safe event emission helper
70
- */
71
- declare function emitEntityEvent(entityType: string, action: 'CREATED' | 'UPDATED' | 'DELETED', payload: Record<string, unknown>): void;
72
-
73
- /**
74
- * Database Accessors & Initialization
75
- *
76
- * This module provides:
77
- * - `initializeFirebase()` — convenience function to init Firebase from env vars
78
- * - `getFirestore()`, `getAuth()` — accessors for Firebase services
79
- * - `db` — lazy Firestore proxy (no eager initialization)
80
- *
81
- * The consuming application MUST call `initializeFirebase()` or
82
- * `admin.initializeApp()` before using any Firebase-dependent features.
83
- */
84
-
85
- /**
86
- * Initialize Firebase Admin SDK from environment variables.
87
- *
88
- * Reads: FIREBASE_PROJECT_ID, FIREBASE_CLIENT_EMAIL, FIREBASE_PRIVATE_KEY,
89
- * FIREBASE_SERVICE_ACCOUNT_PATH, FIRESTORE_EMULATOR_HOST
90
- *
91
- * Safe to call multiple times — returns existing app if already initialized.
92
- */
93
- declare function initializeFirebase(): admin.app.App;
94
- /**
95
- * Get Firestore instance from the pre-initialized Firebase app.
96
- */
97
- declare function getFirestore(): admin.firestore.Firestore;
98
- /**
99
- * Get Firebase Auth instance from the pre-initialized Firebase app.
100
- */
101
- declare function getAuth(): admin.auth.Auth;
102
-
103
- /**
104
- * Lazy Firestore proxy — resolves on first property access, not at import time.
105
- * This prevents the "Firebase not initialized" error during module loading.
106
- */
107
- declare const db: admin.firestore.Firestore;
108
-
109
- /**
110
- * WebSocket Event Broadcast - Cross-client event synchronization
111
- *
112
- * Broadcasts server-side events to all connected clients via WebSocket.
113
- * This enables real-time updates across multiple browser clients.
114
- *
115
- * @packageDocumentation
116
- */
117
-
118
- /**
119
- * Setup WebSocket server for event broadcasting.
120
- *
121
- * Listens to all server events via wildcard and broadcasts to connected clients.
122
- *
123
- * @param server - HTTP server to attach WebSocket to
124
- * @param path - WebSocket endpoint path (default: '/ws/events')
125
- *
126
- * @example
127
- * ```typescript
128
- * import { createServer } from 'http';
129
- * import { setupEventBroadcast } from '@/lib/websocket';
130
- *
131
- * const server = createServer(app);
132
- * setupEventBroadcast(server);
133
- * ```
134
- */
135
- declare function setupEventBroadcast(server: Server, path?: string): WebSocketServer;
136
- /**
137
- * Get the WebSocket server instance (for testing or advanced usage)
138
- */
139
- declare function getWebSocketServer(): WebSocketServer | null;
140
- /**
141
- * Close the WebSocket server
142
- */
143
- declare function closeWebSocketServer(): Promise<void>;
144
- /**
145
- * Get connected client count
146
- */
147
- declare function getConnectedClientCount(): number;
148
-
149
- export { EventBus as E, type EventLogEntry as a, env as b, closeWebSocketServer as c, db as d, emitEntityEvent as e, getConnectedClientCount as f, getAuth as g, getFirestore as h, getWebSocketServer as i, initializeFirebase as j, setupEventBroadcast as k, logger as l, serverEventBus as s };
@@ -1,12 +0,0 @@
1
- import * as express_serve_static_core from 'express-serve-static-core';
2
-
3
- /**
4
- * Observability Routes
5
- *
6
- * Provides endpoints for metrics, health checks, and telemetry.
7
- *
8
- * @packageDocumentation
9
- */
10
- declare const router: express_serve_static_core.Router;
11
-
12
- export { router as default };