@achingbrain/follow-registry 中文文档教程

发布于 5年前 浏览 20 项目主页 更新于 3年前

@achingbrain/follow-registry

构建状态Dependency Status

遵循 npm 注册表并在发布新模块时产生更改对象

Usage

const followRegistry = require('@achinbrain/follow-registry')

// All options are optional
const options = {
  // user agent used to request metadata etc
  ua: 'npm-registry-follower',

  // where to get the changes from
  replicator: 'https://replicate.npmjs.com/registry/_changes',

  // where to get module details from
  registry: 'https://registry.npmjs.com',

  // how many sets of metadata to request concurrently
  concurrency: 50,

  // restart the feed if no changes are received for this long
  inactivityTimeout: 3600000,

  // how long to wait after inactivityTimeout
  inactivityBackoff: 5000,

  // how many times to try fetching module metadata
  metadataRetries: 5,

  // how long to wait between retries
  metadataRetryBackoff: 5000,

  // override which seq value to start streaming changes from
  since: undefined,

  // override sequence file storage
  seq: {
    async read (), // returns a seq number
    async write (seq), // stores a seq number
    async reset () // resets the seq number
  }
}

for await (const { packument, seq, done } of followRegistry(options)) {
  //...do something with the change
  console.info(`${packument.name} was updated in seq ${seq}`)

  // signal we are done processing this change
  //
  // Important - if `done` is not called, the change will be
  // reprocessed the next time `followRegistry` is run
  await done()
}

// read the last sucessfully processed seq
const seq = await follow.seq(options)

// reset the last sucessfully processed seq
await follow.reset(options)

Changes feed

从提要返回的对象位于 缩写格式

Acknowledgements

davglass/follow-registry 分叉。

@achingbrain/follow-registry

Build StatusDependency Status

Follows the npm registry and yields change objects when new modules are published

Usage

const followRegistry = require('@achinbrain/follow-registry')

// All options are optional
const options = {
  // user agent used to request metadata etc
  ua: 'npm-registry-follower',

  // where to get the changes from
  replicator: 'https://replicate.npmjs.com/registry/_changes',

  // where to get module details from
  registry: 'https://registry.npmjs.com',

  // how many sets of metadata to request concurrently
  concurrency: 50,

  // restart the feed if no changes are received for this long
  inactivityTimeout: 3600000,

  // how long to wait after inactivityTimeout
  inactivityBackoff: 5000,

  // how many times to try fetching module metadata
  metadataRetries: 5,

  // how long to wait between retries
  metadataRetryBackoff: 5000,

  // override which seq value to start streaming changes from
  since: undefined,

  // override sequence file storage
  seq: {
    async read (), // returns a seq number
    async write (seq), // stores a seq number
    async reset () // resets the seq number
  }
}

for await (const { packument, seq, done } of followRegistry(options)) {
  //...do something with the change
  console.info(`${packument.name} was updated in seq ${seq}`)

  // signal we are done processing this change
  //
  // Important - if `done` is not called, the change will be
  // reprocessed the next time `followRegistry` is run
  await done()
}

// read the last sucessfully processed seq
const seq = await follow.seq(options)

// reset the last sucessfully processed seq
await follow.reset(options)

Changes feed

Objects returned from the feed are in the abbreviated format.

Acknowledgements

Forked from davglass/follow-registry.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文