@solid/community-server
Version:
Community Solid Server: an open and modular implementation of the Solid specifications
51 lines • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntermediateCreateExtractor = void 0;
const policy_engine_1 = require("@solidlab/policy-engine");
const ModesExtractor_1 = require("./ModesExtractor");
/**
* Returns the required access modes from the source {@link ModesExtractor}.
* In case create permissions are required,
* verifies if any of the containers permissions also need to be created
* and adds the corresponding identifier/mode combinations.
*/
class IntermediateCreateExtractor extends ModesExtractor_1.ModesExtractor {
resourceSet;
strategy;
source;
/**
* Certain permissions depend on the existence of the target resource.
* The provided {@link ResourceSet} will be used for that.
*
* @param resourceSet - {@link ResourceSet} that can verify the target resource existence.
* @param strategy - {@link IdentifierStrategy} that will be used to determine parent containers.
* @param source - The source {@link ModesExtractor}.
*/
constructor(resourceSet, strategy, source) {
super();
this.resourceSet = resourceSet;
this.strategy = strategy;
this.source = source;
}
async canHandle(input) {
return this.source.canHandle(input);
}
async handle(input) {
const requestedModes = await this.source.handle(input);
for (const key of requestedModes.distinctKeys()) {
if (requestedModes.hasEntry(key, policy_engine_1.PERMISSIONS.Create)) {
// Add the `create` mode if the parent does not exist yet
const parent = this.strategy.getParentContainer(key);
if (!await this.resourceSet.hasResource(parent)) {
// It is not completely clear at this point which permissions need to be available
// on intermediate containers to create them,
// so we stick with `create` for now.
requestedModes.add(parent, policy_engine_1.PERMISSIONS.Create);
}
}
}
return requestedModes;
}
}
exports.IntermediateCreateExtractor = IntermediateCreateExtractor;
//# sourceMappingURL=IntermediateCreateExtractor.js.map