lavamoat-core
Version:
LavaMoat kernel and utils
66 lines • 4.04 kB
TypeScript
export = endowmentsToolkit;
/**
* Returns a compy of endowmentsToolkit initialized on provided configuration.
*
* @param {object} opts
* @param {DefaultWrapperFn} [opts.createFunctionWrapper]
* @param {boolean} [opts.handleGlobalWrite]
* @param {Set<string>} [opts.knownWritableFields] - List of globals that can be
* mutated later
*/
declare function endowmentsToolkit({ createFunctionWrapper, handleGlobalWrite, knownWritableFields, }?: {
createFunctionWrapper?: DefaultWrapperFn | undefined;
handleGlobalWrite?: boolean | undefined;
knownWritableFields?: Set<string> | undefined;
}): {
getEndowmentsForConfig: <T extends object>(sourceRef: T, packagePolicy: LMPolicy.PackagePolicy, unwrapTo: object, unwrapFrom: object) => Partial<T>;
copyWrappedGlobals: (globalRef: object, target: Record<PropertyKey, any>, globalThisRefs: string[]) => Record<PropertyKey, any>;
getBuiltinForConfig: <T extends object>(moduleNamespace: T, moduleId: string, policyBuiltin: LMPolicy.BuiltinPolicy) => Partial<T>;
createFunctionWrapper: DefaultWrapperFn;
makeMinimalViewOfRef: <T extends object>(sourceRef: T, paths: string[], unwrapTo?: object | undefined, unwrapFrom?: object | undefined, explicitlyBanned?: string[] | undefined, allowedWriteFields?: Set<string> | undefined) => Partial<T>;
copyValueAtPath: (visitedPath: string, pathParts: string[], explicitlyBanned: string[], sourceRef: object, targetRef: object, unwrapTo?: object | undefined, unwrapFrom?: object | undefined) => void;
applyGetSetPropDescTransforms: (sourcePropDesc: PropertyDescriptor, unwrapFromGlobalThis: object, unwrapToGlobalThis: object) => PropertyDescriptor;
applyEndowmentPropDescTransforms: (propDesc: PropertyDescriptor, unwrapFromCompartmentGlobalThis: object, unwrapToGlobalThis: object) => PropertyDescriptor;
};
declare namespace endowmentsToolkit {
export { _test, DefaultWrapperFn, CopyWrappedGlobals, CopyValueAtPath, ApplyGetSetPropDescTransforms, ApplyEndowmentPropDescTransforms };
}
declare namespace _test {
export { instrumentDynamicValueAtPath };
}
/**
* The default implementation of the utility for wrapping endowed function to
* set `this` to a correct reference.
*/
type DefaultWrapperFn = (sourceValue: (...args: any[]) => any, unwrapTest: (value: any) => boolean, unwrapTo: object) => (...args: any[]) => any;
/**
* Makes a copy of all globals from the global ref to a target and wraps them
* with the wrapper this endowmentsToolkit was configured to use. It also copies
* all circular references to the root package compartment globalThis.
*/
type CopyWrappedGlobals = (globalRef: object, target: Record<PropertyKey, any>, globalThisRefs: string[]) => Record<PropertyKey, any>;
/**
* A recursive function to copy a single (nested) property located at the
* provided path from a sourceRef to targetRef.
*/
type CopyValueAtPath = (visitedPath: string, pathParts: string[], explicitlyBanned: string[], sourceRef: object, targetRef: object, unwrapTo?: object | undefined, unwrapFrom?: object | undefined) => void;
/**
* Utility function used by copyWrappedGlobals to wrap a property with a getter
* and/or setter.
*/
type ApplyGetSetPropDescTransforms = (sourcePropDesc: PropertyDescriptor, unwrapFromGlobalThis: object, unwrapToGlobalThis: object) => PropertyDescriptor;
/**
* Utility function used by copyWrappedGlobals to choose a wrapping strategy for
* a property.
*/
type ApplyEndowmentPropDescTransforms = (propDesc: PropertyDescriptor, unwrapFromCompartmentGlobalThis: object, unwrapToGlobalThis: object) => PropertyDescriptor;
/**
* Puts a getter at the end of the path that returns the nested values from a
* top-level field that might change at runtime.
*
* @param {string[]} pathParts
* @param {Record<string, any>} sourceRef
* @param {Record<string, any>} targetRef
*/
declare function instrumentDynamicValueAtPath(pathParts: string[], sourceRef: Record<string, any>, targetRef: Record<string, any>): void;
//# sourceMappingURL=endowmentsToolkit.d.ts.map