fetch | A window.fetch JavaScript polyfill | Reactive Programming library

 by   github JavaScript Version: v3.6.2 License: MIT

kandi X-RAY | fetch Summary

fetch is a JavaScript library typically used in Programming Style, Reactive Programming, Symfony applications. fetch has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can install using 'npm i whatwg-fetch-strict' or download it from GitHub, npm.
The fetch() function is a Promise-based mechanism for programmatically making web requests in the browser. This project is a polyfill that implements a subset of the standard Fetch specification, enough to make fetch a viable replacement for most uses of XMLHttpRequest in traditional web applications.
    Support
      Quality
        Security
          License
            Reuse
            Support
              Quality
                Security
                  License
                    Reuse

                      kandi-support Support

                        summary
                        fetch has a medium active ecosystem.
                        summary
                        It has 25659 star(s) with 3188 fork(s). There are 635 watchers for this library.
                        summary
                        It had no major release in the last 12 months.
                        summary
                        There are 47 open issues and 579 have been closed. On average issues are closed in 10 days. There are 10 open pull requests and 0 closed requests.
                        summary
                        It has a neutral sentiment in the developer community.
                        summary
                        The latest version of fetch is v3.6.2
                        fetch Support
                          Best in #Reactive Programming
                            Average in #Reactive Programming
                            fetch Support
                              Best in #Reactive Programming
                                Average in #Reactive Programming

                                  kandi-Quality Quality

                                    summary
                                    fetch has 0 bugs and 0 code smells.
                                    fetch Quality
                                      Best in #Reactive Programming
                                        Average in #Reactive Programming
                                        fetch Quality
                                          Best in #Reactive Programming
                                            Average in #Reactive Programming

                                              kandi-Security Security

                                                summary
                                                fetch has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
                                                summary
                                                fetch code analysis shows 0 unresolved vulnerabilities.
                                                summary
                                                There are 0 security hotspots that need review.
                                                fetch Security
                                                  Best in #Reactive Programming
                                                    Average in #Reactive Programming
                                                    fetch Security
                                                      Best in #Reactive Programming
                                                        Average in #Reactive Programming

                                                          kandi-License License

                                                            summary
                                                            fetch is licensed under the MIT License. This license is Permissive.
                                                            summary
                                                            Permissive licenses have the least restrictions, and you can use them in most projects.
                                                            fetch License
                                                              Best in #Reactive Programming
                                                                Average in #Reactive Programming
                                                                fetch License
                                                                  Best in #Reactive Programming
                                                                    Average in #Reactive Programming

                                                                      kandi-Reuse Reuse

                                                                        summary
                                                                        fetch releases are available to install and integrate.
                                                                        summary
                                                                        Deployable package is available in npm.
                                                                        summary
                                                                        Installation instructions, examples and code snippets are available.
                                                                        fetch Reuse
                                                                          Best in #Reactive Programming
                                                                            Average in #Reactive Programming
                                                                            fetch Reuse
                                                                              Best in #Reactive Programming
                                                                                Average in #Reactive Programming
                                                                                  Top functions reviewed by kandi - BETA
                                                                                  kandi has reviewed fetch and discovered the below as its top functions. This is intended to give you an instant insight into fetch implemented functionality, and help decide if they suit your requirements.
                                                                                  • Json object constructor
                                                                                    • Fetch an XML file
                                                                                      • Initialize a new Request .
                                                                                        • Parse raw headers .
                                                                                          • Header Object .
                                                                                            • Generate iterator for the current value
                                                                                              • Initialize a new Response object
                                                                                                • Decodes a form body .
                                                                                                  • Create a reader ready handler
                                                                                                    • Normalizes a header name .
                                                                                                      Get all kandi verified functions for this library.
                                                                                                      Get all kandi verified functions for this library.

                                                                                                      fetch Key Features

                                                                                                      A window.fetch JavaScript polyfill.

                                                                                                      fetch Examples and Code Snippets

                                                                                                      Return a mapper for fetch .
                                                                                                      pythondot imgLines of Code : 32dot imgLicense : Non-SPDX (Apache License 2.0)
                                                                                                      copy iconCopy
                                                                                                      
                                                                                                                                          def for_fetch(fetch): """Creates fetch mapper that handles the structure of `fetch`. The default graph must be the one from which we want to fetch values when this function is called. Args: fetch: An arbitrary fetch structure: singleton, list, tuple, namedtuple, or dict. Returns: An instance of a subclass of `_FetchMapper` that handles the shape. """ if fetch is None: raise TypeError(f'Argument `fetch` = {fetch} has invalid type ' f'"{type(fetch).__name__}". Cannot be None') elif isinstance(fetch, (list, tuple)): # NOTE(touts): This is also the code path for namedtuples. return _ListFetchMapper(fetch) elif isinstance(fetch, collections_abc.Mapping): return _DictFetchMapper(fetch) elif _is_attrs_instance(fetch): return _AttrsFetchMapper(fetch) else: # Look for a handler in the registered expansions. for tensor_type, fetch_fn, _, _ in _REGISTERED_EXPANSIONS: if isinstance(fetch, tensor_type): fetches, contraction_fn = fetch_fn(fetch) return _ElementFetchMapper(fetches, contraction_fn) # Did not find anything. raise TypeError(f'Argument `fetch` = {fetch} has invalid type ' f'"{type(fetch).__name__}"')
                                                                                                      Fetch GitHub info .
                                                                                                      pythondot imgLines of Code : 9dot imgLicense : Permissive (MIT License)
                                                                                                      copy iconCopy
                                                                                                      
                                                                                                                                          def fetch_github_info(auth_token: str) -> dict[Any, Any]: """ Fetch GitHub info of a user using the requests module """ headers = { "Authorization": f"token {auth_token}", "Accept": "application/vnd.github.v3+json", } return requests.get(AUTHENTICATED_USER_ENDPOINT, headers=headers).json()
                                                                                                      Community Discussions

                                                                                                      Trending Discussions on fetch

                                                                                                      Instead change the require of index.js, to a dynamic import() which is available in all CommonJS modules
                                                                                                      chevron right
                                                                                                      Fixing git HTTPS Error: "bad key length" on macOS 12
                                                                                                      chevron right
                                                                                                      Error: require() of ES modules is not supported when importing node-fetch
                                                                                                      chevron right
                                                                                                      EmbeddedKafka failing since Spring Boot 2.6.X : AccessDeniedException: ..\AppData\Local\Temp\spring.kafka*
                                                                                                      chevron right
                                                                                                      require('node-fetch') gives ERR_REQUIRE_ESM
                                                                                                      chevron right
                                                                                                      How to fix the error (TypeError: Cannot assign to read only property 'map' of object '#')
                                                                                                      chevron right
                                                                                                      Chrome 98 Private Network Access problem w/ disabled web security: Request had no target IP address space, yet the resource is in address space local
                                                                                                      chevron right
                                                                                                      ESLint Definition for rule 'import/extensions' was not found
                                                                                                      chevron right
                                                                                                      Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
                                                                                                      chevron right
                                                                                                      Is there any better option to apply pagination without applying OFFSET in SQL Server?
                                                                                                      chevron right

                                                                                                      QUESTION

                                                                                                      Instead change the require of index.js, to a dynamic import() which is available in all CommonJS modules
                                                                                                      Asked 2022-Apr-05 at 06:25

                                                                                                      Trying to work with node/javascript/nfts, I am a noob and followed along a tutorial, but I get this error:

                                                                                                      error [ERR_REQUIRE_ESM]: require() of ES Module [...] is not supported. Instead change the require of index.js [ in my file...]  to a dynamic import() which is available in all CommonJS modules
                                                                                                      

                                                                                                      My understanding is that they've updated the node file, so i need a different code than that in the tutorial, but i don't know which one I'm supposed to change, where and to what. Please be as specific as you can

                                                                                                      const FormData = require('form-data');
                                                                                                      const fetch = require('node-fetch');
                                                                                                      const path = require("path")
                                                                                                      const basePath = process.cwd();
                                                                                                      const fs = require("fs");
                                                                                                      
                                                                                                      fs.readdirSync(`${basePath}/build/images`).foreach(file).forEach(file => {
                                                                                                          const formData = new FormData();
                                                                                                          const fileStream = fs.createReadStream(`${basePath}/build/images/${file}`);
                                                                                                          formData.append('file',fileStream);
                                                                                                      
                                                                                                          let url = 'https://api.nftport.xyz/v0/files';
                                                                                                      
                                                                                                          let options = {
                                                                                                            method: 'POST',
                                                                                                            headers: {
                                                                                                              Authorization: '[...]',
                                                                                                            },
                                                                                                            body: formData
                                                                                                          };
                                                                                                          
                                                                                                          fetch(url, options)
                                                                                                            .then(res => res.json())
                                                                                                            .then(json => {
                                                                                                             const fileName = path.parse(json.file_name).name;
                                                                                                             let rawdata = fs.readFileSync(`${basePath}/build/json/${fileName}.json`);
                                                                                                             let metaData = JSON.parse(rawdata);
                                                                                                      
                                                                                                             metaData.file_url = json.ipfs_url;
                                                                                                      
                                                                                                             fs.writeFileSync(`${basePath}/build/json${fileName}.json`, JSON.stringify(metaData, null, 2));
                                                                                                      
                                                                                                             console.log(`${json.file_name} uploaded & ${fileName}.json updated!`);
                                                                                                            })
                                                                                                            .catch(err => console.error('error:' + err));
                                                                                                      })
                                                                                                      
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2021-Dec-31 at 10:07

                                                                                                      It is because of the node-fetch package. As recent versions of this package only support ESM, you have to downgrade it to an older version node-fetch@2.6.1 or lower.

                                                                                                      npm i node-fetch@2.6.1

                                                                                                      This should solve the issue.

                                                                                                      Source https://stackoverflow.com/questions/70541068

                                                                                                      QUESTION

                                                                                                      Fixing git HTTPS Error: "bad key length" on macOS 12
                                                                                                      Asked 2022-Mar-29 at 17:34

                                                                                                      I am using a company-hosted (Bitbucket) git repository that is accessible via HTTPS. Accessing it (e.g. git fetch) worked using macOS 11 (Big Sur), but broke after an update to macOS 12 Monterey. *

                                                                                                      After the update of macOS to 12 Monterey my previous git setup broke. Now I am getting the following error message:

                                                                                                      $ git fetch
                                                                                                      fatal: unable to access 'https://.../':
                                                                                                      error:06FFF089:digital envelope routines:CRYPTO_internal:bad key length
                                                                                                      

                                                                                                      For what it's worth, using curl does not work either:

                                                                                                      $ curl --insecure -L -v https://...
                                                                                                      *   Trying ...
                                                                                                      * Connected to ... (...) port 443 (#0)
                                                                                                      * ALPN, offering h2
                                                                                                      * ALPN, offering http/1.1
                                                                                                      * successfully set certificate verify locations:
                                                                                                      *  CAfile: /etc/ssl/cert.pem
                                                                                                      *  CApath: none
                                                                                                      * TLSv1.2 (OUT), TLS handshake, Client hello (1):
                                                                                                      * TLSv1.2 (IN), TLS handshake, Server hello (2):
                                                                                                      * TLSv1.2 (IN), TLS handshake, Certificate (11):
                                                                                                      * TLSv1.2 (IN), TLS handshake, Server key exchange (12):
                                                                                                      * TLSv1.2 (IN), TLS handshake, Server finished (14):
                                                                                                      * TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
                                                                                                      * TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
                                                                                                      * TLSv1.2 (OUT), TLS handshake, Finished (20):
                                                                                                      * error:06FFF089:digital envelope routines:CRYPTO_internal:bad key length
                                                                                                      * Closing connection 0
                                                                                                      curl: (35) error:06FFF089:digital envelope routines:CRYPTO_internal:bad key length
                                                                                                      

                                                                                                      Accessing the same HTTPS-source via Safari or Firefox works.

                                                                                                      As far as I understand, the underlying error "bad key length" error is coming from OpenSSL/LibreSSL, this would be consistent with both git and curl failing after an OS upgrade.

                                                                                                      This is the output from openssl:

                                                                                                      $ openssl s_client -servername ... -connect ...:443
                                                                                                      CONNECTED(00000005)
                                                                                                      depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root G2
                                                                                                      verify return:1
                                                                                                      depth=1 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = Thawte TLS RSA CA G1
                                                                                                      verify return:1
                                                                                                      depth=0 ...
                                                                                                      4593010348:error:06FFF089:digital envelope routines:CRYPTO_internal:bad key length:
                                                                                                      /System/Volumes/Data/SWE/macOS/BuildRoots/b8ff8433dc/Library/Caches/com.apple.xbs
                                                                                                      /Sources/libressl/libressl-75/libressl-2.8/crypto/apple/hmac/hmac.c:188:
                                                                                                      ---
                                                                                                      Certificate chain
                                                                                                       ...
                                                                                                      ---
                                                                                                      No client certificate CA names sent
                                                                                                      Server Temp Key: DH, 2048 bits
                                                                                                      ---
                                                                                                      SSL handshake has read 4105 bytes and written 318 bytes
                                                                                                      ---
                                                                                                      New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-GCM-SHA384
                                                                                                      Server public key is 4096 bit
                                                                                                      Secure Renegotiation IS supported
                                                                                                      Compression: NONE
                                                                                                      Expansion: NONE
                                                                                                      No ALPN negotiated
                                                                                                      SSL-Session:
                                                                                                          Protocol  : TLSv1.2
                                                                                                          Cipher    : DHE-RSA-AES256-GCM-SHA384
                                                                                                          Session-ID: 1FA062DC9EEC9A310FF8231F1EB11A3BD6E0778F7AB6E98EAD1020A44CF1A407
                                                                                                          Session-ID-ctx:
                                                                                                          Master-Key:
                                                                                                          Start Time: 1635319904
                                                                                                          Timeout   : 7200 (sec)
                                                                                                          Verify return code: 0 (ok)
                                                                                                      ---
                                                                                                      
                                                                                                      

                                                                                                      I did try to add the server's certificates into a custom pem file and setting http.sslCAInfo, but that didn't work. As a workaround, I am currently using a proxy that decrypts/re-encrypts HTTPS traffic.

                                                                                                      How do I configure git (or all LibreSSL users) to accept the server's certificate?

                                                                                                      ANSWER

                                                                                                      Answered 2021-Nov-02 at 07:12

                                                                                                      Unfortunately I can't provide you with a fix, but I've found a workaround for that exact same problem (company-hosted bitbucket resulting in exact same error). I also don't know exactly why the problem occurs, but my best guess would be that the libressl library shipped with Monterey has some sort of problem with specific (?TLSv1.3) certs. This guess is because the brew-installed openssl v1.1 and v3 don't throw that error when executed with /opt/homebrew/opt/openssl/bin/openssl s_client -connect ...:443

                                                                                                      To get around that error, I've built git from source built against different openssl and curl implementations:

                                                                                                      1. install autoconf, openssl and curl with brew (I think you can select the openssl lib you like, i.e. v1.1 or v3, I chose v3)
                                                                                                      2. clone git version you like, i.e. git clone --branch v2.33.1 https://github.com/git/git.git
                                                                                                      3. cd git
                                                                                                      4. make configure (that is why autoconf is needed)
                                                                                                      5. execute LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib -L/opt/homebrew/opt/curl/lib" CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include -I/opt/homebrew/opt/curl/include" ./configure --prefix=$HOME/git (here LDFLAGS and CPPFLAGS include the libs git will be built against, the right flags are emitted by brew on install success of curl and openssl; --prefix is the install directory of git, defaults to /usr/local but can be changed)
                                                                                                      6. make install
                                                                                                      7. ensure to add the install directory's subfolder /bin to the front of your $PATH to "override" the default git shipped by Monterey
                                                                                                      8. restart terminal
                                                                                                      9. check that git version shows the new version

                                                                                                      This should help for now, but as I already said, this is only a workaround, hopefully Apple fixes their libressl fork ASAP.

                                                                                                      Source https://stackoverflow.com/questions/69734654

                                                                                                      QUESTION

                                                                                                      Error: require() of ES modules is not supported when importing node-fetch
                                                                                                      Asked 2022-Mar-28 at 07:04

                                                                                                      I'm creating a program to analyze security camera streams and got stuck on the very first line. At the moment my .js file has nothing but the import of node-fetch and it gives me an error message. What am I doing wrong?

                                                                                                      Running Ubuntu 20.04.2 LTS in Windows Subsystem for Linux.

                                                                                                      Node version:

                                                                                                      user@MYLLYTIN:~/CAMSERVER$ node -v
                                                                                                      v14.17.6
                                                                                                      

                                                                                                      node-fetch package version:

                                                                                                      user@MYLLYTIN:~/CAMSERVER$ npm v node-fetch
                                                                                                      
                                                                                                      node-fetch@3.0.0 | MIT | deps: 2 | versions: 63
                                                                                                      A light-weight module that brings Fetch API to node.js
                                                                                                      https://github.com/node-fetch/node-fetch
                                                                                                      
                                                                                                      keywords: fetch, http, promise, request, curl, wget, xhr, whatwg
                                                                                                      
                                                                                                      dist
                                                                                                      .tarball: https://registry.npmjs.org/node-fetch/-/node-fetch-3.0.0.tgz
                                                                                                      .shasum: 79da7146a520036f2c5f644e4a26095f17e411ea
                                                                                                      .integrity: sha512-bKMI+C7/T/SPU1lKnbQbwxptpCrG9ashG+VkytmXCPZyuM9jB6VU+hY0oi4lC8LxTtAeWdckNCTa3nrGsAdA3Q==
                                                                                                      .unpackedSize: 75.9 kB
                                                                                                      
                                                                                                      dependencies:
                                                                                                      data-uri-to-buffer: ^3.0.1 fetch-blob: ^3.1.2         
                                                                                                      
                                                                                                      maintainers:
                                                                                                      - endless 
                                                                                                      - bitinn 
                                                                                                      - timothygu 
                                                                                                      - akepinski 
                                                                                                      
                                                                                                      dist-tags:
                                                                                                      latest: 3.0.0        next: 3.0.0-beta.10  
                                                                                                      
                                                                                                      published 3 days ago by endless 
                                                                                                      

                                                                                                      esm package version:

                                                                                                      user@MYLLYTIN:~/CAMSERVER$ npm v esm
                                                                                                      
                                                                                                      esm@3.2.25 | MIT | deps: none | versions: 140
                                                                                                      Tomorrow's ECMAScript modules today!
                                                                                                      https://github.com/standard-things/esm#readme
                                                                                                      
                                                                                                      keywords: commonjs, ecmascript, export, import, modules, node, require
                                                                                                      
                                                                                                      dist
                                                                                                      .tarball: https://registry.npmjs.org/esm/-/esm-3.2.25.tgz
                                                                                                      .shasum: 342c18c29d56157688ba5ce31f8431fbb795cc10
                                                                                                      .integrity: sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==
                                                                                                      .unpackedSize: 308.6 kB
                                                                                                      
                                                                                                      maintainers:
                                                                                                      - jdalton 
                                                                                                      
                                                                                                      dist-tags:
                                                                                                      latest: 3.2.25  
                                                                                                      
                                                                                                      published over a year ago by jdalton 
                                                                                                      

                                                                                                      Contents of the .js file (literally nothing but the import):

                                                                                                      user@MYLLYTIN:~/CAMSERVER$ cat server.js 
                                                                                                      import fetch from "node-fetch";
                                                                                                      

                                                                                                      Result:

                                                                                                      user@MYLLYTIN:~/CAMSERVER$ node -r esm server.js 
                                                                                                      /home/user/CAMSERVER/node_modules/node-fetch/src/index.js:1
                                                                                                      Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/user/CAMSERVER/node_modules/node-fetch/src/index.js
                                                                                                      require() of ES modules is not supported.
                                                                                                      require() of /home/user/CAMSERVER/node_modules/node-fetch/src/index.js from /home/user/CAMSERVER/server.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
                                                                                                      Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/user/CAMSERVER/node_modules/node-fetch/package.json.
                                                                                                      
                                                                                                          at Object.Module._extensions..js (internal/modules/cjs/loader.js:1089:13) {
                                                                                                        code: 'ERR_REQUIRE_ESM'
                                                                                                      }
                                                                                                      user@MYLLYTIN:~/CAMSERVER$ 
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2022-Feb-25 at 00:00

                                                                                                      Use ESM syntax, also use one of these methods before running the file.

                                                                                                      1. specify "type":"module" in package.json
                                                                                                      2. Or use this flag --input-type=module when running the file
                                                                                                      3. Or use .mjs file extension

                                                                                                      Source https://stackoverflow.com/questions/69041454

                                                                                                      QUESTION

                                                                                                      EmbeddedKafka failing since Spring Boot 2.6.X : AccessDeniedException: ..\AppData\Local\Temp\spring.kafka*
                                                                                                      Asked 2022-Mar-25 at 12:39

                                                                                                      e: this has been fixed through Spring Boot 2.6.5 (see https://github.com/spring-projects/spring-boot/issues/30243)

                                                                                                      Since upgrading to Spring Boot 2.6.X (in my case: 2.6.1), I have multiple projects that now have failing unit-tests on Windows that cannot start EmbeddedKafka, that do run with Linux

                                                                                                      There is multiple errors, but this is the first one thrown

                                                                                                      ...
                                                                                                        .   ____          _            __ _ _
                                                                                                       /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
                                                                                                      ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
                                                                                                       \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
                                                                                                        '  |____| .__|_| |_|_| |_\__, | / / / /
                                                                                                       =========|_|==============|___/=/_/_/_/
                                                                                                       :: Spring Boot ::                (v2.6.1)
                                                                                                      
                                                                                                      2021-12-09 16:15:00.300  INFO 13864 --- [           main] k.utils.Log4jControllerRegistration$     : Registered kafka:type=kafka.Log4jController MBean
                                                                                                      2021-12-09 16:15:00.420  INFO 13864 --- [           main] o.a.zookeeper.server.ZooKeeperServer     : 
                                                                                                      2021-12-09 16:15:00.420  INFO 13864 --- [           main] o.a.zookeeper.server.ZooKeeperServer     :   ______                  _                                          
                                                                                                      2021-12-09 16:15:00.420  INFO 13864 --- [           main] o.a.zookeeper.server.ZooKeeperServer     :  |___  /                 | |                                         
                                                                                                      2021-12-09 16:15:00.420  INFO 13864 --- [           main] o.a.zookeeper.server.ZooKeeperServer     :     / /    ___     ___   | | __   ___    ___   _ __     ___   _ __   
                                                                                                      2021-12-09 16:15:00.420  INFO 13864 --- [           main] o.a.zookeeper.server.ZooKeeperServer     :    / /    / _ \   / _ \  | |/ /  / _ \  / _ \ | '_ \   / _ \ | '__|
                                                                                                      2021-12-09 16:15:00.420  INFO 13864 --- [           main] o.a.zookeeper.server.ZooKeeperServer     :   / /__  | (_) | | (_) | |   <  |  __/ |  __/ | |_) | |  __/ | |    
                                                                                                      2021-12-09 16:15:00.420  INFO 13864 --- [           main] o.a.zookeeper.server.ZooKeeperServer     :  /_____|  \___/   \___/  |_|\_\  \___|  \___| | .__/   \___| |_|
                                                                                                      2021-12-09 16:15:00.420  INFO 13864 --- [           main] o.a.zookeeper.server.ZooKeeperServer     :                                               | |                     
                                                                                                      2021-12-09 16:15:00.420  INFO 13864 --- [           main] o.a.zookeeper.server.ZooKeeperServer     :                                               |_|                     
                                                                                                      2021-12-09 16:15:00.420  INFO 13864 --- [           main] o.a.zookeeper.server.ZooKeeperServer     : 
                                                                                                      2021-12-09 16:15:00.422  INFO 13864 --- [           main] o.a.zookeeper.server.ZooKeeperServer     : Server environment:zookeeper.version=3.6.3--6401e4ad2087061bc6b9f80dec2d69f2e3c8660a, built on 04/08/2021 16:35 GMT
                                                                                                      2021-12-09 16:15:00.422  INFO 13864 --- [           main] o.a.zookeeper.server.ZooKeeperServer     : Server environment:host.name=host.docker.internal
                                                                                                      2021-12-09 16:15:00.422  INFO 13864 --- [           main] o.a.zookeeper.server.ZooKeeperServer     : Server environment:java.version=11.0.11
                                                                                                      2021-12-09 16:15:00.422  INFO 13864 --- [           main] o.a.zookeeper.server.ZooKeeperServer     : Server environment:java.vendor=AdoptOpenJDK
                                                                                                      ...
                                                                                                      2021-12-09 16:15:01.015  INFO 13864 --- [nelReaper-Fetch] lientQuotaManager$ThrottledChannelReaper : [ThrottledChannelReaper-Fetch]: Starting
                                                                                                      2021-12-09 16:15:01.015  INFO 13864 --- [lReaper-Produce] lientQuotaManager$ThrottledChannelReaper : [ThrottledChannelReaper-Produce]: Starting
                                                                                                      2021-12-09 16:15:01.016  INFO 13864 --- [lReaper-Request] lientQuotaManager$ThrottledChannelReaper : [ThrottledChannelReaper-Request]: Starting
                                                                                                      2021-12-09 16:15:01.017  INFO 13864 --- [trollerMutation] lientQuotaManager$ThrottledChannelReaper : [ThrottledChannelReaper-ControllerMutation]: Starting
                                                                                                      2021-12-09 16:15:01.037  INFO 13864 --- [           main] kafka.log.LogManager                     : Loading logs from log dirs ArraySeq(C:\Users\ddrop\AppData\Local\Temp\spring.kafka.bf8e2b62-a1f2-4092-b292-a15e35bd31ad18378079390566696446)
                                                                                                      2021-12-09 16:15:01.040  INFO 13864 --- [           main] kafka.log.LogManager                     : Attempting recovery for all logs in C:\Users\ddrop\AppData\Local\Temp\spring.kafka.bf8e2b62-a1f2-4092-b292-a15e35bd31ad18378079390566696446 since no clean shutdown file was found
                                                                                                      2021-12-09 16:15:01.043  INFO 13864 --- [           main] kafka.log.LogManager                     : Loaded 0 logs in 6ms.
                                                                                                      2021-12-09 16:15:01.043  INFO 13864 --- [           main] kafka.log.LogManager                     : Starting log cleanup with a period of 300000 ms.
                                                                                                      2021-12-09 16:15:01.045  INFO 13864 --- [           main] kafka.log.LogManager                     : Starting log flusher with a default period of 9223372036854775807 ms.
                                                                                                      2021-12-09 16:15:01.052  INFO 13864 --- [           main] kafka.log.LogCleaner                     : Starting the log cleaner
                                                                                                      2021-12-09 16:15:01.059  INFO 13864 --- [leaner-thread-0] kafka.log.LogCleaner                     : [kafka-log-cleaner-thread-0]: Starting
                                                                                                      2021-12-09 16:15:01.224  INFO 13864 --- [name=forwarding] k.s.BrokerToControllerRequestThread      : [BrokerToControllerChannelManager broker=0 name=forwarding]: Starting
                                                                                                      2021-12-09 16:15:01.325  INFO 13864 --- [           main] kafka.network.ConnectionQuotas           : Updated connection-accept-rate max connection creation rate to 2147483647
                                                                                                      2021-12-09 16:15:01.327  INFO 13864 --- [           main] kafka.network.Acceptor                   : Awaiting socket connections on localhost:63919.
                                                                                                      2021-12-09 16:15:01.345  INFO 13864 --- [           main] kafka.network.SocketServer               : [SocketServer listenerType=ZK_BROKER, nodeId=0] Created data-plane acceptor and processors for endpoint : ListenerName(PLAINTEXT)
                                                                                                      2021-12-09 16:15:01.350  INFO 13864 --- [0 name=alterIsr] k.s.BrokerToControllerRequestThread      : [BrokerToControllerChannelManager broker=0 name=alterIsr]: Starting
                                                                                                      2021-12-09 16:15:01.364  INFO 13864 --- [eaper-0-Produce] perationPurgatory$ExpiredOperationReaper : [ExpirationReaper-0-Produce]: Starting
                                                                                                      2021-12-09 16:15:01.364  INFO 13864 --- [nReaper-0-Fetch] perationPurgatory$ExpiredOperationReaper : [ExpirationReaper-0-Fetch]: Starting
                                                                                                      2021-12-09 16:15:01.365  INFO 13864 --- [0-DeleteRecords] perationPurgatory$ExpiredOperationReaper : [ExpirationReaper-0-DeleteRecords]: Starting
                                                                                                      2021-12-09 16:15:01.365  INFO 13864 --- [r-0-ElectLeader] perationPurgatory$ExpiredOperationReaper : [ExpirationReaper-0-ElectLeader]: Starting
                                                                                                      2021-12-09 16:15:01.374  INFO 13864 --- [rFailureHandler] k.s.ReplicaManager$LogDirFailureHandler  : [LogDirFailureHandler]: Starting
                                                                                                      2021-12-09 16:15:01.390  INFO 13864 --- [           main] kafka.zk.KafkaZkClient                   : Creating /brokers/ids/0 (is it secure? false)
                                                                                                      2021-12-09 16:15:01.400  INFO 13864 --- [           main] kafka.zk.KafkaZkClient                   : Stat of the created znode at /brokers/ids/0 is: 25,25,1639062901396,1639062901396,1,0,0,72059919267528704,204,0,25
                                                                                                      
                                                                                                      2021-12-09 16:15:01.400  INFO 13864 --- [           main] kafka.zk.KafkaZkClient                   : Registered broker 0 at path /brokers/ids/0 with addresses: PLAINTEXT://localhost:63919, czxid (broker epoch): 25
                                                                                                      2021-12-09 16:15:01.410 ERROR 13864 --- [           main] kafka.server.BrokerMetadataCheckpoint    : Failed to write meta.properties due to
                                                                                                      
                                                                                                      java.nio.file.AccessDeniedException: C:\Users\ddrop\AppData\Local\Temp\spring.kafka.bf8e2b62-a1f2-4092-b292-a15e35bd31ad18378079390566696446
                                                                                                          at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89) ~[na:na]
                                                                                                          at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103) ~[na:na]
                                                                                                          at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108) ~[na:na]
                                                                                                      
                                                                                                      package com.example.demo;
                                                                                                      
                                                                                                      import org.junit.jupiter.api.Test;
                                                                                                      import org.springframework.boot.test.context.SpringBootTest;
                                                                                                      import org.springframework.kafka.test.context.EmbeddedKafka;
                                                                                                      
                                                                                                      @SpringBootTest
                                                                                                      @EmbeddedKafka
                                                                                                      class ApplicationTest {
                                                                                                      
                                                                                                          @Test
                                                                                                          void run() {
                                                                                                              int i = 1 + 1; // just a line of code to set a debug-point
                                                                                                          }
                                                                                                      }
                                                                                                      

                                                                                                      I do not have this error when pinning kafka.version to 2.8.1 in pom.xml's properties.

                                                                                                      It seems like the cause is in Kafka itself, but I have a hard time figuring out if it is spring-kafka intitializing Kafka via EmbeddedKafka incorrectly or if Kafka itself is the culrit here.

                                                                                                      Anyone has an idea? Am I missing a test-parameter to set?

                                                                                                      ANSWER

                                                                                                      Answered 2021-Dec-09 at 15:51

                                                                                                      Known bug on the Apache Kafka side. Nothing to do from Spring perspective. See more info here: https://github.com/spring-projects/spring-kafka/discussions/2027. And here: https://issues.apache.org/jira/browse/KAFKA-13391

                                                                                                      You need to wait until Apache Kafka 3.0.1 or don't use embedded Kafka and just rely on the Testcontainers, for example, or fully external Apache Kafka broker.

                                                                                                      Source https://stackoverflow.com/questions/70292425

                                                                                                      QUESTION

                                                                                                      require('node-fetch') gives ERR_REQUIRE_ESM
                                                                                                      Asked 2022-Mar-16 at 11:46

                                                                                                      I just use

                                                                                                      const fetch = require('node-fetch')
                                                                                                      

                                                                                                      And I get

                                                                                                      Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\Alex\Desktop\rollbot\node_modules\node-fetch\src\index.js from C:\Users\Alex\Desktop\rollbot\index.js not supported.
                                                                                                      Instead change the require of C:\Users\Alex\Desktop\rollbot\node_modules\node-fetch\src\index.js in C:\Users\Alex\Desktop\rollbot\index.js to a 
                                                                                                      dynamic import() which is available in all CommonJS modules.
                                                                                                      {
                                                                                                        code: 'ERR_REQUIRE_ESM'
                                                                                                      }
                                                                                                      

                                                                                                      All my other packages work, just node-fetch does this. What should I do in order to use node-fetch?

                                                                                                      ANSWER

                                                                                                      Answered 2021-Sep-07 at 11:53

                                                                                                      From the node-fetch package readme:

                                                                                                      node-fetch is an ESM-only module - you are not able to import it with require. We recommend you stay on v2 which is built with CommonJS unless you use ESM yourself. We will continue to publish critical bug fixes for it.

                                                                                                      If you want to require it, then downgrade to v2.

                                                                                                      The other option you have is to use async import('node-fetch').then(...)

                                                                                                      Source https://stackoverflow.com/questions/69087292

                                                                                                      QUESTION

                                                                                                      How to fix the error (TypeError: Cannot assign to read only property 'map' of object '#')
                                                                                                      Asked 2022-Mar-05 at 09:40

                                                                                                      I am sending my data to MongoDB via Mongoose. Now, during the fetch of API route for it, an error is thrown.

                                                                                                      Code

                                                                                                      const addChoice = async (e) => {
                                                                                                          try {
                                                                                                              e.preventDefault();
                                                                                                              const res = await fetch("/api/sendChoice", {
                                                                                                                  method: "POST",
                                                                                                                  headers: {
                                                                                                                      "Content-Type": "application/json",
                                                                                                                  },
                                                                                                                  body: JSON.stringify({
                                                                                                                      choiceSeq: choice,
                                                                                                                      checkSubmit: true,
                                                                                                                  }),
                                                                                                              });
                                                                                                              console.log(res);
                                                                                                              router.push("/home");
                                                                                                          } catch (error) {
                                                                                                              console.log(error);
                                                                                                          }
                                                                                                      };
                                                                                                      

                                                                                                      The error is happening at const res = await fetch("/api/sendChoice" ,{

                                                                                                      In terminal server the error

                                                                                                      error - TypeError: Cannot assign to read only property 'map' of object '#'

                                                                                                      In the inspect element the error is as

                                                                                                      I can't find anything related to fix this issue, I don't even understand what the error means to try to resolve it myself.

                                                                                                      Some other related code from my project:

                                                                                                      api/sendChoice

                                                                                                      import { getSession } from "next-auth/client";
                                                                                                      import dbConnect from "../../helpers/dbConnect";
                                                                                                      import Choice from "../../models/Choice";
                                                                                                      
                                                                                                      export default async function sendChoice(req, res) {
                                                                                                          try {
                                                                                                              const session = await getSession({ req });
                                                                                                              await dbConnect();
                                                                                                              if (!session) {
                                                                                                                  res.status(401).send("You are not signed in");
                                                                                                                  return;
                                                                                                              }
                                                                                                              if (req.method === "POST") {
                                                                                                                  console.log(req.body);
                                                                                                                  const { choiceSeq, checkSubmit } = req.body;
                                                                                                                  console.log(choiceSeq, checkSubmit);
                                                                                                                  const userId = session.user.id;
                                                                                                                  const nameP = session.user.name;
                                                                                                                  const choice = new Choice({
                                                                                                                      user: userId,
                                                                                                                      name: nameP,
                                                                                                                      choiceSeq,
                                                                                                                      checkSubmit,
                                                                                                                  });
                                                                                                                  await choice.save();
                                                                                                                  res.status(200).send("Choice saved");
                                                                                                              } else {
                                                                                                                  res.status(400).send("Bad request");
                                                                                                              }
                                                                                                          }
                                                                                                          catch (error) {
                                                                                                              console.log(error);
                                                                                                          }
                                                                                                      }
                                                                                                      

                                                                                                      The MongoDB schema

                                                                                                      import mongoose, { Schema } from 'mongoose';
                                                                                                      
                                                                                                      const ChoiceSchema = new Schema({
                                                                                                          user: {
                                                                                                              type: Schema.Types.ObjectId,
                                                                                                              ref: 'User',
                                                                                                          },
                                                                                                          name: {
                                                                                                              type: String,
                                                                                                          },
                                                                                                          choiceSeq: {
                                                                                                              type: Array,
                                                                                                              default: [],
                                                                                                          },
                                                                                                          checkSubmit: {
                                                                                                              type: Boolean,
                                                                                                          }
                                                                                                      });
                                                                                                      
                                                                                                      mongoose.models = {};
                                                                                                      
                                                                                                      export default mongoose.model('Choice', ChoiceSchema);
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2022-Feb-11 at 00:32

                                                                                                      This issue occured recently and apparently its happening with latest version of node.

                                                                                                      issue link

                                                                                                      So you can change the version of node to older version and it will be fixed. I am using node version v14.19.0

                                                                                                      Source https://stackoverflow.com/questions/71073107

                                                                                                      QUESTION

                                                                                                      Chrome 98 Private Network Access problem w/ disabled web security: Request had no target IP address space, yet the resource is in address space local
                                                                                                      Asked 2022-Feb-25 at 16:03

                                                                                                      We have a test environment on a public site. There we use --disable-web-security flag on chrome for the testers to bypass CORS errors for public service calls during manual test phase. And also we have localhost requests on the agent machine. However today with Chrome 98 update we started struggling with the network requests targeting localhost.

                                                                                                      The error we get is for the localhost requests from a public site:
                                                                                                      Access to XMLHttpRequest at 'https://localhost:3030/static/first.qjson' from origin 'https://....com' has been blocked by CORS policy: Request had no target IP address space, yet the resource is in address space `local`.

                                                                                                      The site on localhost is configured to return Access-Control-Allow-* CORS headers including "Access-Control-Allow-Private-Network: true".

                                                                                                      And also I do not see any preflight request. Just one GET request with CORS error on it.

                                                                                                      We suspect this might be a side effect caused when you disable web security by --disable-web-security. It might be preventing obtaining of the target IP address space. Our assumption is based on the CORS preflight section on https://wicg.github.io/private-network-access/

                                                                                                      3.1.2. CORS preflight
                                                                                                      The HTTP fetch algorithm should be adjusted to ensure that a preflight is triggered for all private network requests initiated from secure contexts.

                                                                                                      The main issue here is again that the response’s IP address space is not known until a connection is obtained in HTTP-network fetch, which is layered under CORS-preflight fetch.

                                                                                                      So does anyone know any workaround for Private Network Access with --disable-web-security flag ? Or maybe we are missing something. Thanks for the help.

                                                                                                      ANSWER

                                                                                                      Answered 2022-Feb-09 at 04:20

                                                                                                      Below Steps can help to solve issue in chrome 98, for other browser like edge you need to do similar like chrome.

                                                                                                      For MAC
                                                                                                      • Requestly with chrome version 98. You need to follow following steps :- Run this command on terminal

                                                                                                        defaults write com.google.Chrome InsecurePrivateNetworkRequestsAllowed -bool true

                                                                                                      • Restart your Browser, Not work then restart your machine

                                                                                                      For WINDOWS
                                                                                                      • Run 'regedit' to open windows registry (If permission issue came then run that command with Admin command prompt)
                                                                                                      • Go to Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome
                                                                                                      • Create new DWORD value with "InsecurePrivateNetworkRequestsAllowed" Name
                                                                                                      • Change Value to "1"
                                                                                                      • Restart your Browser

                                                                                                      Source https://stackoverflow.com/questions/71018461

                                                                                                      QUESTION

                                                                                                      ESLint Definition for rule 'import/extensions' was not found
                                                                                                      Asked 2022-Feb-14 at 08:36

                                                                                                      I'm getting the following two errors on all TypeScript files using ESLint in VS Code:

                                                                                                      Definition for rule 'import/extensions' was not found.eslint(import/extensions)
                                                                                                      Definition for rule 'import/no-extraneous-dependencies' was not found.eslint(import/no-extraneous-dependencies)
                                                                                                      

                                                                                                      A screenshot from VSC Problems pane:

                                                                                                      Note on possible duplicates

                                                                                                      There are many similar questions about different modules and even some about the import/extensions, but none of the suggested solutions help. I've tried them all. I also tried every single solution posted in every single thread suggested by Stack Overflow while typing this question.

                                                                                                      Here is my .eslintrc.json:

                                                                                                      {
                                                                                                        "env": {
                                                                                                            "es2021": true,
                                                                                                            "node": true
                                                                                                        },
                                                                                                        "extends": [
                                                                                                            "airbnb-typescript/base",
                                                                                                            "plugin:@typescript-eslint/recommended"
                                                                                                        ],
                                                                                                        "parser": "@typescript-eslint/parser",
                                                                                                        "parserOptions": {
                                                                                                            "ecmaVersion": 12,
                                                                                                            "sourceType": "module",
                                                                                                            "project": "./tsconfig.json"
                                                                                                        },
                                                                                                        "plugins": [
                                                                                                            "@typescript-eslint"
                                                                                                        ],
                                                                                                        "rules": {
                                                                                                            "@typescript-eslint/no-use-before-define": "off"
                                                                                                        }
                                                                                                      }
                                                                                                      

                                                                                                      package.json:

                                                                                                      {
                                                                                                        "name": "graph-userdata-gateway",
                                                                                                        "version": "1.0.0",
                                                                                                        "description": "Gateway for PowerApps Microsoft Graph API custom connector to query user data with application permissions.",
                                                                                                        "main": "src/index.js",
                                                                                                        "scripts": {
                                                                                                          "test": "echo \"Error: no test specified\" && exit 1"
                                                                                                        },
                                                                                                        "repository": {
                                                                                                          "type": "git",
                                                                                                          "url": "git@gitlab.yobitti.fi:powerapps/graph-userdata-gateway.git"
                                                                                                        },
                                                                                                        "author": "Benjamin Pettinen / YO-bitti Oy",
                                                                                                        "license": "UNLICENSED",
                                                                                                        "dependencies": {
                                                                                                          "@microsoft/microsoft-graph-client": "^3.0.0",
                                                                                                          "dedent": "^0.7.0",
                                                                                                          "express": "^4.17.1",
                                                                                                          "isomorphic-fetch": "^3.0.0",
                                                                                                          "md5": "^2.3.0",
                                                                                                          "node-fetch": "^2.6.1"
                                                                                                        },
                                                                                                        "devDependencies": {
                                                                                                          "@types/dedent": "^0.7.0",
                                                                                                          "@types/express": "^4.17.13",
                                                                                                          "@types/isomorphic-fetch": "0.0.35",
                                                                                                          "@types/md5": "^2.3.1",
                                                                                                          "@types/node-fetch": "^2.5.12",
                                                                                                          "@typescript-eslint/eslint-plugin": "^4.29.2",
                                                                                                          "@typescript-eslint/parser": "^4.29.2",
                                                                                                          "eslint": "^7.32.0",
                                                                                                          "eslint-config-airbnb-base": "^14.2.1",
                                                                                                          "eslint-config-airbnb-typescript": "^13.0.0",
                                                                                                          "eslint-plugin-import": "^2.24.1",
                                                                                                          "typescript": "^4.3.5"
                                                                                                        }
                                                                                                      }
                                                                                                      

                                                                                                      tsconfig.json

                                                                                                      {
                                                                                                        "compilerOptions": {
                                                                                                          "target": "ES6",
                                                                                                          "module": "CommonJS",
                                                                                                          "esModuleInterop": true,
                                                                                                          "noImplicitAny": true,
                                                                                                          "moduleResolution": "Node",
                                                                                                          "outDir": "dist",
                                                                                                          "sourceMap": true
                                                                                                        }
                                                                                                      }
                                                                                                      

                                                                                                      I've tried deleting the whole node_mobules and re-running npm install as well as played with the extends in the .eslintrc.json. If I remove airbnb-typescript/base the error disappears, but I lose the Airbnb style from ESLint. Using airbnb-base instead works, but then ESLint complains about Missing file extension for abc.ts and Unable to resolve path to module abc. I have also multiple time restarted VSC and the ESLint server.

                                                                                                      ANSWER

                                                                                                      Answered 2021-Dec-14 at 12:09

                                                                                                      You missed adding this in your eslint.json file.

                                                                                                      "plugins": ["import"],
                                                                                                      

                                                                                                      Or,

                                                                                                      "extends": ["plugin:import/recommended"]
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/68878189

                                                                                                      QUESTION

                                                                                                      Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
                                                                                                      Asked 2022-Feb-03 at 22:08

                                                                                                      I'm trying to make a Discord bot that just says if someone is online on the game.

                                                                                                      However I keep getting this message:

                                                                                                      [ERR_REQUIRE_ESM]: require() of ES Module from not supported. Instead change the require of index.js in... to a dynamic import() which is available in all CommonJS modules.

                                                                                                      This is my code:

                                                                                                          module.exports = {
                                                                                                              name: 'username',
                                                                                                              description: "this is the username command",
                                                                                                              async execute(message, args) {
                                                                                                      
                                                                                                                  const fetch = require('node-fetch');
                                                                                                      
                                                                                                                  if (args.length !== 1) {
                                                                                                                      return message.channel.send("invalid username wtf")
                                                                                                                  }
                                                                                                      
                                                                                                                  const ign = args[0]
                                                                                                      
                                                                                                                  if (ign.length > 16 || ign.length < 3) {
                                                                                                                      return message.channel.send("invalid username wtf")
                                                                                                                  }
                                                                                                      
                                                                                                                  const uuid = await fetch(`https://api.mojang.com/users/profiles/minecraft/${ign}`).then(data => data.json()).then(data => data.id).catch(err => message.channel.send("error wtf"));
                                                                                                                  const onlineInfo = await fetch(`https://api.hypixel.net/status?key=${john}&uuid=${uuid}`).then(data => data.json());
                                                                                                      
                                                                                                                  if (uuid.length !== 32) {
                                                                                                                      return;
                                                                                                                  }
                                                                                                      
                                                                                                                  if (onlineinfo.success) {
                                                                                                                      if (onlineinfo.session.online) {
                                                                                                                          message.channel.send("they are online")
                                                                                                                      }
                                                                                                                      else {
                                                                                                                          message.channel.send("they are offline")
                                                                                                                      }
                                                                                                                  }
                                                                                                                  else {
                                                                                                                      message.channel.send("hypixel api bad wtf")
                                                                                                                  }
                                                                                                              }
                                                                                                          }
                                                                                                      

                                                                                                      This is my package.json file:

                                                                                                      {
                                                                                                          "name": "discordbot",
                                                                                                          "version": "1.0.0",
                                                                                                          "main": "main.js",
                                                                                                          "scripts": {
                                                                                                              "test": "echo \"Error: no test specified\" && exit 1",
                                                                                                              "start": "node main.js"
                                                                                                          },
                                                                                                          "author": "",
                                                                                                          "license": "ISC",
                                                                                                          "description": "",
                                                                                                          "dependencies": {
                                                                                                              "discord.js": "^13.0.1",
                                                                                                              "node-fetch": "^3.0.0"
                                                                                                          }
                                                                                                      }
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2021-Sep-07 at 06:38

                                                                                                      node-fetch v3 recently stopped support for the require way of importing it in favor of ES Modules. You'll need to use ESM imports now, like:

                                                                                                      import fetch from "node-fetch";
                                                                                                      

                                                                                                      at the top of your file.

                                                                                                      Source https://stackoverflow.com/questions/69081410

                                                                                                      QUESTION

                                                                                                      Is there any better option to apply pagination without applying OFFSET in SQL Server?
                                                                                                      Asked 2022-Jan-30 at 12:24

                                                                                                      I want to apply pagination on a table with huge data. All I want to know a better option than using OFFSET in SQL Server.

                                                                                                      Here is my simple query:

                                                                                                      SELECT *
                                                                                                      FROM TableName
                                                                                                      ORDER BY Id DESC 
                                                                                                      OFFSET 30000000 ROWS
                                                                                                      FETCH NEXT 20 ROWS ONLY
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2022-Jan-30 at 12:24

                                                                                                      You can use Keyset Pagination for this. It's far more efficient than using Rowset Pagination (paging by row number).

                                                                                                      In Rowset Pagination, all previous rows must be read, before being able to read the next page. Whereas in Keyset Pagination, the server can jump immediately to the correct place in the index, so no extra rows are read that do not need to be.

                                                                                                      In this type of pagination, you cannot jump to a specific page number. You jump to a specific key and read from there. For this to perform well, you need to have a unique index on that key, which includes any other columns you need to query.

                                                                                                      One big benefit, apart from the obvious efficiency gain, is avoiding the "missing row" problem when paginating, caused by rows being removed from previously read pages. This does not happen when paginating by key, because the key does not change.

                                                                                                      Here is an example:

                                                                                                      Let us assume you have a table called TableName with an index on Id, and you want to start at the latest Id value and work backwards.

                                                                                                      You begin with:

                                                                                                      SELECT TOP (@numRows)
                                                                                                        *
                                                                                                      FROM TableName
                                                                                                      ORDER BY Id DESC;
                                                                                                      

                                                                                                      Note the use of ORDER BY to ensure the order is correct

                                                                                                      The client will hold the last received Id value (the lowest in this case). On the next request, you jump to that key and carry on:

                                                                                                      SELECT TOP (@numRows)
                                                                                                        *
                                                                                                      FROM TableName
                                                                                                      WHERE Id < @lastId
                                                                                                      ORDER BY Id DESC;
                                                                                                      

                                                                                                      Note the use of < not <=

                                                                                                      In case you were wondering, in a typical B-Tree+ index, the row with the indicated ID is not read, it's the row after it that's read.

                                                                                                      The key chosen must be unique, so if you are paging by a non-unique column then you must add a second column to both ORDER BY and WHERE. You would need an index on OtherColumn, Id for example, to support this type of query. Don't forget INCLUDE columns on the index.

                                                                                                      SQL Server does not support row/tuple comparators, so you cannot do (OtherColumn, Id) < (@lastOther, @lastId) (this is however supported in PostgreSQL, MySQL, MariaDB and SQLite).

                                                                                                      Instead you need the following:

                                                                                                      SELECT TOP (@numRows)
                                                                                                        *
                                                                                                      FROM TableName
                                                                                                      WHERE (
                                                                                                          OtherColumn = @lastOther AND Id < @lastId)
                                                                                                          OR OtherColumn < @lastOther
                                                                                                      )
                                                                                                      ORDER BY
                                                                                                        OtherColumn DESC,
                                                                                                        Id DESC;
                                                                                                      

                                                                                                      This is more efficient than it looks, as SQL Server can convert this into a proper < over both values.

                                                                                                      The presence of NULLs complicates things further. You may want to query those rows separately.

                                                                                                      Source https://stackoverflow.com/questions/70519518

                                                                                                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                                                                                      Vulnerabilities

                                                                                                      No vulnerabilities reported

                                                                                                      Install fetch

                                                                                                      As an alternative to using npm, you can obtain fetch.umd.js from the Releases section. The UMD distribution is compatible with AMD and CommonJS module loaders, as well as loading directly into a page via <script> tag. You will also need a Promise polyfill for older browsers. We recommend taylorhakes/promise-polyfill for its small size and Promises/A+ compatibility.

                                                                                                      Support

                                                                                                      Note: modern browsers such as Chrome, Firefox, Microsoft Edge, and Safari contain native implementations of window.fetch, therefore the code from this polyfill doesn't have any effect on those browsers. If you believe you've encountered an error with how window.fetch is implemented in any of these browsers, you should file an issue with that browser vendor instead of this project.
                                                                                                      Find more information at:
                                                                                                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                                      Find more libraries
                                                                                                      Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                                      Save this library and start creating your kit

                                                                                                      Share this Page

                                                                                                      share link

                                                                                                      Consider Popular Reactive Programming Libraries

                                                                                                      axios

                                                                                                      by axios

                                                                                                      RxJava

                                                                                                      by ReactiveX

                                                                                                      async

                                                                                                      by caolan

                                                                                                      rxjs

                                                                                                      by ReactiveX

                                                                                                      fetch

                                                                                                      by github

                                                                                                      Try Top Libraries by github

                                                                                                      hub

                                                                                                      by githubGo

                                                                                                      copilot-docs

                                                                                                      by githubPython

                                                                                                      docs

                                                                                                      by githubJavaScript

                                                                                                      opensource.guide

                                                                                                      by githubHTML

                                                                                                      gh-ost

                                                                                                      by githubGo

                                                                                                      Compare Reactive Programming Libraries with Highest Support

                                                                                                      aiohttp

                                                                                                      by aio-libs

                                                                                                      axios

                                                                                                      by axios

                                                                                                      twisted

                                                                                                      by twisted

                                                                                                      bluebird

                                                                                                      by petkaantonov

                                                                                                      uvicorn

                                                                                                      by encode

                                                                                                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                                      Find more libraries
                                                                                                      Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                                      Save this library and start creating your kit