Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@antora/content-classifier

Package Overview
Dependencies
Maintainers
2
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antora/content-classifier - npm Package Compare versions

Comparing version 2.3.0-alpha.1 to 2.3.0-alpha.2

157

lib/content-catalog.js
'use strict'
const _ = require('lodash')
const File = require('./file')

@@ -15,10 +14,9 @@ const parseResourceId = require('./util/parse-resource-id')

const $files = Symbol('files')
const $generateId = Symbol('generateId')
class ContentCatalog {
constructor (playbook) {
this[$components] = {}
this[$files] = {}
this.htmlUrlExtensionStyle = _.get(playbook, ['urls', 'htmlExtensionStyle'], 'default')
//this.urlRedirectFacility = _.get(playbook, ['urls', 'redirectFacility'], 'static')
constructor (playbook = {}) {
this[$components] = new Map()
this[$files] = new Map()
this.htmlUrlExtensionStyle = (playbook.urls || {}).htmlExtensionStyle || 'default'
this.urlRedirectFacility = (playbook.urls || {}).redirectFacility || 'static'
}

@@ -54,3 +52,3 @@

if (asciidocConfig) componentVersion.asciidocConfig = asciidocConfig
const component = this[$components][name]
const component = this.getComponent(name)
if (component) {

@@ -69,22 +67,25 @@ const componentVersions = component.versions

} else {
this[$components][name] = Object.defineProperties(
{ name, latest: componentVersion, versions: [componentVersion] },
{
// NOTE alias latestVersion to latest for backwards compatibility
latestVersion: {
get: function () {
return this.latest
this[$components].set(
name,
Object.defineProperties(
{ name, latest: componentVersion, versions: [componentVersion] },
{
// NOTE alias latestVersion to latest for backwards compatibility
latestVersion: {
get: function () {
return this.latest
},
},
},
title: {
get: function () {
return this.latest.title
title: {
get: function () {
return this.latest.title
},
},
},
url: {
get: function () {
return this.latest.url
url: {
get: function () {
return this.latest.url
},
},
},
}
}
)
)

@@ -96,5 +97,5 @@ }

addFile (file) {
const id = this[$generateId](file.src)
if (id in this[$files]) {
throw new Error(`Duplicate ${file.src.family}: ${id.replace(':' + file.src.family + '$', ':')}`)
const key = generateKey(file.src)
if (this[$files].has(key)) {
throw new Error(`Duplicate ${file.src.family}: ${key.replace(':' + file.src.family + '$', ':')}`)
}

@@ -117,20 +118,31 @@ if (!File.isVinyl(file)) file = new File(file)

}
this[$files][id] = file
this[$files].set(key, file)
}
findBy (criteria) {
return _.filter(this[$files], { src: criteria })
const criteriaEntries = Object.entries(criteria)
const accum = []
for (const entry of this[$files]) {
const candidate = entry[1]
const candidateSrc = candidate.src
if (criteriaEntries.every(([key, val]) => candidateSrc[key] === val)) accum.push(candidate)
}
return accum
}
getById ({ component, version, module, family, relative }) {
const id = this[$generateId]({ component, version, module, family, relative })
return this[$files][id]
return this[$files].get(generateKey({ component, version, module, family, relative }))
}
getByPath ({ component, version, path: path_ }) {
return _.find(this[$files], { path: path_, src: { component, version } })
for (const entry of this[$files]) {
const candidate = entry[1]
if (candidate.path === path_ && candidate.src.component === component && candidate.src.version === version) {
return candidate
}
}
}
getComponent (name) {
return this[$components][name]
return this[$components].get(name)
}

@@ -145,3 +157,7 @@

getComponentMap () {
return Object.assign({}, this[$components])
const accum = {}
for (const [name, component] of this[$components]) {
accum[name] = component
}
return accum
}

@@ -154,3 +170,3 @@

getComponents () {
return Object.values(this[$components])
return [...this[$components].values()]
}

@@ -162,6 +178,15 @@

getFiles () {
return Object.values(this[$files])
getAll () {
return [...this[$files].values()]
}
getPages () {
const accum = []
for (const entry of this[$files]) {
const candidate = entry[1]
if (candidate.src.family === 'page') accum.push(candidate)
}
return accum
}
// TODO add `follow` argument to control whether alias is followed

@@ -175,3 +200,3 @@ getSiteStartPage () {

registerPageAlias (aliasSpec, targetPage) {
const src = parseResourceId(aliasSpec, targetPage.src, ['page'])
const src = parseResourceId(aliasSpec, targetPage.src, 'page', ['page'])
// QUESTION should we throw an error if alias is invalid?

@@ -186,3 +211,3 @@ if (!src) return

// TODO we'll need some way to easily get a displayable page ID
let qualifiedSpec = this[$generateId](existingPage.src)
let qualifiedSpec = generateKey(existingPage.src)
qualifiedSpec = qualifiedSpec.replace(':page$', ':')

@@ -224,14 +249,56 @@ const message = `Page alias cannot reference ${targetPage === existingPage ? 'itself' : 'an existing page'}`

resolvePage (spec, context = {}) {
return resolveResource(spec, this, context, ['page'])
return resolveResource(spec, this, context, 'page', ['page'])
}
resolveResource (spec, context = {}, permittedFamilies = undefined, defaultFamily = undefined) {
return resolveResource(spec, this, context, permittedFamilies, defaultFamily)
resolveResource (spec, context = {}, defaultFamily = undefined, permittedFamilies = undefined) {
return resolveResource(spec, this, context, defaultFamily, permittedFamilies)
}
[$generateId] ({ component, version, module, family, relative }) {
return `${version}@${component}:${module}:${family}$${relative}`
exportToModel () {
const target = this
return new (class ContentCatalog {
findBy (criteria) {
return target.findBy(criteria)
}
getAll () {
return target.getAll()
}
getById (id) {
return target.getById(id)
}
getComponent (name) {
return target.getComponent(name)
}
getComponents () {
return target.getComponents()
}
getPages () {
return target.getPages()
}
resolvePage (spec, context = {}) {
return target.resolvePage(spec, context)
}
resolveResource (spec, context = {}, defaultFamily = undefined, permittedFamilies = undefined) {
return target.resolveResource(spec, context, defaultFamily, permittedFamilies)
}
})()
}
}
/**
* @deprecated superceded by getAll()
*/
ContentCatalog.prototype.getFiles = ContentCatalog.prototype.getAll
function generateKey ({ component, version, module, family, relative }) {
return `${version}@${component}:${module}:${family}$${relative}`
}
function expandPageSrc (src, family = 'page') {

@@ -238,0 +305,0 @@ src.family = family

@@ -24,4 +24,5 @@ 'use strict'

* @param {Object} [ctx={}] - The src context.
* @param {Array<String>} [permittedFamilies=undefined] - An optional array of permitted family names.
* @param {String} [defaultFamily='page'] - The default family to use if family is not specified in spec.
* @param {String} [defaultFamily='page'] - The default family to use if family is not specified in the spec.
* This value is always used instead of family value provided by the ctx.
* @param {Array<String>} [permittedFamilies=undefined] - An optional array of family names to allow.
*

@@ -31,3 +32,3 @@ * @returns {Object} A resource ID object that can be used to look up the file in the content

*/
function parseResourceId (spec, ctx = {}, permittedFamilies = undefined, defaultFamily = 'page') {
function parseResourceId (spec, ctx = {}, defaultFamily = 'page', permittedFamilies = undefined) {
const match = spec.match(RESOURCE_ID_RX)

@@ -34,0 +35,0 @@ if (!match) return

@@ -19,5 +19,5 @@ 'use strict'

* @param {Object} [ctx={}] - The src context.
* @param {Array<String>} [permittedFamilies=undefined] - An optional array of permitted family names.
* @param {String} [defaultFamily=undefined] - The default family to use if family is not specified in spec.
* If not specified, and spec is missing a family, the family will default to "page".
* The value "page" is used if not specified. This value is always used instead of family value provided by the ctx.
* @param {Array<String>} [permittedFamilies=undefined] - An optional array of family names to allow.
*

@@ -27,8 +27,7 @@ * @return {File} The virtual file to which the contextual resource ID spec refers, or undefined if

*/
function resolveResource (spec, catalog, ctx = {}, permittedFamilies = undefined, defaultFamily = undefined) {
const id = parseResourceId(spec, ctx, permittedFamilies, defaultFamily)
function resolveResource (spec, catalog, ctx = {}, defaultFamily = undefined, permittedFamilies = undefined) {
const id = parseResourceId(spec, ctx, defaultFamily, permittedFamilies)
if (!id) throw new Error(`Invalid ${defaultFamily || 'resource'} ID syntax`)
if (!id.family) return
if (!id.version) {

@@ -39,2 +38,3 @@ const component = catalog.getComponent(id.component)

}
if (!id.module) id.module = 'ROOT'

@@ -41,0 +41,0 @@ return catalog.getById(id)

{
"name": "@antora/content-classifier",
"version": "2.3.0-alpha.1",
"version": "2.3.0-alpha.2",
"description": "Organizes aggregated content into a virtual file catalog for use in an Antora documentation pipeline.",

@@ -19,7 +19,6 @@ "license": "MPL-2.0",

"dependencies": {
"lodash": "~4.17",
"vinyl": "~2.2"
},
"devDependencies": {
"@antora/content-aggregator": "2.3.0-alpha.1"
"@antora/content-aggregator": "2.3.0-alpha.2"
},

@@ -26,0 +25,0 @@ "engines": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc