@mosetta/build 0.0.34 → 0.0.35
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/CHANGELOG.md +5 -0
- package/package.json +6 -6
- package/src/build.mjs +34 -8
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mosetta/build",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.35",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "The core of the tile forge: builds a tile palette — its tile side artifacts, their dependency closure, the tile host descriptor. Environment-agnostic — the file system and the bundling engine are supplied from outside.",
|
|
6
6
|
"type": "module",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"scheduler": "*",
|
|
29
29
|
"systemjs": "^6.15.1",
|
|
30
30
|
"yaml": "^2.9.0",
|
|
31
|
-
"@mosetta/
|
|
32
|
-
"@mosetta/server": "0.0.
|
|
33
|
-
"@mosetta/
|
|
34
|
-
"@mosetta/
|
|
35
|
-
"@mosetta/
|
|
31
|
+
"@mosetta/router": "0.0.35",
|
|
32
|
+
"@mosetta/server": "0.0.35",
|
|
33
|
+
"@mosetta/server-action": "0.0.35",
|
|
34
|
+
"@mosetta/runtime": "0.0.35",
|
|
35
|
+
"@mosetta/tar": "0.0.35"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
package/src/build.mjs
CHANGED
|
@@ -381,7 +381,8 @@ export async function build(root, { mode = 'development', log, fileSystem, resol
|
|
|
381
381
|
const brings = mods.some((m) => m.namespace === r.namespace)
|
|
382
382
|
|| (r.dir !== root && discoverPrefabsIn(fileSystem, r.dir, () => {}).length > 0)
|
|
383
383
|
|| cfg?.service !== undefined
|
|
384
|
-
|| cfg?.workbench !== undefined
|
|
384
|
+
|| cfg?.workbench !== undefined
|
|
385
|
+
|| cfg?.permissions !== undefined;
|
|
385
386
|
if (!brings) continue;
|
|
386
387
|
const descriptor = distributionDescriptor(fileSystem, r, (key, file) => {
|
|
387
388
|
watchFiles.add(file);
|
|
@@ -560,11 +561,11 @@ export function sourceLinkOf(repository) {
|
|
|
560
561
|
}
|
|
561
562
|
|
|
562
563
|
/** what a service may be granted on a site that takes it: palettes, a palette's tile, or the host's doors */
|
|
563
|
-
const SERVICE_GRANT_RE = /^(?:@(?:previews|media|code|
|
|
564
|
+
const SERVICE_GRANT_RE = /^(?:@(?:previews|media|code|repositories)|[a-z][a-z0-9-]{0,62}(?:\/[a-z][A-Za-z0-9]{0,63})?)$/;
|
|
564
565
|
/** an action of the palette named for a workbench: `<tile>.<action>` */
|
|
565
566
|
const WORKBENCH_ACTION_RE = /^[a-z][A-Za-z0-9]{0,63}\.[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
566
|
-
/** the parts a palette may play in a workbench */
|
|
567
|
-
const WORKBENCH_ROLES = ['assistant', 'transcribe'];
|
|
567
|
+
/** the parts a palette may play in a workbench (@mosetta/content/workbench) */
|
|
568
|
+
const WORKBENCH_ROLES = ['assistant', 'transcribe', 'tools', 'icon'];
|
|
568
569
|
|
|
569
570
|
/**
|
|
570
571
|
* A distribution's offer of itself as a service (mosetta.json `service: { grant: [...] }`): what it
|
|
@@ -577,20 +578,20 @@ export function serviceOf(raw) {
|
|
|
577
578
|
if (unknown !== undefined) throw new Error(`mosetta.json: service.${unknown} is no part of a service's offer — it is { "grant": [...] }`);
|
|
578
579
|
const grant = raw?.grant ?? [];
|
|
579
580
|
if (!Array.isArray(grant) || grant.length > 32 || !grant.every((g) => typeof g === 'string' && SERVICE_GRANT_RE.test(g))) {
|
|
580
|
-
throw new Error('mosetta.json: service.grant is up to 32 palettes (`brand`), tiles (`brand/tile`) or host doors (`@previews`, `@media`, `@code`, `@
|
|
581
|
+
throw new Error('mosetta.json: service.grant is up to 32 palettes (`brand`), tiles (`brand/tile`) or host doors (`@previews`, `@media`, `@code`, `@repositories`) the service asks to call');
|
|
581
582
|
}
|
|
582
583
|
return { grant: [...new Set(grant)] };
|
|
583
584
|
}
|
|
584
585
|
|
|
585
586
|
/**
|
|
586
587
|
* The parts a palette plays in the workbench of a site it is connected to (mosetta.json
|
|
587
|
-
* `workbench: { assistant, transcribe }`): the assistant's turn, dictation
|
|
588
|
-
* own, `<tile>.<action>`. The palette's own, whichever way a site connects it — as code or as a
|
|
588
|
+
* `workbench: { assistant, transcribe, tools, icon }`): the assistant's turn, dictation, its own tools
|
|
589
|
+
* for the site's connector, the site's icon drawn — each an action of its own, `<tile>.<action>`. The palette's own, whichever way a site connects it — as code or as a
|
|
589
590
|
* service. A part named wrong stops the build: a palette that meant one must not ship without it.
|
|
590
591
|
*/
|
|
591
592
|
export function workbenchOf(raw) {
|
|
592
593
|
if (raw === undefined) return null;
|
|
593
|
-
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) throw new Error(
|
|
594
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) throw new Error(`mosetta.json: workbench names the parts the palette plays in a workbench, each \`<tile>.<action>\`: ${WORKBENCH_ROLES.join(', ')}`);
|
|
594
595
|
const unknown = Object.keys(raw).find((role) => !WORKBENCH_ROLES.includes(role));
|
|
595
596
|
if (unknown !== undefined) throw new Error(`mosetta.json: workbench.${unknown} is no part of a workbench — the parts are ${WORKBENCH_ROLES.join(', ')}`);
|
|
596
597
|
const workbench = {};
|
|
@@ -603,6 +604,29 @@ export function workbenchOf(raw) {
|
|
|
603
604
|
return Object.keys(workbench).length ? workbench : null;
|
|
604
605
|
}
|
|
605
606
|
|
|
607
|
+
/** Operations a palette declares under its own brand for a project's role catalogue. */
|
|
608
|
+
export function permissionDefinitionsOf(brand, raw) {
|
|
609
|
+
if (raw === undefined) return [];
|
|
610
|
+
if (!Array.isArray(raw) || raw.length > 200) throw new Error(`mosetta.json: ${brand} permissions must be an array of at most 200 operations`);
|
|
611
|
+
const seen = new Set();
|
|
612
|
+
return raw.map((permission, index) => {
|
|
613
|
+
const at = `mosetta.json: ${brand} permissions[${index}]`;
|
|
614
|
+
if (!permission || typeof permission !== 'object' || Array.isArray(permission)
|
|
615
|
+
|| Object.keys(permission).some((key) => !['name', 'title', 'about', 'target'].includes(key))) {
|
|
616
|
+
throw new Error(`${at} requires name, title, about and target`);
|
|
617
|
+
}
|
|
618
|
+
const { name, title, about, target } = permission;
|
|
619
|
+
if (typeof name !== 'string' || name.length > 200 || !/^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)*$/.test(name)
|
|
620
|
+
|| !name.startsWith(`${brand}.`)) throw new Error(`${at} name must be an explicit operation under ${brand}.`);
|
|
621
|
+
if (typeof title !== 'string' || !title.trim() || title.length > 160
|
|
622
|
+
|| typeof about !== 'string' || !about.trim() || about.length > 2000) throw new Error(`${at} requires a title and description`);
|
|
623
|
+
if (target !== 'resource' && target !== 'project') throw new Error(`${at} target must be resource or project`);
|
|
624
|
+
if (seen.has(name)) throw new Error(`${at} duplicates operation ${name}`);
|
|
625
|
+
seen.add(name);
|
|
626
|
+
return { name, title: title.trim(), about: about.trim(), target };
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
|
|
606
630
|
/**
|
|
607
631
|
* A distribution's catalog entity: what it calls itself, from its mosetta.json (title,
|
|
608
632
|
* description, icon, cover, source) with package.json behind the description and the source.
|
|
@@ -610,6 +634,7 @@ export function workbenchOf(raw) {
|
|
|
610
634
|
*/
|
|
611
635
|
export function distributionDescriptor(fileSystem, root, ship) {
|
|
612
636
|
const cfg = readConfig(fileSystem, root.dir);
|
|
637
|
+
const permissions = permissionDefinitionsOf(root.namespace, cfg.permissions);
|
|
613
638
|
let pkg = {};
|
|
614
639
|
try {
|
|
615
640
|
pkg = fileSystem.readJson(path.join(root.dir, 'package.json'));
|
|
@@ -635,6 +660,7 @@ export function distributionDescriptor(fileSystem, root, ship) {
|
|
|
635
660
|
...(serviceOf(cfg.service) ? { service: serviceOf(cfg.service) } : {}),
|
|
636
661
|
// the parts it plays in a workbench (the assistant's turn, dictation)
|
|
637
662
|
...(workbenchOf(cfg.workbench) ? { workbench: workbenchOf(cfg.workbench) } : {}),
|
|
663
|
+
...(permissions.length ? { permissions } : {}),
|
|
638
664
|
...(text(cfg.description) ?? text(pkg.description) ? { description: text(cfg.description) ?? text(pkg.description) } : {}),
|
|
639
665
|
...(text(cfg.source) ?? sourceLinkOf(pkg.repository) ? { source: text(cfg.source) ?? sourceLinkOf(pkg.repository) } : {}),
|
|
640
666
|
...(changesOf(fileSystem, root) ? { changes: changesOf(fileSystem, root) } : {}),
|