Skip to content

Latest commit

History

History
53 lines (32 loc) 路 5.69 KB

events.md

File metadata and controls

53 lines (32 loc) 路 5.69 KB

Events

new version

The new version event occurs when a new package version is found, and consists of the version files as a JSON string array. For example, for a new version 1.0.28 of our test package a-happy-tyler:

2020-08-03 19:40:56 a-happy-tyler: new version: 1.0.28: ["happy.css","happy.js","happy.min.css","happy.min.js","happy.woff","happy.woff2","kristina.js","kristina.min.js","package.json","smile.jpg"]

Note that additional autogenerated files may be included, such as minified JavaScript files.

new version kv files

The new version kv files event occurs when the files from the new version are pushed to Workers KV from the cdnjs autoupdater. This event lists the files pushed to KV as a JSON string array. For example:

2020-08-03 19:40:56 a-happy-tyler: new version kv files: 1.0.28: ["happy.css.br","happy.css.gz","happy.js.br","happy.js.gz","happy.min.css.br","happy.min.css.gz","happy.min.js.br","happy.min.js.gz","happy.woff.br","happy.woff.gz","happy.woff2","kristina.js.br","kristina.js.gz","kristina.min.js.br","kristina.min.js.gz","package.json.br","package.json.gz","smile.jpg.br","smile.jpg.gz"]

Currently, all files except woff2 will be compressed with brotli and gzip before insertion to KV. Note that if a file is not included here but its uncompressed version was included in the new version event, then it failed to reach KV. In this case, either the file extension was unsupported or it exceeded the maximum size allowed in KV (10MiB).

In the case the compressed file size exceeded 10MiB, its uncompressed version will still exist in the cdnjs repo, and will be fetchable from the CDN, so do not panic! We are planning to add support to KV for oversized files soon.

new version kv SRIs

The new version kv SRIs event occurs when SRIs are calculated for the js and css files from the new version and pushed to Workers KV from the cdnjs autoupdater. This event lists the respectively file names of the SRIs pushed to KV as a JSON string array. For example:

2020-08-21 13:44:26 a-happy-tyler: new version kv SRIs: 1.0.51: ["happy.css","happy.js","happy.min.css","happy.min.js","kristina.js","kristina.min.js"]

update metadata

The update metadata event occurs when there is a change to a package's metadata, and the new metadata is pushed to Workers KV. Traditionally, this would be a git commit to the package's respective package.json file in the cdnjs repo. For example, with the new stable version 1.0.28 of a-happy-tyler, the metadata updated:

2020-08-03 19:42:02 a-happy-tyler: update metadata: 1.0.28: {"authors":[{"name":"Tyler Caslin","email":"[email protected]"}],"autoupdate":{"source":"git","target":"git://github.com/tc80/a-happy-tyler.git","fileMap":[{"basePath":"src","files":["*"]}]},"description":"Tyler is happy. Be like Tyler.","filename":"happy.js","keywords":["tyler","happy"],"license":"MIT","name":"a-happy-tyler","repository":{"type":"git","url":"git://github.com/tc80/a-happy-tyler.git"},"version":"1.0.28","author":"Tyler Caslin <[email protected]>"}

Note that the update metadata event may not always occur after a new version kv event as there are times when the package metadata has not changed. Since the version field represents the latest stable version, a new beta version will not overwrite it (assuming all package versions are semver).

Finally, note that this JSON metadata is considered "robot-only", or "non-human-readable". It's JSON schema can be found here. The "human-readable" metadata JSON can be found in the packages repo, whose JSON schema can be found here.

update aggregated metadata

The update aggregated metadata event occurs when there is a new version kv event or an update metadata event. In order to boost performance in the cdnjs API, we maintain aggregated metadata entries in Workers KV. The cdnjs autoupdater will fetch the package's aggregated metadata from Workers KV, update it with the new metadata, and write it back to Workers KV. This event describes whether the aggregated metadata entry was found in Workers KV using found, and lists the array of keys updated in our aggregated metadata namespace with kv_writes. For instance, with the new stable version 1.0.41 of a-happy-tyler, the aggregated metadata updated:

2020-08-14 15:23:24 a-happy-tyler: update aggregated metadata: 1.0.41: {"found":true,"kv_writes":["a-happy-tyler"]}

Note that found should always be true unless the package is new, since false involves creating a new aggregated metadata entry. In addition, kv_writes should never be empty. If kv_writes is empty, no keys were updated in Workers KV, most likely indicating the entry exceeded Workers KV's 10MiB limit. To avoid this limit, we are currently gzipping the aggregated metadata.