MCPcopy
hub / github.com/nock/nock / Scope

Class Scope

lib/scope.js:61–281  ·  view source on GitHub ↗

* @param {string|RegExp|URL} basePath * @param {Object} options * @param {boolean} options.allowUnmocked * @param {string[]} options.badheaders * @param {function} options.conditionally * @param {boolean} options.encodedQueryParams * @param {function} options.filteringScope * @para

Source from the content-addressed store, hash-verified

59 * @constructor
60 */
61class Scope extends EventEmitter {
62 constructor(basePath, options) {
63 super()
64
65 this.keyedInterceptors = {}
66 this.interceptors = []
67 this.transformPathFunction = null
68 this.transformRequestBodyFunction = null
69 this.matchHeaders = []
70 this.scopeOptions = options || {}
71 this.urlParts = {}
72 this._persist = false
73 this.contentLen = false
74 this.date = null
75 this.basePath = basePath
76 this.basePathname = ''
77 this.port = null
78 this._defaultReplyHeaders = []
79
80 let logNamespace = String(basePath)
81
82 if (!(basePath instanceof RegExp)) {
83 this.urlParts = normalizeUrl(basePath)
84 this.port = this.urlParts.port
85 this.basePathname = this.urlParts.pathname.replace(/\/$/, '')
86 this.basePath = `${this.urlParts.protocol}//${this.urlParts.hostname}:${this.port}`
87 logNamespace = this.urlParts.host
88 }
89
90 this.logger = scopeDebuglog(logNamespace)
91 }
92
93 add(key, interceptor) {
94 if (!(key in this.keyedInterceptors)) {
95 this.keyedInterceptors[key] = []
96 }
97 this.keyedInterceptors[key].push(interceptor)
98 addInterceptor(
99 this.basePath,
100 interceptor,
101 this,
102 this.scopeOptions,
103 this.urlParts.hostname,
104 )
105 }
106
107 remove(key, interceptor) {
108 if (this._persist) {
109 return
110 }
111 const arr = this.keyedInterceptors[key]
112 if (arr) {
113 arr.splice(arr.indexOf(interceptor), 1)
114 if (arr.length === 0) {
115 delete this.keyedInterceptors[key]
116 }
117 }
118 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…