@crombolo/server 0.27.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -12
- package/src/bundle-build.ts +139 -0
- package/src/bundle-reload.ts +84 -0
- package/src/config.ts +17 -1
- package/src/database.ts +4 -4
- package/src/index.ts +4 -0
- package/src/marketplace.ts +14 -3
- package/src/media-folders.ts +32 -0
- package/src/schema.ts +0 -6
- package/src/seed/compile.ts +745 -0
- package/src/seed/export.ts +416 -0
- package/src/seed/index.ts +5 -0
- package/src/seed/keys.ts +35 -0
- package/src/seed/lines.ts +58 -0
- package/src/seed/read.ts +175 -0
- package/src/server.ts +23 -1
- package/src/settings.ts +13 -0
- package/src/webhook-files.ts +50 -13
- package/src/webhooks.ts +59 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"description": "The crombolo HTTP server: routing, configuration, media stores and background jobs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@crombolo/api-delivery": "0.
|
|
34
|
-
"@crombolo/api-management": "0.
|
|
35
|
-
"@crombolo/auth": "0.
|
|
36
|
-
"@crombolo/backoffice-host": "0.
|
|
37
|
-
"@crombolo/content": "0.
|
|
38
|
-
"@crombolo/contracts": "0.
|
|
39
|
-
"@crombolo/core": "0.
|
|
40
|
-
"@crombolo/data": "0.
|
|
41
|
-
"@crombolo/render": "0.
|
|
42
|
-
"@crombolo/schema": "0.
|
|
43
|
-
"@crombolo/transfer": "0.
|
|
33
|
+
"@crombolo/api-delivery": "0.29.0",
|
|
34
|
+
"@crombolo/api-management": "0.29.0",
|
|
35
|
+
"@crombolo/auth": "0.29.0",
|
|
36
|
+
"@crombolo/backoffice-host": "0.29.0",
|
|
37
|
+
"@crombolo/content": "0.29.0",
|
|
38
|
+
"@crombolo/contracts": "0.29.0",
|
|
39
|
+
"@crombolo/core": "0.29.0",
|
|
40
|
+
"@crombolo/data": "0.29.0",
|
|
41
|
+
"@crombolo/render": "0.29.0",
|
|
42
|
+
"@crombolo/schema": "0.29.0",
|
|
43
|
+
"@crombolo/transfer": "0.29.0",
|
|
44
44
|
"@logtape/logtape": "^2.3.8",
|
|
45
45
|
"jose": "^6.2.12"
|
|
46
46
|
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A bundle from a site directory (story 164): its schema, components, styles,
|
|
3
|
+
* scripts and seed, as one bundle that installs into a bare site — types,
|
|
4
|
+
* views and content in one transaction. The seed is compiled against that
|
|
5
|
+
* directory's own schema, booted in a throwaway database, so building needs no
|
|
6
|
+
* site or database of its own.
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
|
|
9
|
+
import { tmpdir } from 'node:os'
|
|
10
|
+
import { join, resolve } from 'node:path'
|
|
11
|
+
import { type BundleFile, bundleIdFor, writeBundle, writeBundlePackage } from '@crombolo/transfer'
|
|
12
|
+
import { createFileSystemPort } from './adapters/file-system.ts'
|
|
13
|
+
import { createTemplateFileStore } from './adapters/template-files.ts'
|
|
14
|
+
import { loadConfig, VERSION } from './config.ts'
|
|
15
|
+
import { bootstrapDatabase } from './database.ts'
|
|
16
|
+
import { syncSchemaDirectory } from './schema.ts'
|
|
17
|
+
import { compileSeed, type SeedBuild } from './seed/compile.ts'
|
|
18
|
+
import { siteSections } from './site-sections.ts'
|
|
19
|
+
|
|
20
|
+
export interface BundleBuildOptions {
|
|
21
|
+
/** The npm package name; default, from the directory's `site.json` or `package.json`. */
|
|
22
|
+
name?: string
|
|
23
|
+
/** What a person calls it; default, the site's name. */
|
|
24
|
+
label?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface BundleBuildResult {
|
|
28
|
+
/** What stops it being built: the schema refused, or the seed's findings. */
|
|
29
|
+
problems: string[]
|
|
30
|
+
seed?: SeedBuild
|
|
31
|
+
files?: BundleFile[]
|
|
32
|
+
name: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** What a directory calls its site: `site.json`, then `package.json`, then its folder. */
|
|
36
|
+
function siteIdentity(dir: string): { name: string; label: string } {
|
|
37
|
+
const read = (file: string) =>
|
|
38
|
+
existsSync(join(dir, file))
|
|
39
|
+
? (JSON.parse(readFileSync(join(dir, file), 'utf8')) as Record<string, unknown>)
|
|
40
|
+
: undefined
|
|
41
|
+
const site = read('site.json') ?? read('template.json')
|
|
42
|
+
const pkg = read('package.json')
|
|
43
|
+
const label =
|
|
44
|
+
(typeof site?.name === 'string' && site.name) ||
|
|
45
|
+
(typeof pkg?.name === 'string' && pkg.name) ||
|
|
46
|
+
(dir.split(/[\\/]/).at(-1) as string)
|
|
47
|
+
const slug = (typeof site?.id === 'string' ? site.id : label)
|
|
48
|
+
.toLowerCase()
|
|
49
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
50
|
+
.replace(/^-+|-+$/g, '')
|
|
51
|
+
return { name: slug || 'site', label }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function buildBundleFromDirectory(
|
|
55
|
+
sourceDir: string,
|
|
56
|
+
options: BundleBuildOptions = {},
|
|
57
|
+
): Promise<BundleBuildResult> {
|
|
58
|
+
const dir = resolve(sourceDir)
|
|
59
|
+
const identity = siteIdentity(dir)
|
|
60
|
+
const name = options.name ?? identity.name
|
|
61
|
+
if (!existsSync(join(dir, 'schema')))
|
|
62
|
+
return { problems: [`${dir} has no schema/ directory, so it is not a site`], name }
|
|
63
|
+
const work = mkdtempSync(join(tmpdir(), 'crombolo-bundle-build-'))
|
|
64
|
+
try {
|
|
65
|
+
const config = loadConfig(
|
|
66
|
+
{
|
|
67
|
+
siteName: options.label ?? identity.label,
|
|
68
|
+
dialect: 'sqlite',
|
|
69
|
+
sqliteFile: join(work, 'build.sqlite'),
|
|
70
|
+
siteDir: dir,
|
|
71
|
+
schemaDir: join(dir, 'schema'),
|
|
72
|
+
componentsDir: join(dir, 'components'),
|
|
73
|
+
stylesheetsDir: join(dir, 'css'),
|
|
74
|
+
scriptsDir: join(dir, 'scripts'),
|
|
75
|
+
mediaDir: join(work, 'media'),
|
|
76
|
+
logsDir: join(work, 'logs'),
|
|
77
|
+
development: true,
|
|
78
|
+
},
|
|
79
|
+
work,
|
|
80
|
+
)
|
|
81
|
+
const { db } = await bootstrapDatabase(config)
|
|
82
|
+
try {
|
|
83
|
+
const report = await syncSchemaDirectory(db, config, {
|
|
84
|
+
nodeId: config.nodeId,
|
|
85
|
+
revision: config.schemaRevision,
|
|
86
|
+
})
|
|
87
|
+
if (report.action === 'refused')
|
|
88
|
+
return {
|
|
89
|
+
problems: [
|
|
90
|
+
`the schema was refused: ${report.reason ?? report.problems.map((p) => `${p.file}: ${p.message}`).join('; ')}`,
|
|
91
|
+
],
|
|
92
|
+
name,
|
|
93
|
+
}
|
|
94
|
+
const seed = await compileSeed(db, config)
|
|
95
|
+
if (seed.findings.length > 0 || !seed.set)
|
|
96
|
+
return {
|
|
97
|
+
problems: seed.findings.map((f) => `${f.file}:${f.line} ${f.message}`),
|
|
98
|
+
seed,
|
|
99
|
+
name,
|
|
100
|
+
}
|
|
101
|
+
const sections = await siteSections(
|
|
102
|
+
{
|
|
103
|
+
db,
|
|
104
|
+
componentFiles: createTemplateFileStore(config.componentsDir),
|
|
105
|
+
components: createFileSystemPort(config.componentsDir, {
|
|
106
|
+
extension: '.tsx',
|
|
107
|
+
rewrites: ['.cshtml'],
|
|
108
|
+
}),
|
|
109
|
+
stylesheets: createFileSystemPort(config.stylesheetsDir, { extension: '.css' }),
|
|
110
|
+
scripts: createFileSystemPort(config.scriptsDir, { extension: '.js' }),
|
|
111
|
+
schemaDir: config.schemaDir,
|
|
112
|
+
},
|
|
113
|
+
'all',
|
|
114
|
+
)
|
|
115
|
+
const set = {
|
|
116
|
+
...seed.set,
|
|
117
|
+
manifest: {
|
|
118
|
+
...seed.set.manifest,
|
|
119
|
+
label: config.siteName,
|
|
120
|
+
createdBy: 'crombolo bundle build',
|
|
121
|
+
},
|
|
122
|
+
}
|
|
123
|
+
const files = writeBundlePackage(writeBundle(set, seed.blobs, sections), {
|
|
124
|
+
name,
|
|
125
|
+
version: '1.0.0',
|
|
126
|
+
id: bundleIdFor(name),
|
|
127
|
+
label: config.siteName,
|
|
128
|
+
private: true,
|
|
129
|
+
// As `release:version` writes it into every committed bundle.
|
|
130
|
+
peerRange: `>=${VERSION}`,
|
|
131
|
+
})
|
|
132
|
+
return { problems: [], seed, files, name }
|
|
133
|
+
} finally {
|
|
134
|
+
await db.close()
|
|
135
|
+
}
|
|
136
|
+
} finally {
|
|
137
|
+
rmSync(work, { recursive: true, force: true })
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A host installs a site's bundles itself and tells each node (story 181):
|
|
3
|
+
* `reloadBundles()` reads the site's `package.json` and `node_modules` again,
|
|
4
|
+
* so the back office serves what is there now. It never mounts a server half:
|
|
5
|
+
* configured `bundles` are wired at boot only, and stay as they were.
|
|
6
|
+
*/
|
|
7
|
+
import type { BundlePackage, ExtensionRegistry } from '@crombolo/backoffice-host'
|
|
8
|
+
|
|
9
|
+
/** The event a signed-in back office hears when this node's bundles change. */
|
|
10
|
+
export const BUNDLES_CHANGED_EVENT = {
|
|
11
|
+
eventSource: 'Crombolo:Bundles',
|
|
12
|
+
eventType: 'Changed',
|
|
13
|
+
key: '00000000-0000-0000-0000-000000000000',
|
|
14
|
+
} as const
|
|
15
|
+
|
|
16
|
+
export interface ReloadedBundle {
|
|
17
|
+
packageName: string
|
|
18
|
+
version: string
|
|
19
|
+
carries: BundlePackage['carries']
|
|
20
|
+
/** Whether its server half is mounted; a bundle found by a reload never is. */
|
|
21
|
+
wired: boolean
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface BundleReload {
|
|
25
|
+
added: ReloadedBundle[]
|
|
26
|
+
removed: { packageName: string; version: string }[]
|
|
27
|
+
changed: { packageName: string; from: string; to: string }[]
|
|
28
|
+
/** A dependency that claims to be a bundle and is not a valid one. */
|
|
29
|
+
problems: { packageName: string; problems: string[] }[]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface BundleReloader {
|
|
33
|
+
reload(): BundleReload
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface BundleReloaderOptions {
|
|
37
|
+
extensions: ExtensionRegistry
|
|
38
|
+
/** The ids of the configured server halves mounted at boot. */
|
|
39
|
+
wired: () => readonly string[]
|
|
40
|
+
/** Called when anything changed, with what did. */
|
|
41
|
+
changed: (reload: BundleReload) => void
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Compares against what this node last saw rather than the registry's cache,
|
|
46
|
+
* which development leaves off, so a reload reports a change once either way.
|
|
47
|
+
*/
|
|
48
|
+
export function createBundleReloader(options: BundleReloaderOptions): BundleReloader {
|
|
49
|
+
const byName = (bundles: readonly BundlePackage[]) =>
|
|
50
|
+
new Map(bundles.map((bundle) => [bundle.packageName, bundle]))
|
|
51
|
+
let seen = byName(options.extensions.bundles().bundles)
|
|
52
|
+
return {
|
|
53
|
+
reload() {
|
|
54
|
+
options.extensions.invalidate()
|
|
55
|
+
const found = options.extensions.bundles()
|
|
56
|
+
const now = byName(found.bundles)
|
|
57
|
+
const wired = new Set(options.wired())
|
|
58
|
+
const result: BundleReload = {
|
|
59
|
+
added: [...now.values()]
|
|
60
|
+
.filter((bundle) => !seen.has(bundle.packageName))
|
|
61
|
+
.map((bundle) => ({
|
|
62
|
+
packageName: bundle.packageName,
|
|
63
|
+
version: bundle.version,
|
|
64
|
+
carries: bundle.carries,
|
|
65
|
+
wired: bundle.carries.server && wired.has(bundle.id),
|
|
66
|
+
})),
|
|
67
|
+
removed: [...seen.values()]
|
|
68
|
+
.filter((bundle) => !now.has(bundle.packageName))
|
|
69
|
+
.map((bundle) => ({ packageName: bundle.packageName, version: bundle.version })),
|
|
70
|
+
changed: [...now.values()].flatMap((bundle) => {
|
|
71
|
+
const before = seen.get(bundle.packageName)
|
|
72
|
+
return before && before.version !== bundle.version
|
|
73
|
+
? [{ packageName: bundle.packageName, from: before.version, to: bundle.version }]
|
|
74
|
+
: []
|
|
75
|
+
}),
|
|
76
|
+
problems: found.problems,
|
|
77
|
+
}
|
|
78
|
+
seen = now
|
|
79
|
+
if (result.added.length + result.removed.length + result.changed.length > 0)
|
|
80
|
+
options.changed(result)
|
|
81
|
+
return result
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -404,6 +404,13 @@ export interface CromboloConfig {
|
|
|
404
404
|
* about the nodes' disks. `CROMBOLO_RUNTIME_INSTALLS`.
|
|
405
405
|
*/
|
|
406
406
|
runtimeInstalls: boolean
|
|
407
|
+
/**
|
|
408
|
+
* Where a host that installs packages for the site says to go instead (story
|
|
409
|
+
* 181), shown by the Marketplace while `runtimeInstalls` is off in place of
|
|
410
|
+
* "add it to package.json and deploy". `CROMBOLO_INSTALLS_ELSEWHERE_MESSAGE`
|
|
411
|
+
* and `CROMBOLO_INSTALLS_ELSEWHERE_URL`.
|
|
412
|
+
*/
|
|
413
|
+
installsElsewhere?: { message: string; url?: string }
|
|
407
414
|
/**
|
|
408
415
|
* Where the Packages section's Marketplace sends someone browsing for
|
|
409
416
|
* extensions. Never framed — npm refuses to be framed — so the native view
|
|
@@ -524,6 +531,14 @@ export function defineConfig(overrides: Partial<CromboloConfig> = {}): Partial<C
|
|
|
524
531
|
return overrides
|
|
525
532
|
}
|
|
526
533
|
|
|
534
|
+
/** Where installs happen, from the environment; only set when it names a message. */
|
|
535
|
+
function installsElsewhereFromEnv(): Pick<CromboloConfig, 'installsElsewhere'> {
|
|
536
|
+
const message = setting('CROMBOLO_INSTALLS_ELSEWHERE_MESSAGE')
|
|
537
|
+
if (!message) return {}
|
|
538
|
+
const url = setting('CROMBOLO_INSTALLS_ELSEWHERE_URL')
|
|
539
|
+
return { installsElsewhere: { message, ...(url ? { url } : {}) } }
|
|
540
|
+
}
|
|
541
|
+
|
|
527
542
|
/** Builds the effective config: explicit values, then environment, then defaults. */
|
|
528
543
|
export function loadConfig(
|
|
529
544
|
overrides: Partial<CromboloConfig> = {},
|
|
@@ -697,6 +712,7 @@ export function loadConfig(
|
|
|
697
712
|
// Nor here: it is the installation's decision about that code.
|
|
698
713
|
hostProvided: [],
|
|
699
714
|
marketplaceUrl: setting('CROMBOLO_MARKETPLACE_URL') ?? DEFAULTS.marketplaceUrl,
|
|
715
|
+
...installsElsewhereFromEnv(),
|
|
700
716
|
packageKeyword: setting('CROMBOLO_PACKAGE_KEYWORD') ?? DEFAULTS.packageKeyword,
|
|
701
717
|
npmRegistry: setting('CROMBOLO_NPM_REGISTRY') ?? DEFAULTS.npmRegistry,
|
|
702
718
|
// Nor here: a host reads its own variables inside `defineConfig`, if it wants them.
|
|
@@ -813,7 +829,7 @@ export function describeDatabase(
|
|
|
813
829
|
}
|
|
814
830
|
}
|
|
815
831
|
|
|
816
|
-
export const VERSION = '0.
|
|
832
|
+
export const VERSION = '0.29.0'
|
|
817
833
|
|
|
818
834
|
/** A whole number of seconds from the environment; undefined when unset or not one. */
|
|
819
835
|
function numberSetting(name: Parameters<typeof setting>[0]): number | undefined {
|
package/src/database.ts
CHANGED
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
type Db,
|
|
12
12
|
ensureBuiltInDataTypes,
|
|
13
13
|
ensureSystemContentTypes,
|
|
14
|
-
ensureSystemMediaTypes,
|
|
15
14
|
ensureSystemMemberTypes,
|
|
16
15
|
INITIAL_STATE,
|
|
17
16
|
markSetupPending,
|
|
@@ -25,6 +24,7 @@ import { ensureApiClient } from './api-client.ts'
|
|
|
25
24
|
import { type BundleChain, migrateBundles, pendingBundleSteps } from './bundle-tables.ts'
|
|
26
25
|
import { type CromboloConfig, runsOnLocalhost } from './config.ts'
|
|
27
26
|
import { logger } from './logging.ts'
|
|
27
|
+
import { linkMediaFolders } from './media-folders.ts'
|
|
28
28
|
|
|
29
29
|
/** Production never auto-upgrades: an existing database with steps pending refuses to boot. */
|
|
30
30
|
export class UpgradePendingError extends Error {
|
|
@@ -73,7 +73,7 @@ export class DatabaseNotReadyError extends Error {
|
|
|
73
73
|
* served an unmigrated database would answer queries against missing tables.
|
|
74
74
|
*/
|
|
75
75
|
export async function attachDatabase(config: CromboloConfig): Promise<Bootstrap> {
|
|
76
|
-
const db = await connect({ file: config.sqliteFile })
|
|
76
|
+
const db = await connect({ dialect: config.dialect, file: config.sqliteFile })
|
|
77
77
|
const pending = await pendingMigrations(db, cromboloPlan)
|
|
78
78
|
if (pending.length > 0) {
|
|
79
79
|
await db.close()
|
|
@@ -91,7 +91,7 @@ export async function bootstrapDatabase(
|
|
|
91
91
|
config: CromboloConfig,
|
|
92
92
|
chains: readonly BundleChain[] = [],
|
|
93
93
|
): Promise<Bootstrap> {
|
|
94
|
-
const db = await connect({ file: config.sqliteFile })
|
|
94
|
+
const db = await connect({ dialect: config.dialect, file: config.sqliteFile })
|
|
95
95
|
try {
|
|
96
96
|
// pendingMigrations throws when the database is newer than this code.
|
|
97
97
|
const pending = await pendingMigrations(db, cromboloPlan)
|
|
@@ -155,7 +155,7 @@ export async function installDatabase(
|
|
|
155
155
|
await seedContent(db)
|
|
156
156
|
// A database from an older version gains the built-ins it lacks.
|
|
157
157
|
await ensureBuiltInDataTypes(db)
|
|
158
|
-
await
|
|
158
|
+
await linkMediaFolders(db, config.schemaDir)
|
|
159
159
|
await ensureSystemMemberTypes(db)
|
|
160
160
|
await ensureSystemContentTypes(db)
|
|
161
161
|
|
package/src/index.ts
CHANGED
|
@@ -18,7 +18,9 @@ export * from './api-client.ts'
|
|
|
18
18
|
export * from './atomic-write.ts'
|
|
19
19
|
export * from './backup.ts'
|
|
20
20
|
export * from './boot-failure.ts'
|
|
21
|
+
export * from './bundle-build.ts'
|
|
21
22
|
export * from './bundle-install.ts'
|
|
23
|
+
export * from './bundle-reload.ts'
|
|
22
24
|
export * from './bundle-sections.ts'
|
|
23
25
|
export * from './bundle-tables.ts'
|
|
24
26
|
export * from './bundles.ts'
|
|
@@ -64,6 +66,7 @@ export * from './log-viewer.ts'
|
|
|
64
66
|
export * from './logging.ts'
|
|
65
67
|
export * from './marketplace.ts'
|
|
66
68
|
export * from './media-files.ts'
|
|
69
|
+
export * from './media-folders.ts'
|
|
67
70
|
export * from './media-store.ts'
|
|
68
71
|
export * from './media-store-azure.ts'
|
|
69
72
|
export * from './media-store-s3.ts'
|
|
@@ -79,6 +82,7 @@ export * from './remote-media.ts'
|
|
|
79
82
|
export * from './schema.ts'
|
|
80
83
|
export * from './schema-store.ts'
|
|
81
84
|
export * from './secrets.ts'
|
|
85
|
+
export * from './seed/index.ts'
|
|
82
86
|
export * from './seo.ts'
|
|
83
87
|
export * from './server.ts'
|
|
84
88
|
export * from './server-events.ts'
|
package/src/marketplace.ts
CHANGED
|
@@ -98,6 +98,8 @@ export interface MarketplaceOptions {
|
|
|
98
98
|
* `package.json` and a deploy, so every node has it and it outlives a restart.
|
|
99
99
|
*/
|
|
100
100
|
installs?: boolean
|
|
101
|
+
/** A host's own word on where installs happen, said in place of a deploy (story 181). */
|
|
102
|
+
installsElsewhere?: { message: string; url?: string }
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
export interface InstallOutcome {
|
|
@@ -320,7 +322,7 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
|
320
322
|
},
|
|
321
323
|
|
|
322
324
|
async install(name, version, request = {}) {
|
|
323
|
-
if (options.installs === false) return refusedHere(name, 'add')
|
|
325
|
+
if (options.installs === false) return refusedHere(name, 'add', options.installsElsewhere)
|
|
324
326
|
if (!isValidPackageName(name))
|
|
325
327
|
return { ok: false, message: `'${name}' is not a package name npm would accept.` }
|
|
326
328
|
if (version !== undefined && !isValidVersion(version))
|
|
@@ -378,7 +380,7 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
|
378
380
|
},
|
|
379
381
|
|
|
380
382
|
async uninstall(name) {
|
|
381
|
-
if (options.installs === false) return refusedHere(name, 'remove')
|
|
383
|
+
if (options.installs === false) return refusedHere(name, 'remove', options.installsElsewhere)
|
|
382
384
|
if (!isValidPackageName(name))
|
|
383
385
|
return { ok: false, message: `'${name}' is not a package name npm would accept.` }
|
|
384
386
|
const result = await install('remove', name, options.siteDir)
|
|
@@ -406,7 +408,16 @@ function descriptionOf(directory: string): string {
|
|
|
406
408
|
}
|
|
407
409
|
|
|
408
410
|
/** What a site that does not install at runtime says instead, with what to do. */
|
|
409
|
-
function refusedHere(
|
|
411
|
+
function refusedHere(
|
|
412
|
+
name: string,
|
|
413
|
+
verb: 'add' | 'remove',
|
|
414
|
+
elsewhere?: { message: string; url?: string },
|
|
415
|
+
): InstallOutcome {
|
|
416
|
+
if (elsewhere)
|
|
417
|
+
return {
|
|
418
|
+
ok: false,
|
|
419
|
+
message: elsewhere.url ? `${elsewhere.message} ${elsewhere.url}` : elsewhere.message,
|
|
420
|
+
}
|
|
410
421
|
return {
|
|
411
422
|
ok: false,
|
|
412
423
|
message:
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Folder holds the other built-in media types (story 180). Every command and
|
|
3
|
+
* boot opens the database through `installDatabase`, which links Folder here
|
|
4
|
+
* unless a schema file defines Folder and so says itself what it allows. A sync
|
|
5
|
+
* links any type it adds in its own transaction (`syncSchema`).
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
8
|
+
import { join } from 'node:path'
|
|
9
|
+
import { type Db, ensureSystemMediaTypes } from '@crombolo/data'
|
|
10
|
+
|
|
11
|
+
/** Whether a file under `schema/media-types/` defines Folder. */
|
|
12
|
+
export function folderDefinedInFiles(schemaDir: string): boolean {
|
|
13
|
+
const dir = join(schemaDir, 'media-types')
|
|
14
|
+
if (!existsSync(dir)) return false
|
|
15
|
+
return readdirSync(dir)
|
|
16
|
+
.filter((name) => name.endsWith('.toml'))
|
|
17
|
+
.some((name) => {
|
|
18
|
+
try {
|
|
19
|
+
const parsed = Bun.TOML.parse(readFileSync(join(dir, name), 'utf8')) as {
|
|
20
|
+
'media-type'?: { alias?: unknown }
|
|
21
|
+
}
|
|
22
|
+
const alias = parsed['media-type']?.alias
|
|
23
|
+
return typeof alias === 'string' && alias.toLowerCase() === 'folder'
|
|
24
|
+
} catch {
|
|
25
|
+
return false
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function linkMediaFolders(db: Db, schemaDir: string): Promise<void> {
|
|
31
|
+
await ensureSystemMediaTypes(db, { linkFolderChildren: !folderDefinedInFiles(schemaDir) })
|
|
32
|
+
}
|
package/src/schema.ts
CHANGED
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
currentSchemaState,
|
|
15
15
|
type Db,
|
|
16
16
|
ensureSystemContentTypes,
|
|
17
|
-
ensureSystemMediaTypes,
|
|
18
17
|
ensureSystemMemberTypes,
|
|
19
18
|
type Finding,
|
|
20
19
|
Locks,
|
|
@@ -150,7 +149,6 @@ export async function bootSchema(db: Db, config: CromboloConfig): Promise<Schema
|
|
|
150
149
|
if (!existsSync(config.schemaDir)) {
|
|
151
150
|
const nodeState = { version: '0', revision: config.schemaRevision }
|
|
152
151
|
await touchServer(db, { nodeId, ...nodeState, role: config.role, cromboloVersion: VERSION })
|
|
153
|
-
await ensureSystemMediaTypes(db, { linkFolderChildren: true })
|
|
154
152
|
await ensureSystemMemberTypes(db)
|
|
155
153
|
await ensureSystemContentTypes(db)
|
|
156
154
|
return { nodeState, nodeId, report: undefined, compatibilityMode: false }
|
|
@@ -170,10 +168,6 @@ export async function bootSchema(db: Db, config: CromboloConfig): Promise<Schema
|
|
|
170
168
|
}
|
|
171
169
|
const report = await syncSchemaDirectory(db, config, node)
|
|
172
170
|
if (report.action === 'refused') throw new SchemaBootError(report)
|
|
173
|
-
// Folder allows whichever built-in media types the site has — unless a file
|
|
174
|
-
// defines Folder, and so says itself what it allows.
|
|
175
|
-
const folderInFiles = (loaded.set.mediaTypes ?? []).some((t) => t.alias === 'Folder')
|
|
176
|
-
await ensureSystemMediaTypes(db, { linkFolderChildren: !folderInFiles })
|
|
177
171
|
await ensureSystemMemberTypes(db)
|
|
178
172
|
await ensureSystemContentTypes(db)
|
|
179
173
|
const boot: SchemaBoot = {
|