nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: pinojs/pino-http
Pull request #22 (2017-01-26 10:34:57)

Handle client abort and server timeout separatly.


Patch:
diff --git a/logger.js b/logger.js
index 295a31f..2a323e6 100644
--- a/logger.js
+++ b/logger.js
@@ -24,7 +24,7 @@ function pinoLogger (opts, stream) {
   loggingMiddleware.logger = logger
   return loggingMiddleware
 
-  function onResFinished (err) {
+  function onResFinished (err, msg) {
     this.removeListener('finish', onResFinished)
     this.removeListener('error', onResFinished)
 
@@ -43,13 +43,20 @@ function pinoLogger (opts, stream) {
     log[useLevel]({
       res: this,
       responseTime: responseTime
-    }, 'request completed')
+    }, 'request ' + (msg || 'completed'))
   }
 
   function onReqAborted () {
+    var res = this.res
+    onResFinished.call(res, null, 'aborted')
+  }
+
+  function onReqTimeout () {
+    this.removeListener('aborted', onReqAborted)
+
     var res = this.res
     res.statusCode = 408
-    onResFinished.call(res, new Error('Aborted'))
+    onResFinished.call(res, new Error('Timeout'))
   }
 
   function loggingMiddleware (req, res, next) {
@@ -60,8 +67,8 @@ function pinoLogger (opts, stream) {
 
     res.on('finish', onResFinished)
     res.on('error', onResFinished)
-    // it's possible that browser aborts connection, or http-server because of timeout
     req.on('aborted', onReqAborted)
+    req.socket.on('timeout', onReqTimeout.bind(req))
 
     if (next) {
       next()
diff --git a/package.json b/package.json
index 4ecf155..e639000 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,7 @@
   "description": "High-speed HTTP logger for Node.js",
   "main": "logger.js",
   "dependencies": {
-    "pino": "^3.0.1"
+    "pino": "^3.3.2"
   },
   "devDependencies": {
     "coveralls": "^2.11.15",


Test patch:
diff --git a/test.js b/test.js
index 450e2bc..21680d9 100644
--- a/test.js
+++ b/test.js
@@ -291,14 +291,12 @@ test('react on aborted event from clientside', function (t) {
   }, logger)
 
   dest.on('data', function (line) {
-    t.equal(line.msg, 'request errored', 'message is set')
-    t.equal(line.err.message, 'Aborted', 'error message is set')
-    t.equal(line.res.statusCode, 408, 'statusCode is 408')
+    t.equal(line.msg, 'request aborted', 'message is set')
     t.end()
   })
 })
 
-test('react on aborted event from server', function (t) {
+test('react on timeout event from server', function (t) {
   var dest = split(JSON.parse)
 
   var idToTest
@@ -325,7 +323,7 @@ test('react on aborted event from server', function (t) {
 
   dest.on('data', function (line) {
     t.equal(line.msg, 'request errored', 'message is set')
-    t.equal(line.err.message, 'Aborted', 'error message is set')
+    t.equal(line.err.message, 'Timeout', 'error message is set')
     t.equal(line.res.statusCode, 408, 'statusCode is 408')
     t.end()
   })
Repository: pinojs/pino-http
Pull request #99 (2020-04-23 21:47:03)

Remove trailing space in error message
Currently causing the tests to fail in express-pino-logger:

```text
  not ok message is set
    --- wanted                  
    +++ found                   
    -"request errored"          
    +"request errored "         
```

LinusU: @mcollina done 👍 

Patch:
diff --git a/logger.js b/logger.js
index fefcda5..e67e5b7 100644
--- a/logger.js
+++ b/logger.js
@@ -50,7 +50,7 @@ function pinoLogger (opts, stream) {
   delete opts.autoLogging
 
   var successMessage = opts.customSuccessMessage || function () { return 'request completed' }
-  var errorMessage = opts.customErrorMessage || function () { return 'request errored ' }
+  var errorMessage = opts.customErrorMessage || function () { return 'request errored' }
   delete opts.customSuccessfulMessage
   delete opts.customErroredMessage
 


Test patch:
diff --git a/test.js b/test.js
index c33f642..b227b1c 100644
--- a/test.js
+++ b/test.js
@@ -257,6 +257,7 @@ test('responseTime for errored request', function (t) {
 
   dest.on('data', function (line) {
     t.ok(line.responseTime >= 0, 'responseTime is defined')
+    t.equal(line.msg, 'request errored', 'message is set')
     t.end()
   })
 })
Repository: pinojs/pino-http
Pull request #100 (2020-04-28 13:28:46)

Support regex path matching for autoLogging.ignorePaths option
I was using the latest version and have a use-case where I want to ignore a dynamic range of paths that can change over time. In order to support this I thought that adding RegExp support to the ignoring mechanism might be an option.

Let me know what you think. Thanks for taking a look.


Patch:
diff --git a/logger.js b/logger.js
index e67e5b7..e1b096f 100644
--- a/logger.js
+++ b/logger.js
@@ -100,7 +100,13 @@ function pinoLogger (opts, stream) {
           url = URL.parse(req.url)
         }
         if (url && url.pathname) {
-          shouldLogSuccess = !autoLoggingIgnorePaths.includes(url.pathname)
+          shouldLogSuccess = !autoLoggingIgnorePaths.find(ignorePath => {
+            if (ignorePath instanceof RegExp) {
+              return ignorePath.test(url.pathname)
+            }
+
+            return ignorePath === url.pathname
+          })
         }
       }
 


Test patch:
diff --git a/test.js b/test.js
index b227b1c..d9bf360 100644
--- a/test.js
+++ b/test.js
@@ -377,6 +377,30 @@ test('auto logging with autoLogging set to true and getPath result is not ignore
   })
 })
 
+test('no auto logging with autoLogging set to use regular expressions. result is ignored', function (t) {
+  var dest = split(JSON.parse)
+  var logger = pinoHttp({
+    autoLogging: {
+      ignorePaths: [/\/[A-z]{4}\/ignorethis/, '/another-ignored-path'],
+      getPath: function (req) {
+        return req.url
+      }
+    }
+  }, dest)
+
+  setup(t, logger, function (err, server) {
+    t.error(err)
+    doGet(server, '/abcd/ignorethis')
+    doGet(server, '/another-ignored-path')
+    doGet(server, '/abcd0/shouldlogthis')
+  })
+
+  dest.on('data', function (line) {
+    t.pass('path should log')
+    t.end()
+  })
+})
+
 test('support a custom instance', function (t) {
   var dest = split(JSON.parse)
   var logger = pinoHttp({
Repository: plaid/sanctuary
Pull request #99 (2015-09-23 00:16:48)

unfoldr
Closes https://github.com/plaid/sanctuary/issues/89

davidchambers: This function belongs in the List section rather than the String section.

benperez: :zap: 

Patch:
diff --git a/index.js b/index.js
index b6ad08b..8514ee9 100644
--- a/index.js
+++ b/index.js
@@ -1616,6 +1616,32 @@
     return R.map(get(type, key), xs);
   });
 
+  //# unfoldr :: (b -> Maybe (a, b)) -> b -> [a]
+  //.
+  //. Takes a function and a seed value, and returns a list generated by
+  //. applying the function repeatedly. The list is initially empty. The
+  //. function is initially applied to the seed value. Each application
+  //. of the function should result in either:
+  //.
+  //.   - a Nothing, in which case the list is returned; or
+  //.
+  //.   - Just a pair, in which case the first element is appended to
+  //.     the list and the function is applied to the second element.
+  //.
+  //. ```javascript
+  //. > S.unfoldr(n => n < 5 ? S.Just([n, n + 1]) : S.Nothing(), 1)
+  //. [1, 2, 3, 4]
+  //. ```
+  S.unfoldr = def('unfoldr', [Function, a], function(f, x) {
+    var result = [];
+    var m = f(x);
+    while (is(Just, m)) {
+      result.push(m.value[0]);
+      m = f(m.value[1]);
+    }
+    return result;
+  });
+
   //. ### Object
 
   //# get :: TypeRep a -> String -> Accessible -> Maybe a


Test patch:
diff --git a/test/index.js b/test/index.js
index a1e7753..c9f95e8 100644
--- a/test/index.js
+++ b/test/index.js
@@ -2368,6 +2368,31 @@ describe('list', function() {
 
   });
 
+  describe('unfoldr', function() {
+
+    it('is a binary function', function() {
+      eq(typeof S.unfoldr, 'function');
+      eq(S.unfoldr.length, 2);
+    });
+
+    it('type checks its arguments', function() {
+      assert.throws(function() { S.unfoldr(null); },
+                    errorEq(TypeError,
+                            '‘unfoldr’ requires a value of type Function ' +
+                            'as its first argument; received null'));
+    });
+
+    it('correctly unfolds a value into a list', function() {
+      var f = function(n) {
+        return n >= 5 ? S.Nothing() : S.Just([n, n + 1]);
+      };
+      eq(S.unfoldr(f, 5), []);
+      eq(S.unfoldr(f, 4), [4]);
+      eq(S.unfoldr(f, 1), [1, 2, 3, 4]);
+    });
+
+  });
+
 });
 
 describe('object', function() {
Repository: plaid/sanctuary
Pull request #109 (2015-10-25 06:13:42)

regexp: add S.test
Like [`R.test`][1], but with the type checking we know and love. See ramda/ramda#1413 for a compelling example of the problems that arise due to Ramda's lack of type checking.

/cc @albrow


[1]: http://ramdajs.com/docs/#test



Patch:
diff --git a/index.js b/index.js
index 5516be5..a67614b 100644
--- a/index.js
+++ b/index.js
@@ -2015,6 +2015,22 @@
     return new RegExp(source, flags);
   });
 
+  //# test :: RegExp -> String -> Boolean
+  //.
+  //. Takes a pattern and a string, and returns `true` if the pattern
+  //. matches the string; `false` otherwise.
+  //.
+  //. ```javascript
+  //. > S.test(/^a/, 'abacus')
+  //. true
+  //.
+  //. > S.test(/^a/, 'banana')
+  //. false
+  //. ```
+  S.test = def('test', [RegExp, String], function(pattern, s) {
+    return pattern.test(s);
+  });
+
   //# match :: RegExp -> String -> Maybe [Maybe String]
   //.
   //. Takes a pattern and a string, and returns Just a list of matches


Test patch:
diff --git a/test/index.js b/test/index.js
index 21a9e2c..1280cfe 100644
--- a/test/index.js
+++ b/test/index.js
@@ -2938,6 +2938,40 @@ describe('regexp', function() {
 
   });
 
+  describe('test', function() {
+
+    it('is a binary function', function() {
+      eq(typeof S.test, 'function');
+      eq(S.test.length, 2);
+    });
+
+    it('type checks its arguments', function() {
+      assert.throws(function() { S.test('^a'); },
+                    errorEq(TypeError,
+                            '‘test’ requires a value of type RegExp ' +
+                            'as its first argument; received "^a"'));
+
+      assert.throws(function() { S.test(/^a/, [1, 2, 3]); },
+                    errorEq(TypeError,
+                            '‘test’ requires a value of type String ' +
+                            'as its second argument; received [1, 2, 3]'));
+    });
+
+    it('returns true if pattern matches string', function() {
+      eq(S.test(/^a/, 'abacus'), true);
+    });
+
+    it('returns false if pattern does not match string', function() {
+      eq(S.test(/^a/, 'banana'), false);
+    });
+
+    it('is curried', function() {
+      eq(S.test(/^a/).length, 1);
+      eq(S.test(/^a/)('abacus'), true);
+    });
+
+  });
+
   describe('match', function() {
 
     it('is a binary function', function() {
Repository: plaid/sanctuary
Pull request #115 (2015-11-08 22:13:05)

Add S.not
I haven't added anything about `S.lift` to the docs, I guess we can hold off on merging this until that's in.

davidchambers: I'd been thinking this function would be of type `Boolean -> Boolean`. `toBoolean` is a requirement for types which implement Alternative, but I don't see `not` as relating to Alternative. Can you convince me otherwise? :)

svozza: Well I actually envisaged it working your way too but then I saw how `and` and `or` were implemented and second-guessed myself. I'm happy to make this function more restrictive.
svozza: Done.

Patch:
diff --git a/index.js b/index.js
index 4c6bdc6..2c4a9de 100644
--- a/index.js
+++ b/index.js
@@ -1512,6 +1512,22 @@
     }
   };
 
+  //# not :: Boolean -> Boolean
+  //.
+  //. Takes a Boolean and returns the negation of that value
+  //. (`false` for `true`; `true` for `false`).
+  //.
+  //. ```javascript
+  //. > S.not(true)
+  //. false
+  //.
+  //. > S.not(false)
+  //. true
+  //. ```
+  S.not = def('not', [Boolean], function(x) {
+    return !x.valueOf();
+  });
+
   //# and :: a -> a -> a
   //.
   //. Takes two values of the same type and returns the second value


Test patch:
diff --git a/test/index.js b/test/index.js
index c3880fc..9bbbee7 100644
--- a/test/index.js
+++ b/test/index.js
@@ -1885,6 +1885,31 @@ describe('either', function() {
 
 describe('control', function() {
 
+  describe('not', function() {
+
+    it('is a unary function', function() {
+      eq(typeof S.not, 'function');
+      eq(S.not.length, 1);
+    });
+
+    it('can be applied to Booleans', function() {
+      eq(S.not(false), true);
+      eq(S.not(true), false);
+      // jshint -W053
+      eq(S.not(new Boolean(false)), true);
+      eq(S.not(new Boolean(true)), false);
+      // jshint +W053
+    });
+
+    it('throws when applied to a non-Boolean value', function() {
+      assert.throws(function() { S.not(0); },
+                    errorEq(TypeError,
+                            '‘not’ requires a value of type Boolean ' +
+                            'as its first argument; received 0'));
+    });
+
+  });
+
   describe('and', function() {
 
     it('is a binary function', function() {
Repository: plaid/sanctuary
Pull request #124 (2015-12-19 09:06:03)

Add flip function (again)
Following my gitastrophe in the intitial pull request for this (#116), here's the new version off `master`. :relieved: 

davidchambers: I'm sorry Git gave you the runaround. All is well now, I hope. Aside from the minor docstring change I suggested, LGTM. :)


Patch:
diff --git a/index.js b/index.js
index 4c6bdc6..c2b8fdd 100644
--- a/index.js
+++ b/index.js
@@ -402,6 +402,23 @@
   //. ```
   S.K = def('K', [a, b], function(x, y) { return x; });
 
+  //. ### Function
+
+  //# flip :: (a -> b -> c) -> b -> a -> c
+  //.
+  //. Takes a binary function and two values and returns the result of
+  //. applying the function - with its argument order reversed - to the
+  //. values. `flip` may also be applied to a Ramda-style curried
+  //. function with arity greater than two.
+  //.
+  //. ```javascript
+  //. > R.map(S.flip(Math.pow)(2), [1, 2, 3, 4, 5])
+  //. [1, 4, 9, 16, 25]
+  //. ```
+  S.flip = def('flip', [Function, a, b], function(f, x, y) {
+    return f(y, x);
+  });
+
   //. ### Composition
 
   //# compose :: (b -> c) -> (a -> b) -> a -> c


Test patch:
diff --git a/test/index.js b/test/index.js
index c3880fc..12d4282 100644
--- a/test/index.js
+++ b/test/index.js
@@ -264,6 +264,37 @@ describe('combinator', function() {
 
 });
 
+describe('function', function() {
+
+  describe('flip', function() {
+
+    it('is a ternary function', function() {
+      eq(typeof S.flip, 'function');
+      eq(S.flip.length, 3);
+    });
+
+    it('throws if applied to values of different types', function() {
+      assert.throws(function() { S.flip('wrong'); },
+                    errorEq(TypeError,
+                            '‘flip’ requires a value of type Function as its ' +
+                            'first argument; received "wrong"'));
+    });
+
+    it("flips a function's argument order", function() {
+      eq(R.map(S.flip(Math.pow)(2), [1, 2, 3, 4, 5]), [1, 4, 9, 16, 25]);
+      eq(S.flip(S.indexOf, ['a', 'b', 'c', 'd'], 'c'), S.Just(2));
+    });
+
+    it('is curried', function() {
+      eq(S.flip(S.indexOf).length, 2);
+      eq(S.flip(S.indexOf)(['a', 'b', 'c', 'd']).length, 1);
+      eq(S.flip(S.indexOf)(['a', 'b', 'c', 'd'])('c'), S.Just(2));
+    });
+
+  });
+
+});
+
 describe('composition', function() {
 
   describe('compose', function() {
Repository: plaid/sanctuary
Pull request #128 (2016-01-10 00:18:35)

regexp: make S.test referentially transparent for "global" patterns
See purescript/purescript-strings#54

`R.test` has always behaved this way. I simply forgot about this internal state when preparing #109.



Patch:
diff --git a/index.js b/index.js
index 346b0b5..5105303 100644
--- a/index.js
+++ b/index.js
@@ -2263,7 +2263,10 @@
   //. false
   //. ```
   S.test = def('test', [RegExp, String], function(pattern, s) {
-    return pattern.test(s);
+    var lastIndex = pattern.lastIndex;
+    var result = pattern.test(s);
+    pattern.lastIndex = lastIndex;
+    return result;
   });
 
   //# match :: RegExp -> String -> Maybe [Maybe String]


Test patch:
diff --git a/test/index.js b/test/index.js
index 5c63e38..dcc3883 100644
--- a/test/index.js
+++ b/test/index.js
@@ -3497,6 +3497,14 @@ describe('regexp', function() {
       eq(S.test(/^a/, 'banana'), false);
     });
 
+    it('is referentially transparent', function() {
+      var pattern = /x/g;
+      eq(pattern.lastIndex, 0);
+      eq(S.test(pattern, 'xyz'), true);
+      eq(pattern.lastIndex, 0);
+      eq(S.test(pattern, 'xyz'), true);
+    });
+
     it('is curried', function() {
       eq(S.test(/^a/).length, 1);
       eq(S.test(/^a/)('abacus'), true);
Repository: plaid/sanctuary
Pull request #153 (2016-02-17 18:00:26)

ValidDate satisfies the requirements of Ord
This may be of interest to you, @svozza, given your recent work on various date libraries. :)



Patch:
diff --git a/index.js b/index.js
index 56edd33..f9b22a9 100644
--- a/index.js
+++ b/index.js
@@ -180,11 +180,7 @@
   //  Ord :: TypeClass
   var Ord = $.TypeClass(
     'sanctuary/Ord',
-    function(x) {
-      var type = _type(x);
-      return type === 'Number' && $.ValidNumber.test(x) ||
-             type === 'String';
-    }
+    R.anyPass([$.String.test, $.ValidDate.test, $.ValidNumber.test])
   );
 
   //  Semigroup :: TypeClass
@@ -250,6 +246,7 @@
     $Maybe,
     $.RegexFlags,
     TypeRep,
+    $.ValidDate,
     $.ValidNumber
   ]);
 
@@ -2505,6 +2502,9 @@
   //. > S.min(10, 2)
   //. 2
   //.
+  //. > S.min(new Date('1999-12-31'), new Date('2000-01-01'))
+  //. new Date('1999-12-31')
+  //.
   //. > S.min('10', '2')
   //. '10'
   //. ```
@@ -2528,6 +2528,9 @@
   //. > S.max(10, 2)
   //. 10
   //.
+  //. > S.max(new Date('1999-12-31'), new Date('2000-01-01'))
+  //. new Date('2000-01-01')
+  //.
   //. > S.max('10', '2')
   //. '2'
   //. ```


Test patch:
diff --git a/test/index.js b/test/index.js
index 8f502cd..59319e4 100644
--- a/test/index.js
+++ b/test/index.js
@@ -3717,6 +3717,11 @@ describe('number', function() {
                     errorEq(TypeError,
                             '‘min’ requires ‘a’ to implement Ord; ' +
                             'Number does not'));
+
+      assert.throws(function() { S.min(new Date('XXX')); },
+                    errorEq(TypeError,
+                            '‘min’ requires ‘a’ to implement Ord; ' +
+                            'Date does not'));
     });
 
     it('may be applied to (valid) numbers', function() {
@@ -3728,6 +3733,11 @@ describe('number', function() {
       eq(S.min(-Infinity, Infinity), -Infinity);
     });
 
+    it('may be applied to (valid) dates', function() {
+      eq(S.min(new Date(10), new Date(2)), new Date(2));
+      eq(S.min(new Date(2), new Date(10)), new Date(2));
+    });
+
     it('may be applied to strings', function() {
       eq(S.min('abc', 'xyz'), 'abc');
       eq(S.min('xyz', 'abc'), 'abc');
@@ -3761,6 +3771,11 @@ describe('number', function() {
                     errorEq(TypeError,
                             '‘max’ requires ‘a’ to implement Ord; ' +
                             'Number does not'));
+
+      assert.throws(function() { S.max(new Date('XXX')); },
+                    errorEq(TypeError,
+                            '‘max’ requires ‘a’ to implement Ord; ' +
+                            'Date does not'));
     });
 
     it('may be applied to (valid) numbers', function() {
@@ -3772,6 +3787,11 @@ describe('number', function() {
       eq(S.max(-Infinity, Infinity), Infinity);
     });
 
+    it('may be applied to (valid) dates', function() {
+      eq(S.max(new Date(10), new Date(2)), new Date(10));
+      eq(S.max(new Date(2), new Date(10)), new Date(10));
+    });
+
     it('may be applied to strings', function() {
       eq(S.max('abc', 'xyz'), 'xyz');
       eq(S.max('xyz', 'abc'), 'xyz');
Repository: plaid/sanctuary
Pull request #176 (2016-04-11 05:48:05)

string: add S.trim
See #145


svozza: LGTM.

Patch:
diff --git a/index.js b/index.js
index e2d88d0..6a74cac 100644
--- a/index.js
+++ b/index.js
@@ -2919,6 +2919,20 @@
       [$.String, $.String],
       function(s) { return s.toLowerCase(); });
 
+  //# trim :: String -> String
+  //.
+  //. Strips leading and trailing whitespace characters.
+  //.
+  //. ```javascript
+  //. > S.trim('\t\t foo bar \n')
+  //. 'foo bar'
+  //. ```
+  S.trim =
+  def('trim',
+      {},
+      [$.String, $.String],
+      R.trim);
+
   //# words :: String -> [String]
   //.
   //. Takes a string and returns the list of words the string contains


Test patch:
diff --git a/test/index.js b/test/index.js
index fb19ee4..5927dec 100644
--- a/test/index.js
+++ b/test/index.js
@@ -5553,6 +5553,39 @@ describe('string', function() {
 
   });
 
+  describe('trim', function() {
+
+    it('is a unary function', function() {
+      eq(typeof S.trim, 'function');
+      eq(S.trim.length, 1);
+    });
+
+    it('type checks its arguments', function() {
+      throws(function() { S.trim(/XXX/); },
+             errorEq(TypeError,
+                     'Invalid value\n' +
+                     '\n' +
+                     'trim :: String -> String\n' +
+                     '        ^^^^^^\n' +
+                     '          1\n' +
+                     '\n' +
+                     '1)  /XXX/ :: RegExp\n' +
+                     '\n' +
+                     'The value at position 1 is not a member of ‘String’.\n'));
+    });
+
+    it('strips leading and trailing whitespace characters', function() {
+      eq(S.trim(''), '');
+      eq(S.trim(' '), '');
+      eq(S.trim('x'), 'x');
+      eq(S.trim(' x'), 'x');
+      eq(S.trim('x '), 'x');
+      eq(S.trim(' x '), 'x');
+      eq(S.trim('\n\r\t x \n\r\t x \n\r\t'), 'x \n\r\t x');
+    });
+
+  });
+
   describe('words', function() {
 
     it('is a unary function', function() {