22 lines
694 B
JavaScript
22 lines
694 B
JavaScript
|
|
"use strict";
|
||
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
|
exports.createInMemoryEntityRegistry = createInMemoryEntityRegistry;
|
||
|
|
exports.assertTenantIsolation = assertTenantIsolation;
|
||
|
|
function createInMemoryEntityRegistry(entities) {
|
||
|
|
const index = new Map();
|
||
|
|
for (const e of entities) {
|
||
|
|
index.set(`${e.tenantId}:${e.entityId}`, e);
|
||
|
|
}
|
||
|
|
return {
|
||
|
|
entities,
|
||
|
|
getEntity(entityId, tenantId) {
|
||
|
|
return index.get(`${tenantId}:${entityId}`);
|
||
|
|
},
|
||
|
|
};
|
||
|
|
}
|
||
|
|
function assertTenantIsolation(actorTenantId, resourceTenantId) {
|
||
|
|
if (actorTenantId !== resourceTenantId) {
|
||
|
|
throw new Error('Tenant isolation violation');
|
||
|
|
}
|
||
|
|
}
|