"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateModesExtractor = void 0;
const policy_engine_1 = require("@solidlab/policy-engine");
const ModesExtractor_1 = require("./ModesExtractor");
/**
 * Adds the `create` access mode to the result of the source in case the target resource does not exist.
 */
class CreateModesExtractor extends ModesExtractor_1.ModesExtractor {
    source;
    resourceSet;
    constructor(source, resourceSet) {
        super();
        this.source = source;
        this.resourceSet = resourceSet;
    }
    async canHandle(operation) {
        await this.source.canHandle(operation);
    }
    async handle(operation) {
        const accessMap = await this.source.handle(operation);
        if (!accessMap.hasEntry(operation.target, policy_engine_1.PERMISSIONS.Create) &&
            !await this.resourceSet.hasResource(operation.target)) {
            accessMap.add(operation.target, policy_engine_1.PERMISSIONS.Create);
        }
        return accessMap;
    }
}
exports.CreateModesExtractor = CreateModesExtractor;
//# sourceMappingURL=CreateModesExtractor.js.map