@almadar/server 1.0.13 → 1.0.14

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/dist/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  export { E as EventBus, c as closeWebSocketServer, d as db, e as emitEntityEvent, a as env, g as getAuth, b as getConnectedClientCount, f as getFirestore, h as getWebSocketServer, l as logger, s as serverEventBus, i as setupEventBroadcast } from './index--XhXIuTh.js';
2
2
  export { AppError, ConflictError, ForbiddenError, NotFoundError, UnauthorizedError, ValidationError, asyncHandler, authenticateFirebase, errorHandler, notFoundHandler, validateBody, validateParams, validateQuery } from './middleware/index.js';
3
3
  export { D as DataService, E as EntitySchema, a as EntitySeedConfig, F as FieldSchema, M as MockDataService, P as PaginatedResult, b as PaginationOptions, d as dataService, m as mockDataService, s as seedMockData } from './index-D8fohXsO.js';
4
+ export { ChangeSetStore, SchemaProtectionService, SchemaStore, SnapshotStore, ValidationStore, fromFirestoreFormat, toFirestoreFormat } from './stores/index.js';
4
5
  export { FirestoreWhereFilterOp, PaginationParams, ParsedFilter, applyFiltersToQuery, extractPaginationParams, parseQueryFilters } from './utils/index.js';
5
6
  export { default as admin } from 'firebase-admin';
6
7
  import 'ws';
7
8
  import 'http';
8
9
  import 'express';
9
10
  import 'zod';
11
+ import '@almadar/core';
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import admin from 'firebase-admin';
4
4
  export { default as admin } from 'firebase-admin';
5
5
  import { WebSocketServer, WebSocket } from 'ws';
6
6
  import { faker } from '@faker-js/faker';
7
+ import { diffSchemas, categorizeRemovals, detectPageContentReduction, isDestructiveChange, hasSignificantPageReduction, requiresConfirmation } from '@almadar/core';
7
8
 
8
9
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
10
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
@@ -1010,6 +1011,501 @@ function seedMockData(entities) {
1010
1011
  logger.info("[DataService] Mock data seeding complete");
1011
1012
  }
1012
1013
 
