* Helper to convert PermissionRule array to PermissionUpdate array
( rules: PermissionRule[], updateType: 'addRules' | 'replaceRules', )
| 1373 | * Helper to convert PermissionRule array to PermissionUpdate array |
| 1374 | */ |
| 1375 | function convertRulesToUpdates( |
| 1376 | rules: PermissionRule[], |
| 1377 | updateType: 'addRules' | 'replaceRules', |
| 1378 | ): PermissionUpdate[] { |
| 1379 | // Group rules by source and behavior |
| 1380 | const grouped = new Map<string, PermissionRuleValue[]>() |
| 1381 | |
| 1382 | for (const rule of rules) { |
| 1383 | const key = `${rule.source}:${rule.ruleBehavior}` |
| 1384 | if (!grouped.has(key)) { |
| 1385 | grouped.set(key, []) |
| 1386 | } |
| 1387 | grouped.get(key)!.push(rule.ruleValue) |
| 1388 | } |
| 1389 | |
| 1390 | // Convert to PermissionUpdate array |
| 1391 | const updates: PermissionUpdate[] = [] |
| 1392 | for (const [key, ruleValues] of grouped) { |
| 1393 | const [source, behavior] = key.split(':') |
| 1394 | updates.push({ |
| 1395 | type: updateType, |
| 1396 | rules: ruleValues, |
| 1397 | behavior: behavior as PermissionBehavior, |
| 1398 | destination: source as PermissionUpdateDestination, |
| 1399 | }) |
| 1400 | } |
| 1401 | |
| 1402 | return updates |
| 1403 | } |
| 1404 | |
| 1405 | /** |
| 1406 | * Apply permission rules to context (additive - for initial setup) |
no test coverage detected