openvibers/openvibe.publishing index.js
index.js
| 1 | ; |
| 2 | /** |
| 3 | * openvibe-publishing — every module is also its own entry point and can be used alone: |
| 4 | * require('openvibe-publishing/revisions'), …/schedule, …/taxonomy, …/citations, …/media, |
| 5 | * …/discussion, …/seo, …/authorship, …/index-hooks, …/ssr, …/blocks, …/ai, …/ingest, …/publication, |
| 6 | * …/search-feed, …/search-relay, …/layout |
| 7 | * This root export loads each one lazily, on first access. |
| 8 | * |
| 9 | * schema({ revisions: 'wiki_page', citations: 'wiki', … }) is the DDL of every store a product uses, |
| 10 | * for its migration file (keys are module names; a value is a prefix or a list of prefixes). |
| 11 | */ |
| 12 | const MODULES = { |
| 13 | revisions: './lib/revisions', |
| 14 | schedule: './lib/schedule', |
| 15 | taxonomy: './lib/taxonomy', |
| 16 | citations: './lib/citations', |
| 17 | media: './lib/media', |
| 18 | discussion: './lib/discussion', |
| 19 | seo: './lib/seo', |
| 20 | authorship: './lib/authorship', |
| 21 | indexHooks: './lib/index-hooks', |
| 22 | ssr: './lib/ssr', |
| 23 | blocks: './lib/blocks', |
| 24 | ai: './lib/ai', |
| 25 | ingest: './lib/ingest', |
| 26 | publication: './lib/publication', |
| 27 | searchFeed: './lib/search-feed', |
| 28 | searchRelay: './lib/search-relay', |
| 29 | layout: './lib/layout', |
| 30 | }; |
| 31 | |
| 32 | /** Which function gives each storing module's DDL. */ |
| 33 | const SCHEMAS = { |
| 34 | revisions: (p) => require('./lib/revisions').schema(p), |
| 35 | citations: (p) => require('./lib/citations').schema(p), |
| 36 | media: (p) => require('./lib/media').schema(p), |
| 37 | discussion: (p) => require('./lib/discussion').schema(p), |
| 38 | schedule: (p) => require('./lib/schedule').schema(p), |
| 39 | authorship: (p) => require('./lib/authorship').schema(p), |
| 40 | taxonomy: (p) => require('./lib/taxonomy').schema(p), |
| 41 | seo: (p) => require('./lib/seo').redirectsSchema(p), |
| 42 | indexHooks: (p) => require('./lib/index-hooks').sequencerSchema(p), |
| 43 | ingest: (p) => require('./lib/ingest').schema(p), |
| 44 | }; |
| 45 | |
| 46 | function schema(stores = {}) { |
| 47 | const parts = []; |
| 48 | for (const [name, prefixes] of Object.entries(stores)) { |
| 49 | if (!SCHEMAS[name]) throw new TypeError(`schema: no store in module "${name}" (one of ${Object.keys(SCHEMAS).join(', ')})`); |
| 50 | for (const p of [].concat(prefixes)) parts.push(`-- openvibe-publishing/${name === 'indexHooks' ? 'index-hooks' : name} (prefix ${p})\n${SCHEMAS[name](p)}`); |
| 51 | } |
| 52 | return parts.join('\n'); |
| 53 | } |
| 54 | |
| 55 | const api = {}; |
| 56 | for (const [name, path] of Object.entries(MODULES)) { |
| 57 | Object.defineProperty(api, name, { enumerable: true, get: () => require(path) }); |
| 58 | } |
| 59 | Object.defineProperty(api, 'PublishingError', { enumerable: true, get: () => require('./lib/internal').PublishingError }); |
| 60 | Object.defineProperty(api, 'schema', { enumerable: true, value: schema }); |
| 61 | Object.defineProperty(api, 'version', { enumerable: true, value: require('./package.json').version }); |
| 62 | |
| 63 | module.exports = api; |
| 64 |