1013
- export { AppError, ConflictError, EventBus, ForbiddenError, MockDataService, NotFoundError, UnauthorizedError, ValidationError, applyFiltersToQuery, asyncHandler, authenticateFirebase, closeWebSocketServer, dataService, db, emitEntityEvent, env, errorHandler, extractPaginationParams, getAuth, getConnectedClientCount, getFirestore, getWebSocketServer, logger, mockDataService, notFoundHandler, parseQueryFilters, seedMockData, serverEventBus, setupEventBroadcast, validateBody, validateParams, validateQuery };
1014
+ // src/stores/firestoreFormat.ts
1015
+ function toFirestoreFormat(schema) {
1016
+ const data = { ...schema };
1017
+ if (schema.orbitals) {
1018
+ data._orbitalsJson = JSON.stringify(schema.orbitals);
1019
+ data.orbitalCount = schema.orbitals.length;
1020
+ delete data.orbitals;
1021
+ }
1022
+ if (data.traits) {
1023
+ const traits = data.traits;
1024
+ data._traitsJson = JSON.stringify(traits);
1025
+ data.traitCount = traits.length;
1026
+ delete data.traits;
1027
+ }
1028
+ if (schema.services) {
1029
+ data._servicesJson = JSON.stringify(schema.services);
1030
+ data.serviceCount = schema.services.length;
1031
+ delete data.services;
1032
+ }
1033
+ return data;
1034
+ }
1035
+ function fromFirestoreFormat(data) {
1036
+ const result = { ...data };
1037
+ if (result._orbitalsJson && typeof result._orbitalsJson === "string") {
1038
+ try {
1039
+ result.orbitals = JSON.parse(result._orbitalsJson);
1040
+ delete result._orbitalsJson;
1041
+ delete result.orbitalCount;
1042
+ } catch (e) {
1043
+ console.warn("[OrbitalStore] Failed to parse _orbitalsJson:", e);
1044
+ result.orbitals = [];
1045
+ }
1046
+ }
1047
+ if (result._traitsJson && typeof result._traitsJson === "string") {
1048
+ try {
1049
+ result.traits = JSON.parse(result._traitsJson);
1050
+ delete result._traitsJson;
1051
+ delete result.traitCount;
1052
+ } catch (e) {
1053
+ console.warn("[OrbitalStore] Failed to parse _traitsJson:", e);
1054
+ }
1055
+ }
1056
+ if (result._servicesJson && typeof result._servicesJson === "string") {
1057
+ try {
1058
+ result.services = JSON.parse(result._servicesJson);
1059
+ delete result._servicesJson;
1060
+ delete result.serviceCount;
1061
+ } catch (e) {
1062
+ console.warn("[OrbitalStore] Failed to parse _servicesJson:", e);
1063
+ }
1064
+ }
1065
+ return result;
1066
+ }
1067
+ var SchemaProtectionService = class {
1068
+ /**
1069
+ * Compare two schemas and detect destructive changes.
1070
+ *
1071
+ * Returns categorized removals including page content reductions.
1072
+ */
1073
+ compareSchemas(before, after) {
1074
+ const changeSet = diffSchemas(before, after);
1075
+ const removals = categorizeRemovals(changeSet);
1076
+ const beforePages = before.orbitals?.flatMap((o) => o.pages || []) || [];
1077
+ const afterPages = after.orbitals?.flatMap((o) => o.pages || []) || [];
1078
+ const pageContentReductions = detectPageContentReduction(beforePages, afterPages);
1079
+ removals.pageContentReductions = pageContentReductions;
1080
+ const isDestructive = isDestructiveChange(changeSet) || hasSignificantPageReduction(pageContentReductions);
1081
+ return { isDestructive, removals };
1082
+ }
1083
+ /** Check if critical removals require confirmation */
1084
+ requiresConfirmation(removals) {
1085
+ return requiresConfirmation(removals);
1086
+ }
1087
+ /** Check for significant page content reductions */
1088
+ hasSignificantContentReduction(reductions) {
1089
+ return hasSignificantPageReduction(reductions);
1090
+ }
1091
+ };
1092
+
1093
+ // src/stores/SchemaStore.ts
1094
+ var SCHEMA_CACHE_TTL_MS = 6e4;
1095
+ var LIST_CACHE_TTL_MS = 3e4;
1096
+ var SchemaStore = class {
1097
+ appsCollection;
1098
+ schemaCache = /* @__PURE__ */ new Map();
1099
+ listCache = /* @__PURE__ */ new Map();
1100
+ protectionService = new SchemaProtectionService();
1101
+ snapshotStore = null;
1102
+ constructor(appsCollection = "apps") {
1103
+ this.appsCollection = appsCollection;
1104
+ }
1105
+ /** Set snapshot store for auto-snapshot on destructive saves */
1106
+ setSnapshotStore(store) {
1107
+ this.snapshotStore = store;
1108
+ }
1109
+ /** Get a schema by app ID */
1110
+ async get(uid, appId) {
1111
+ const cacheKey = `${uid}:${appId}`;
1112
+ const cached = this.schemaCache.get(cacheKey);
1113
+ if (cached && Date.now() - cached.timestamp < SCHEMA_CACHE_TTL_MS) {
1114
+ return cached.schema;
1115
+ }
1116
+ try {
1117
+ const db2 = getFirestore();
1118
+ const appDoc = await db2.doc(`users/${uid}/${this.appsCollection}/${appId}`).get();
1119
+ if (!appDoc.exists) return null;
1120
+ const data = appDoc.data();
1121
+ const hasOrbitals = data.orbitals || data._orbitalsJson;
1122
+ if (!data.name || !hasOrbitals) return null;
1123
+ const schema = fromFirestoreFormat(data);
1124
+ this.schemaCache.set(cacheKey, { schema, timestamp: Date.now() });
1125
+ return schema;
1126
+ } catch (error) {
1127
+ console.error("[SchemaStore] Error fetching schema:", error);
1128
+ return null;
1129
+ }
1130
+ }
1131
+ /**
1132
+ * Save a schema (create or full replace).
1133
+ *
1134
+ * Features:
1135
+ * - Detects destructive changes (removals)
1136
+ * - Requires confirmation for critical removals
1137
+ * - Auto-creates snapshots before destructive changes (if SnapshotStore attached)
1138
+ */
1139
+ async save(uid, appId, schema, options = {}) {
1140
+ try {
1141
+ const existingSchema = await this.get(uid, appId);
1142
+ let snapshotId;
1143
+ if (existingSchema && options.snapshotReason && this.snapshotStore) {
1144
+ snapshotId = await this.snapshotStore.create(uid, appId, existingSchema, options.snapshotReason);
1145
+ }
1146
+ if (existingSchema && !options.skipProtection) {
1147
+ const comparison = this.protectionService.compareSchemas(existingSchema, schema);
1148
+ if (comparison.isDestructive) {
1149
+ const { removals } = comparison;
1150
+ const hasCriticalRemovals = this.protectionService.requiresConfirmation(removals);
1151
+ const hasContentReductions = this.protectionService.hasSignificantContentReduction(
1152
+ removals.pageContentReductions
1153
+ );
1154
+ if ((hasCriticalRemovals || hasContentReductions) && !options.confirmRemovals) {
1155
+ return {
1156
+ success: false,
1157
+ requiresConfirmation: true,
1158
+ removals: comparison.removals,
1159
+ error: hasContentReductions ? "Page content reduction detected - confirmation required" : "Confirmation required for critical removals"
1160
+ };
1161
+ }
1162
+ if (!snapshotId && this.snapshotStore && (removals.critical.length > 0 || removals.pageContentReductions.length > 0)) {
1163
+ snapshotId = await this.snapshotStore.create(
1164
+ uid,
1165
+ appId,
1166
+ existingSchema,
1167
+ `auto_before_removal_${Date.now()}`
1168
+ );
1169
+ }
1170
+ }
1171
+ }
1172
+ const firestoreData = toFirestoreFormat(schema);
1173
+ const now = Date.now();
1174
+ const docData = {
1175
+ ...firestoreData,
1176
+ _metadata: {
1177
+ version: options.expectedVersion ? options.expectedVersion + 1 : 1,
1178
+ updatedAt: now,
1179
+ createdAt: existingSchema ? void 0 : now,
1180
+ source: options.source || "manual"
1181
+ }
1182
+ };
1183
+ const db2 = getFirestore();
1184
+ await db2.doc(`users/${uid}/${this.appsCollection}/${appId}`).set(docData, { merge: true });
1185
+ this.invalidateCache(uid, appId);
1186
+ return { success: true, snapshotId };
1187
+ } catch (error) {
1188
+ console.error("[SchemaStore] Error saving schema:", error);
1189
+ return {
1190
+ success: false,
1191
+ error: error instanceof Error ? error.message : "Unknown error"
1192
+ };
1193
+ }
1194
+ }
1195
+ /** Create a new app with initial schema */
1196
+ async create(uid, metadata) {
1197
+ const appId = `app-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
1198
+ const now = Date.now();
1199
+ const schema = {
1200
+ name: metadata.name,
1201
+ description: metadata.description,
1202
+ orbitals: []
1203
+ };
1204
+ const firestoreData = toFirestoreFormat(schema);
1205
+ const docData = {
1206
+ ...firestoreData,
1207
+ _metadata: { version: 1, createdAt: now, updatedAt: now, source: "manual" }
1208
+ };
1209
+ const db2 = getFirestore();
1210
+ await db2.doc(`users/${uid}/${this.appsCollection}/${appId}`).set(docData);
1211
+ this.listCache.delete(uid);
1212
+ return { appId, schema };
1213
+ }
1214
+ /** Delete an app */
1215
+ async delete(uid, appId) {
1216
+ try {
1217
+ const db2 = getFirestore();
1218
+ const ref = db2.doc(`users/${uid}/${this.appsCollection}/${appId}`);
1219
+ const doc = await ref.get();
1220
+ if (!doc.exists) return false;
1221
+ await ref.delete();
1222
+ this.invalidateCache(uid, appId);
1223
+ return true;
1224
+ } catch (error) {
1225
+ console.error("[SchemaStore] Error deleting app:", error);
1226
+ return false;
1227
+ }
1228
+ }
1229
+ /** List all apps for a user */
1230
+ async list(uid) {
1231
+ const cached = this.listCache.get(uid);
1232
+ if (cached && Date.now() - cached.timestamp < LIST_CACHE_TTL_MS) {
1233
+ return cached.apps;
1234
+ }
1235
+ try {
1236
+ const db2 = getFirestore();
1237
+ const snapshot = await db2.collection(`users/${uid}/${this.appsCollection}`).select("name", "description", "domainContext", "_metadata", "orbitalCount", "traitCount").orderBy("_metadata.updatedAt", "desc").get();
1238
+ const apps = snapshot.docs.map((doc) => {
1239
+ const data = doc.data();
1240
+ const metadata = data._metadata;
1241
+ const orbitalCount = data.orbitalCount;
1242
+ return {
1243
+ id: doc.id,
1244
+ name: data.name || "Untitled",
1245
+ description: data.description,
1246
+ updatedAt: metadata?.updatedAt || Date.now(),
1247
+ createdAt: metadata?.createdAt || Date.now(),
1248
+ stats: { entities: orbitalCount ?? 0, pages: 0, states: 0, events: 0, transitions: 0 },
1249
+ domainContext: data.domainContext,
1250
+ hasValidationErrors: false
1251
+ };
1252
+ });
1253
+ this.listCache.set(uid, { apps, timestamp: Date.now() });
1254
+ return apps;
1255
+ } catch (error) {
1256
+ console.error("[SchemaStore] Error listing apps:", error);
1257
+ return [];
1258
+ }
1259
+ }
1260
+ /** Compute stats from OrbitalSchema */
1261
+ computeStats(schema) {
1262
+ const orbitals = schema.orbitals || [];
1263
+ const entities = orbitals.length;
1264
+ const pages = orbitals.reduce((n, o) => n + (o.pages?.length || 0), 0);
1265
+ const allTraits = [
1266
+ ...schema.traits || [],
1267
+ ...orbitals.flatMap(
1268
+ (o) => (o.traits || []).filter((t) => typeof t !== "string" && "stateMachine" in t)
1269
+ )
1270
+ ];
1271
+ return {
1272
+ states: allTraits.flatMap((t) => t.stateMachine?.states || []).length,
1273
+ events: allTraits.flatMap((t) => t.stateMachine?.events || []).length,
1274
+ pages,
1275
+ entities,
1276
+ transitions: allTraits.flatMap((t) => t.stateMachine?.transitions || []).length
1277
+ };
1278
+ }
1279
+ /** Invalidate caches for a specific app */
1280
+ invalidateCache(uid, appId) {
1281
+ this.schemaCache.delete(`${uid}:${appId}`);
1282
+ this.listCache.delete(uid);
1283
+ }
1284
+ /** Clear all caches */
1285
+ clearCaches() {
1286
+ this.schemaCache.clear();
1287
+ this.listCache.clear();
1288
+ }
1289
+ /** Get the collection path for an app */
1290
+ getAppDocPath(uid, appId) {
1291
+ return `users/${uid}/${this.appsCollection}/${appId}`;
1292
+ }
1293
+ /** Expose apps collection name for subcollection stores */
1294
+ getAppsCollection() {
1295
+ return this.appsCollection;
1296
+ }
1297
+ };
1298
+
1299
+ // src/stores/SnapshotStore.ts
1300
+ var SNAPSHOTS_COLLECTION = "snapshots";
1301
+ var SnapshotStore = class {
1302
+ appsCollection;
1303
+ constructor(appsCollection = "apps") {
1304
+ this.appsCollection = appsCollection;
1305
+ }
1306
+ getCollectionPath(uid, appId) {
1307
+ return `users/${uid}/${this.appsCollection}/${appId}/${SNAPSHOTS_COLLECTION}`;
1308
+ }
1309
+ getAppDocPath(uid, appId) {
1310
+ return `users/${uid}/${this.appsCollection}/${appId}`;
1311
+ }
1312
+ /** Create a snapshot of the current schema */
1313
+ async create(uid, appId, schema, reason) {
1314
+ const db2 = getFirestore();
1315
+ const snapshotId = `snapshot_${Date.now()}`;
1316
+ const snapshotDoc = {
1317
+ id: snapshotId,
1318
+ timestamp: Date.now(),
1319
+ schema: toFirestoreFormat(schema),
1320
+ reason
1321
+ };
1322
+ await db2.doc(`${this.getCollectionPath(uid, appId)}/${snapshotId}`).set(snapshotDoc);
1323
+ const appDocRef = db2.doc(this.getAppDocPath(uid, appId));
1324
+ const appDoc = await appDocRef.get();
1325
+ const currentMeta = appDoc.data()?._historyMeta;
1326
+ const updatedMeta = {
1327
+ latestSnapshotId: snapshotId,
1328
+ latestChangeSetId: currentMeta?.latestChangeSetId,
1329
+ snapshotCount: (currentMeta?.snapshotCount || 0) + 1,
1330
+ changeSetCount: currentMeta?.changeSetCount || 0
1331
+ };
1332
+ await appDocRef.set({ _historyMeta: updatedMeta }, { merge: true });
1333
+ return snapshotId;
1334
+ }
1335
+ /** Get all snapshots for an app (ordered by timestamp desc) */
1336
+ async getAll(uid, appId) {
1337
+ const db2 = getFirestore();
1338
+ const query = await db2.collection(this.getCollectionPath(uid, appId)).orderBy("timestamp", "desc").get();
1339
+ return query.docs.map((doc) => doc.data());
1340
+ }
1341
+ /** Get a specific snapshot by ID */
1342
+ async get(uid, appId, snapshotId) {
1343
+ const db2 = getFirestore();
1344
+ const doc = await db2.doc(`${this.getCollectionPath(uid, appId)}/${snapshotId}`).get();
1345
+ if (!doc.exists) return null;
1346
+ return doc.data();
1347
+ }
1348
+ /** Delete a snapshot */
1349
+ async delete(uid, appId, snapshotId) {
1350
+ const db2 = getFirestore();
1351
+ const ref = db2.doc(`${this.getCollectionPath(uid, appId)}/${snapshotId}`);
1352
+ const doc = await ref.get();
1353
+ if (!doc.exists) return false;
1354
+ await ref.delete();
1355
+ const appDocRef = db2.doc(this.getAppDocPath(uid, appId));
1356
+ const appDoc = await appDocRef.get();
1357
+ const currentMeta = appDoc.data()?._historyMeta;
1358
+ if (currentMeta) {
1359
+ const updatedMeta = {
1360
+ ...currentMeta,
1361
+ snapshotCount: Math.max(0, (currentMeta.snapshotCount || 1) - 1),
1362
+ latestSnapshotId: currentMeta.latestSnapshotId === snapshotId ? void 0 : currentMeta.latestSnapshotId
1363
+ };
1364
+ await appDocRef.set({ _historyMeta: updatedMeta }, { merge: true });
1365
+ }
1366
+ return true;
1367
+ }
1368
+ /** Get schema snapshot at a specific version */
1369
+ async getByVersion(uid, appId, version) {
1370
+ const db2 = getFirestore();
1371
+ const query = await db2.collection(this.getCollectionPath(uid, appId)).where("version", "==", version).limit(1).get();
1372
+ if (query.empty) return null;
1373
+ const snapshot = query.docs[0].data();
1374
+ return fromFirestoreFormat(snapshot.schema);
1375
+ }
1376
+ /** Get the schema from a snapshot (deserialized) */
1377
+ getSchemaFromSnapshot(snapshot) {
1378
+ return fromFirestoreFormat(snapshot.schema);
1379
+ }
1380
+ };
1381
+
1382
+ // src/stores/ChangeSetStore.ts
1383
+ var CHANGESETS_COLLECTION = "changesets";
1384
+ var ChangeSetStore = class {
1385
+ appsCollection;
1386
+ constructor(appsCollection = "apps") {
1387
+ this.appsCollection = appsCollection;
1388
+ }
1389
+ getCollectionPath(uid, appId) {
1390
+ return `users/${uid}/${this.appsCollection}/${appId}/${CHANGESETS_COLLECTION}`;
1391
+ }
1392
+ getAppDocPath(uid, appId) {
1393
+ return `users/${uid}/${this.appsCollection}/${appId}`;
1394
+ }
1395
+ /** Append a changeset to history */
1396
+ async append(uid, appId, changeSet) {
1397
+ const db2 = getFirestore();
1398
+ await db2.doc(`${this.getCollectionPath(uid, appId)}/${changeSet.id}`).set(changeSet);
1399
+ const appDocRef = db2.doc(this.getAppDocPath(uid, appId));
1400
+ const appDoc = await appDocRef.get();
1401
+ const currentMeta = appDoc.data()?._historyMeta;
1402
+ const updatedMeta = {
1403
+ latestSnapshotId: currentMeta?.latestSnapshotId,
1404
+ latestChangeSetId: changeSet.id,
1405
+ snapshotCount: currentMeta?.snapshotCount || 0,
1406
+ changeSetCount: (currentMeta?.changeSetCount || 0) + 1
1407
+ };
1408
+ await appDocRef.set({ _historyMeta: updatedMeta }, { merge: true });
1409
+ }
1410
+ /** Get change history for an app (ordered by version desc) */
1411
+ async getHistory(uid, appId) {
1412
+ try {
1413
+ const db2 = getFirestore();
1414
+ const query = await db2.collection(this.getCollectionPath(uid, appId)).orderBy("version", "desc").get();
1415
+ return query.docs.map((doc) => doc.data());
1416
+ } catch (error) {
1417
+ console.error("[ChangeSetStore] Error getting change history:", error);
1418
+ return [];
1419
+ }
1420
+ }
1421
+ /** Get a specific changeset by ID */
1422
+ async get(uid, appId, changeSetId) {
1423
+ const db2 = getFirestore();
1424
+ const doc = await db2.doc(`${this.getCollectionPath(uid, appId)}/${changeSetId}`).get();
1425
+ if (!doc.exists) return null;
1426
+ return doc.data();
1427
+ }
1428
+ /** Update a changeset's status */
1429
+ async updateStatus(uid, appId, changeSetId, status) {
1430
+ const db2 = getFirestore();
1431
+ const ref = db2.doc(`${this.getCollectionPath(uid, appId)}/${changeSetId}`);
1432
+ const doc = await ref.get();
1433
+ if (!doc.exists) return;
1434
+ await ref.update({ status });
1435
+ }
1436
+ /** Delete a changeset */
1437
+ async delete(uid, appId, changeSetId) {
1438
+ const db2 = getFirestore();
1439
+ const ref = db2.doc(`${this.getCollectionPath(uid, appId)}/${changeSetId}`);
1440
+ const doc = await ref.get();
1441
+ if (!doc.exists) return false;
1442
+ await ref.delete();
1443
+ const appDocRef = db2.doc(this.getAppDocPath(uid, appId));
1444
+ const appDoc = await appDocRef.get();
1445
+ const currentMeta = appDoc.data()?._historyMeta;
1446
+ if (currentMeta) {
1447
+ const updatedMeta = {
1448
+ ...currentMeta,
1449
+ changeSetCount: Math.max(0, (currentMeta.changeSetCount || 1) - 1),
1450
+ latestChangeSetId: currentMeta.latestChangeSetId === changeSetId ? void 0 : currentMeta.latestChangeSetId
1451
+ };
1452
+ await appDocRef.set({ _historyMeta: updatedMeta }, { merge: true });
1453
+ }
1454
+ return true;
1455
+ }
1456
+ };
1457
+
1458
+ // src/stores/ValidationStore.ts
1459
+ var VALIDATION_COLLECTION = "validation";
1460
+ var VALIDATION_DOC_ID = "current";
1461
+ var ValidationStore = class {
1462
+ appsCollection;
1463
+ constructor(appsCollection = "apps") {
1464
+ this.appsCollection = appsCollection;
1465
+ }
1466
+ getDocPath(uid, appId) {
1467
+ return `users/${uid}/${this.appsCollection}/${appId}/${VALIDATION_COLLECTION}/${VALIDATION_DOC_ID}`;
1468
+ }
1469
+ getAppDocPath(uid, appId) {
1470
+ return `users/${uid}/${this.appsCollection}/${appId}`;
1471
+ }
1472
+ /** Save validation results */
1473
+ async save(uid, appId, results) {
1474
+ const db2 = getFirestore();
1475
+ await db2.doc(this.getDocPath(uid, appId)).set(results);
1476
+ const validationMeta = {
1477
+ errorCount: results.errors?.length || 0,
1478
+ warningCount: results.warnings?.length || 0,
1479
+ validatedAt: results.validatedAt
1480
+ };
1481
+ await db2.doc(this.getAppDocPath(uid, appId)).set(
1482
+ { _operational: { validationMeta } },
1483
+ { merge: true }
1484
+ );
1485
+ }
1486
+ /** Get validation results */
1487
+ async get(uid, appId) {
1488
+ try {
1489
+ const db2 = getFirestore();
1490
+ const doc = await db2.doc(this.getDocPath(uid, appId)).get();
1491
+ if (!doc.exists) return null;
1492
+ return doc.data();
1493
+ } catch (error) {
1494
+ console.error("[ValidationStore] Error getting validation results:", error);
1495
+ return null;
1496
+ }
1497
+ }
1498
+ /** Clear validation results */
1499
+ async clear(uid, appId) {
1500
+ const db2 = getFirestore();
1501
+ const { FieldValue } = await import('firebase-admin/firestore');
1502
+ await db2.doc(this.getDocPath(uid, appId)).delete();
1503
+ await db2.doc(this.getAppDocPath(uid, appId)).update({
1504
+ "_operational.validationMeta": FieldValue.delete()
1505
+ });
1506
+ }
1507
+ };
1508
+
1509
+ export { AppError, ChangeSetStore, ConflictError, EventBus, ForbiddenError, MockDataService, NotFoundError, SchemaProtectionService, SchemaStore, SnapshotStore, UnauthorizedError, ValidationError, ValidationStore, applyFiltersToQuery, asyncHandler, authenticateFirebase, closeWebSocketServer, dataService, db, emitEntityEvent, env, errorHandler, extractPaginationParams, fromFirestoreFormat, getAuth, getConnectedClientCount, getFirestore, getWebSocketServer, logger, mockDataService, notFoundHandler, parseQueryFilters, seedMockData, serverEventBus, setupEventBroadcast, toFirestoreFormat, validateBody, validateParams, validateQuery };
1014
1510
  //# sourceMappingURL=index.js.map
1015
1511
  //# sourceMappingURL=index.js.map