@cratis/scene.engine 4.23.0 → 4.25.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/descriptors/componentBadge.ts +41 -0
- package/descriptors/index.ts +7 -0
- package/descriptors/matchComponentQuery.ts +55 -0
- package/descriptors/rankFrequentlyUsedComponents.ts +29 -0
- package/descriptors/validateComponentDescriptors.ts +122 -0
- package/dist/cjs/descriptors/componentBadge.js +35 -0
- package/dist/cjs/descriptors/componentBadge.js.map +1 -0
- package/dist/cjs/descriptors/matchComponentQuery.js +56 -0
- package/dist/cjs/descriptors/matchComponentQuery.js.map +1 -0
- package/dist/cjs/descriptors/rankFrequentlyUsedComponents.js +18 -0
- package/dist/cjs/descriptors/rankFrequentlyUsedComponents.js.map +1 -0
- package/dist/cjs/descriptors/validateComponentDescriptors.js +116 -0
- package/dist/cjs/descriptors/validateComponentDescriptors.js.map +1 -0
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/templateApplicability.js.map +1 -1
- package/dist/cjs/templates/TemplateReferenceResolution.js +15 -0
- package/dist/cjs/templates/TemplateReferenceResolution.js.map +1 -0
- package/dist/cjs/templates/applicableTemplates.js +199 -0
- package/dist/cjs/templates/applicableTemplates.js.map +1 -0
- package/dist/cjs/templates/describeTemplateCatalog.js +11 -6
- package/dist/cjs/templates/describeTemplateCatalog.js.map +1 -1
- package/dist/cjs/templates/resolveTemplateReference.js +89 -0
- package/dist/cjs/templates/resolveTemplateReference.js.map +1 -0
- package/dist/cjs/templates/validateTemplateMetadata.js +9 -0
- package/dist/cjs/templates/validateTemplateMetadata.js.map +1 -1
- package/dist/esm/descriptors/componentBadge.d.ts +3 -0
- package/dist/esm/descriptors/componentBadge.d.ts.map +1 -0
- package/dist/esm/descriptors/componentBadge.js +33 -0
- package/dist/esm/descriptors/componentBadge.js.map +1 -0
- package/dist/esm/descriptors/index.d.ts +5 -0
- package/dist/esm/descriptors/index.d.ts.map +1 -0
- package/dist/esm/descriptors/index.js +5 -0
- package/dist/esm/descriptors/index.js.map +1 -0
- package/dist/esm/descriptors/matchComponentQuery.d.ts +9 -0
- package/dist/esm/descriptors/matchComponentQuery.d.ts.map +1 -0
- package/dist/esm/descriptors/matchComponentQuery.js +54 -0
- package/dist/esm/descriptors/matchComponentQuery.js.map +1 -0
- package/dist/esm/descriptors/rankFrequentlyUsedComponents.d.ts +7 -0
- package/dist/esm/descriptors/rankFrequentlyUsedComponents.d.ts.map +1 -0
- package/dist/esm/descriptors/rankFrequentlyUsedComponents.js +15 -0
- package/dist/esm/descriptors/rankFrequentlyUsedComponents.js.map +1 -0
- package/dist/esm/descriptors/validateComponentDescriptors.d.ts +3 -0
- package/dist/esm/descriptors/validateComponentDescriptors.d.ts.map +1 -0
- package/dist/esm/descriptors/validateComponentDescriptors.js +114 -0
- package/dist/esm/descriptors/validateComponentDescriptors.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +8 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/templateApplicability.d.ts +1 -2
- package/dist/esm/templateApplicability.d.ts.map +1 -1
- package/dist/esm/templateApplicability.js.map +1 -1
- package/dist/esm/templates/ApplicableTemplateSet.d.ts +27 -0
- package/dist/esm/templates/ApplicableTemplateSet.d.ts.map +1 -0
- package/dist/esm/templates/ApplicableTemplateSet.js +2 -0
- package/dist/esm/templates/ApplicableTemplateSet.js.map +1 -0
- package/dist/esm/templates/TemplateCatalogEntry.d.ts +3 -1
- package/dist/esm/templates/TemplateCatalogEntry.d.ts.map +1 -1
- package/dist/esm/templates/TemplateLibrary.d.ts +6 -0
- package/dist/esm/templates/TemplateLibrary.d.ts.map +1 -0
- package/dist/esm/templates/TemplateLibrary.js +2 -0
- package/dist/esm/templates/TemplateLibrary.js.map +1 -0
- package/dist/esm/templates/TemplateReferenceResolution.d.ts +16 -0
- package/dist/esm/templates/TemplateReferenceResolution.d.ts.map +1 -0
- package/dist/esm/templates/TemplateReferenceResolution.js +13 -0
- package/dist/esm/templates/TemplateReferenceResolution.js.map +1 -0
- package/dist/esm/templates/TemplateTarget.d.ts +9 -0
- package/dist/esm/templates/TemplateTarget.d.ts.map +1 -0
- package/dist/esm/templates/TemplateTarget.js +2 -0
- package/dist/esm/templates/TemplateTarget.js.map +1 -0
- package/dist/esm/templates/applicableTemplates.d.ts +9 -0
- package/dist/esm/templates/applicableTemplates.d.ts.map +1 -0
- package/dist/esm/templates/applicableTemplates.js +194 -0
- package/dist/esm/templates/applicableTemplates.js.map +1 -0
- package/dist/esm/templates/describeTemplateCatalog.d.ts.map +1 -1
- package/dist/esm/templates/describeTemplateCatalog.js +12 -7
- package/dist/esm/templates/describeTemplateCatalog.js.map +1 -1
- package/dist/esm/templates/index.d.ts +6 -0
- package/dist/esm/templates/index.d.ts.map +1 -1
- package/dist/esm/templates/index.js +6 -0
- package/dist/esm/templates/index.js.map +1 -1
- package/dist/esm/templates/resolveTemplateReference.d.ts +5 -0
- package/dist/esm/templates/resolveTemplateReference.d.ts.map +1 -0
- package/dist/esm/templates/resolveTemplateReference.js +87 -0
- package/dist/esm/templates/resolveTemplateReference.js.map +1 -0
- package/dist/esm/templates/validateTemplateMetadata.d.ts +2 -0
- package/dist/esm/templates/validateTemplateMetadata.d.ts.map +1 -1
- package/dist/esm/templates/validateTemplateMetadata.js +8 -1
- package/dist/esm/templates/validateTemplateMetadata.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/index.ts +1 -0
- package/package.json +3 -3
- package/templateApplicability.ts +2 -1
- package/templates/ApplicableTemplateSet.ts +54 -0
- package/templates/TemplateCatalogEntry.ts +5 -1
- package/templates/TemplateLibrary.ts +16 -0
- package/templates/TemplateReferenceResolution.ts +35 -0
- package/templates/TemplateTarget.ts +23 -0
- package/templates/applicableTemplates.ts +148 -0
- package/templates/describeTemplateCatalog.ts +11 -7
- package/templates/index.ts +6 -0
- package/templates/resolveTemplateReference.ts +79 -0
- package/templates/validateTemplateMetadata.ts +11 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { TemplateScope, SliceKind, TemplateReferenceSource } from '@cratis/scene.model';
|
|
2
|
+
import { resolveScreenTemplates } from '../resolveScreenTemplates.js';
|
|
3
|
+
import { validateDialogTemplateApplicability, validateLayoutApplicability, validateScreenTemplateApplicability } from '../templateApplicability.js';
|
|
4
|
+
import { TemplateCatalogKind } from './TemplateCatalogKind.js';
|
|
5
|
+
|
|
6
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
7
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
8
|
+
const screenScopes = [
|
|
9
|
+
TemplateScope.Module,
|
|
10
|
+
TemplateScope.Feature,
|
|
11
|
+
TemplateScope.Subfeature
|
|
12
|
+
];
|
|
13
|
+
const dialogSliceKinds = [
|
|
14
|
+
SliceKind.StateChange
|
|
15
|
+
];
|
|
16
|
+
const screenSliceKinds = [
|
|
17
|
+
SliceKind.StateChange,
|
|
18
|
+
SliceKind.StateView
|
|
19
|
+
];
|
|
20
|
+
/**
|
|
21
|
+
* Decides which templates a picker offers at a target, so no host re-implements the rules: own templates by
|
|
22
|
+
* category, then each blueprint that has at least one applicable template. A blueprint with none is omitted.
|
|
23
|
+
*
|
|
24
|
+
* It composes the applicability validators (kind and scope, explicit scopes override, category never implies a
|
|
25
|
+
* scope, slot fit against the container) and `resolveScreenTemplates` (a template must find exactly one home and
|
|
26
|
+
* nothing may nest inside itself) with the defaults of each hierarchy level, used when a template declares no scopes:
|
|
27
|
+
*
|
|
28
|
+
* - Application - layouts.
|
|
29
|
+
* - Module, Feature, Subfeature - screen templates, fitting a slot of the container.
|
|
30
|
+
* - Slice, state change - dialog templates.
|
|
31
|
+
* - Slice, state view - screen templates that declare the Slice scope or state view slice kinds.
|
|
32
|
+
*
|
|
33
|
+
* Declared `scopes` and `sliceKinds` always override the defaults. The C# engine (`ApplicableTemplates.Compute`)
|
|
34
|
+
* returns identical results; both are asserted against `template-applicability-fixtures.json`.
|
|
35
|
+
*/ function applicableTemplates(library, target) {
|
|
36
|
+
const own = library.own ? groupByCategory(applicableIn(library.own, target, false)) : [];
|
|
37
|
+
const blueprints = [];
|
|
38
|
+
for (const source of library.blueprints){
|
|
39
|
+
const categories = groupByCategory(applicableIn(source, target, true));
|
|
40
|
+
if (categories.length > 0) {
|
|
41
|
+
blueprints.push({
|
|
42
|
+
blueprint: source.manifest.name,
|
|
43
|
+
version: source.manifest.version,
|
|
44
|
+
displayName: source.manifest.displayName,
|
|
45
|
+
categories
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
own,
|
|
51
|
+
blueprints
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Why a layout does not apply at a target; empty when it does. */ function validateLayoutForTarget(layout, target) {
|
|
55
|
+
return withDefaults(validateLayoutApplicability(layout, target.scope), layout.name, TemplateCatalogKind.Layout, layout.metadata, target);
|
|
56
|
+
}
|
|
57
|
+
/** Why a screen template does not apply at a target, including whether its slot nesting resolves; empty when it does. */ function validateScreenTemplateForTarget(template, target) {
|
|
58
|
+
const problems = withDefaults(validateScreenTemplateApplicability(template, target.scope, target.container), template.name, TemplateCatalogKind.ScreenTemplate, template.metadata, target);
|
|
59
|
+
if (problems.length > 0) return problems;
|
|
60
|
+
if (target.chain?.includes(template.name)) {
|
|
61
|
+
return [
|
|
62
|
+
`Template '${template.name}' is already chosen above this target; nesting it again would make the chain loop`
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
if (template.fitsSlot !== undefined && target.container) {
|
|
66
|
+
const containerName = target.container.name;
|
|
67
|
+
const resolution = resolveScreenTemplates({
|
|
68
|
+
name: containerName,
|
|
69
|
+
slots: target.container.slots
|
|
70
|
+
}, [
|
|
71
|
+
template
|
|
72
|
+
]);
|
|
73
|
+
const valid = resolution.unplaced.length === 0 && resolution.cycles.length === 0;
|
|
74
|
+
if (!valid || !resolution.placements.some((placement)=>placement.template === template.name && placement.container === containerName)) {
|
|
75
|
+
return [
|
|
76
|
+
`Template '${template.name}' cannot be placed in '${containerName}': its slot nesting does not resolve`
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
/** Why a dialog template does not apply at a target; empty when it does. */ function validateDialogTemplateForTarget(template, target) {
|
|
83
|
+
return withDefaults(validateDialogTemplateApplicability(template, target.scope), template.name, TemplateCatalogKind.DialogTemplate, template.metadata, target);
|
|
84
|
+
}
|
|
85
|
+
function applicableIn(source, target, isBlueprint) {
|
|
86
|
+
const { manifest } = source;
|
|
87
|
+
const referenceTo = (name)=>isBlueprint ? {
|
|
88
|
+
source: TemplateReferenceSource.Blueprint,
|
|
89
|
+
id: name,
|
|
90
|
+
blueprint: manifest.name,
|
|
91
|
+
version: `^${manifest.version}`
|
|
92
|
+
} : {
|
|
93
|
+
source: TemplateReferenceSource.Own,
|
|
94
|
+
id: name
|
|
95
|
+
};
|
|
96
|
+
const applicable = [];
|
|
97
|
+
for (const layout of source.layouts ?? []){
|
|
98
|
+
if (validateLayoutForTarget(layout, target).length > 0) continue;
|
|
99
|
+
applicable.push({
|
|
100
|
+
package: manifest.name,
|
|
101
|
+
packageVersion: manifest.version,
|
|
102
|
+
kind: TemplateCatalogKind.Layout,
|
|
103
|
+
name: layout.name,
|
|
104
|
+
metadata: layout.metadata,
|
|
105
|
+
reference: referenceTo(layout.name)
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
for (const template of source.screenTemplates ?? []){
|
|
109
|
+
if (validateScreenTemplateForTarget(template, target).length > 0) continue;
|
|
110
|
+
applicable.push({
|
|
111
|
+
package: manifest.name,
|
|
112
|
+
packageVersion: manifest.version,
|
|
113
|
+
kind: TemplateCatalogKind.ScreenTemplate,
|
|
114
|
+
name: template.name,
|
|
115
|
+
displayName: template.displayName,
|
|
116
|
+
description: template.description,
|
|
117
|
+
metadata: template.metadata,
|
|
118
|
+
reference: referenceTo(template.name)
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
for (const template of source.dialogTemplates ?? []){
|
|
122
|
+
if (validateDialogTemplateForTarget(template, target).length > 0) continue;
|
|
123
|
+
applicable.push({
|
|
124
|
+
package: manifest.name,
|
|
125
|
+
packageVersion: manifest.version,
|
|
126
|
+
kind: TemplateCatalogKind.DialogTemplate,
|
|
127
|
+
name: template.name,
|
|
128
|
+
displayName: template.displayName,
|
|
129
|
+
description: template.description,
|
|
130
|
+
metadata: template.metadata,
|
|
131
|
+
reference: referenceTo(template.name)
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
return applicable;
|
|
135
|
+
}
|
|
136
|
+
function groupByCategory(templates) {
|
|
137
|
+
const categoryOf = (template)=>template.metadata?.category?.trim() ? template.metadata.category : undefined;
|
|
138
|
+
const categories = [
|
|
139
|
+
...new Set(templates.map(categoryOf).filter((category)=>category !== undefined))
|
|
140
|
+
];
|
|
141
|
+
const groups = categories.map((category)=>({
|
|
142
|
+
category,
|
|
143
|
+
templates: templates.filter((template)=>categoryOf(template) === category)
|
|
144
|
+
}));
|
|
145
|
+
const uncategorized = templates.filter((template)=>categoryOf(template) === undefined);
|
|
146
|
+
if (uncategorized.length > 0) groups.push({
|
|
147
|
+
templates: uncategorized
|
|
148
|
+
});
|
|
149
|
+
return groups;
|
|
150
|
+
}
|
|
151
|
+
function withDefaults(problems, name, kind, metadata, target) {
|
|
152
|
+
if (problems.length > 0 || !Object.values(TemplateScope).includes(target.scope)) return problems;
|
|
153
|
+
if (metadata?.scopes === undefined && !defaultScopes(kind, metadata).includes(target.scope)) {
|
|
154
|
+
return [
|
|
155
|
+
`Template '${name}' is not offered at scope '${target.scope}' unless it declares that scope`
|
|
156
|
+
];
|
|
157
|
+
}
|
|
158
|
+
if (target.scope === TemplateScope.Slice && target.sliceKind !== undefined) {
|
|
159
|
+
const sliceKind = target.sliceKind;
|
|
160
|
+
if (!Object.values(SliceKind).includes(sliceKind)) return [
|
|
161
|
+
`Template '${name}' has unknown target slice kind '${sliceKind}'`
|
|
162
|
+
];
|
|
163
|
+
if (sliceKind === SliceKind.Automation) return [
|
|
164
|
+
`Template '${name}' cannot be applied to an Automation slice, which has no presentation`
|
|
165
|
+
];
|
|
166
|
+
const kinds = metadata?.sliceKinds ?? defaultSliceKinds(kind);
|
|
167
|
+
if (!kinds.includes(sliceKind)) return [
|
|
168
|
+
`Template '${name}' does not apply to slice kind '${sliceKind}'`
|
|
169
|
+
];
|
|
170
|
+
}
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
function defaultScopes(kind, metadata) {
|
|
174
|
+
switch(kind){
|
|
175
|
+
case TemplateCatalogKind.Layout:
|
|
176
|
+
return [
|
|
177
|
+
TemplateScope.Application
|
|
178
|
+
];
|
|
179
|
+
case TemplateCatalogKind.DialogTemplate:
|
|
180
|
+
return [
|
|
181
|
+
TemplateScope.Slice
|
|
182
|
+
];
|
|
183
|
+
default:
|
|
184
|
+
return metadata?.sliceKinds === undefined ? screenScopes : [
|
|
185
|
+
TemplateScope.Slice
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function defaultSliceKinds(kind) {
|
|
190
|
+
return kind === TemplateCatalogKind.DialogTemplate ? dialogSliceKinds : screenSliceKinds;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export { applicableTemplates, validateDialogTemplateForTarget, validateLayoutForTarget, validateScreenTemplateForTarget };
|
|
194
|
+
//# sourceMappingURL=applicableTemplates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applicableTemplates.js","sources":["../../../templates/applicableTemplates.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DialogTemplate, Layout, ScreenTemplate, TemplateMetadata, TemplateReference, TemplateReferenceSource, TemplateScope, SliceKind } from '@cratis/scene.model';\nimport { resolveScreenTemplates } from '../resolveScreenTemplates';\nimport { validateDialogTemplateApplicability, validateLayoutApplicability, validateScreenTemplateApplicability } from '../templateApplicability';\nimport { ApplicableBlueprint, ApplicableTemplate, ApplicableTemplateGroup, ApplicableTemplateSet } from './ApplicableTemplateSet';\nimport { TemplateCatalogKind } from './TemplateCatalogKind';\nimport { TemplateLibrary } from './TemplateLibrary';\nimport { TemplateSource } from './TemplateSource';\nimport { TemplateTarget } from './TemplateTarget';\n\nconst screenScopes = [TemplateScope.Module, TemplateScope.Feature, TemplateScope.Subfeature];\nconst dialogSliceKinds = [SliceKind.StateChange];\nconst screenSliceKinds = [SliceKind.StateChange, SliceKind.StateView];\n\n/**\n * Decides which templates a picker offers at a target, so no host re-implements the rules: own templates by\n * category, then each blueprint that has at least one applicable template. A blueprint with none is omitted.\n *\n * It composes the applicability validators (kind and scope, explicit scopes override, category never implies a\n * scope, slot fit against the container) and `resolveScreenTemplates` (a template must find exactly one home and\n * nothing may nest inside itself) with the defaults of each hierarchy level, used when a template declares no scopes:\n *\n * - Application - layouts.\n * - Module, Feature, Subfeature - screen templates, fitting a slot of the container.\n * - Slice, state change - dialog templates.\n * - Slice, state view - screen templates that declare the Slice scope or state view slice kinds.\n *\n * Declared `scopes` and `sliceKinds` always override the defaults. The C# engine (`ApplicableTemplates.Compute`)\n * returns identical results; both are asserted against `template-applicability-fixtures.json`.\n */\nexport function applicableTemplates(library: TemplateLibrary, target: TemplateTarget): ApplicableTemplateSet {\n const own = library.own ? groupByCategory(applicableIn(library.own, target, false)) : [];\n const blueprints: ApplicableBlueprint[] = [];\n for (const source of library.blueprints) {\n const categories = groupByCategory(applicableIn(source, target, true));\n if (categories.length > 0) {\n blueprints.push({ blueprint: source.manifest.name, version: source.manifest.version, displayName: source.manifest.displayName, categories });\n }\n }\n return { own, blueprints };\n}\n\n/** Why a layout does not apply at a target; empty when it does. */\nexport function validateLayoutForTarget(layout: Layout, target: TemplateTarget): string[] {\n return withDefaults(validateLayoutApplicability(layout, target.scope), layout.name, TemplateCatalogKind.Layout, layout.metadata, target);\n}\n\n/** Why a screen template does not apply at a target, including whether its slot nesting resolves; empty when it does. */\nexport function validateScreenTemplateForTarget(template: ScreenTemplate, target: TemplateTarget): string[] {\n const problems = withDefaults(\n validateScreenTemplateApplicability(template, target.scope, target.container),\n template.name,\n TemplateCatalogKind.ScreenTemplate,\n template.metadata,\n target,\n );\n if (problems.length > 0) return problems;\n\n if (target.chain?.includes(template.name)) {\n return [`Template '${template.name}' is already chosen above this target; nesting it again would make the chain loop`];\n }\n\n if (template.fitsSlot !== undefined && target.container) {\n const containerName = target.container.name;\n const resolution = resolveScreenTemplates({ name: containerName, slots: target.container.slots } as Layout, [template]);\n const valid = resolution.unplaced.length === 0 && resolution.cycles.length === 0;\n if (!valid || !resolution.placements.some(placement => placement.template === template.name && placement.container === containerName)) {\n return [`Template '${template.name}' cannot be placed in '${containerName}': its slot nesting does not resolve`];\n }\n }\n return [];\n}\n\n/** Why a dialog template does not apply at a target; empty when it does. */\nexport function validateDialogTemplateForTarget(template: DialogTemplate, target: TemplateTarget): string[] {\n return withDefaults(validateDialogTemplateApplicability(template, target.scope), template.name, TemplateCatalogKind.DialogTemplate, template.metadata, target);\n}\n\nfunction applicableIn(source: TemplateSource, target: TemplateTarget, isBlueprint: boolean): ApplicableTemplate[] {\n const { manifest } = source;\n const referenceTo = (name: string): TemplateReference => isBlueprint\n ? { source: TemplateReferenceSource.Blueprint, id: name, blueprint: manifest.name, version: `^${manifest.version}` }\n : { source: TemplateReferenceSource.Own, id: name };\n\n const applicable: ApplicableTemplate[] = [];\n for (const layout of source.layouts ?? []) {\n if (validateLayoutForTarget(layout, target).length > 0) continue;\n applicable.push({\n package: manifest.name, packageVersion: manifest.version, kind: TemplateCatalogKind.Layout, name: layout.name,\n metadata: layout.metadata, reference: referenceTo(layout.name),\n });\n }\n for (const template of source.screenTemplates ?? []) {\n if (validateScreenTemplateForTarget(template, target).length > 0) continue;\n applicable.push({\n package: manifest.name, packageVersion: manifest.version, kind: TemplateCatalogKind.ScreenTemplate, name: template.name,\n displayName: template.displayName, description: template.description, metadata: template.metadata, reference: referenceTo(template.name),\n });\n }\n for (const template of source.dialogTemplates ?? []) {\n if (validateDialogTemplateForTarget(template, target).length > 0) continue;\n applicable.push({\n package: manifest.name, packageVersion: manifest.version, kind: TemplateCatalogKind.DialogTemplate, name: template.name,\n displayName: template.displayName, description: template.description, metadata: template.metadata, reference: referenceTo(template.name),\n });\n }\n return applicable;\n}\n\nfunction groupByCategory(templates: ApplicableTemplate[]): ApplicableTemplateGroup[] {\n const categoryOf = (template: ApplicableTemplate) => template.metadata?.category?.trim() ? template.metadata.category : undefined;\n const categories = [...new Set(templates.map(categoryOf).filter((category): category is string => category !== undefined))];\n const groups: ApplicableTemplateGroup[] = categories.map(category => ({ category, templates: templates.filter(template => categoryOf(template) === category) }));\n const uncategorized = templates.filter(template => categoryOf(template) === undefined);\n if (uncategorized.length > 0) groups.push({ templates: uncategorized });\n return groups;\n}\n\nfunction withDefaults(problems: string[], name: string, kind: TemplateCatalogKind, metadata: TemplateMetadata | undefined, target: TemplateTarget): string[] {\n if (problems.length > 0 || !Object.values(TemplateScope).includes(target.scope)) return problems;\n\n if (metadata?.scopes === undefined && !defaultScopes(kind, metadata).includes(target.scope)) {\n return [`Template '${name}' is not offered at scope '${target.scope}' unless it declares that scope`];\n }\n\n if (target.scope === TemplateScope.Slice && target.sliceKind !== undefined) {\n const sliceKind = target.sliceKind;\n if (!Object.values(SliceKind).includes(sliceKind)) return [`Template '${name}' has unknown target slice kind '${sliceKind}'`];\n if (sliceKind === SliceKind.Automation) return [`Template '${name}' cannot be applied to an Automation slice, which has no presentation`];\n const kinds = metadata?.sliceKinds ?? defaultSliceKinds(kind);\n if (!kinds.includes(sliceKind)) return [`Template '${name}' does not apply to slice kind '${sliceKind}'`];\n }\n return [];\n}\n\nfunction defaultScopes(kind: TemplateCatalogKind, metadata: TemplateMetadata | undefined): TemplateScope[] {\n switch (kind) {\n case TemplateCatalogKind.Layout: return [TemplateScope.Application];\n case TemplateCatalogKind.DialogTemplate: return [TemplateScope.Slice];\n default: return metadata?.sliceKinds === undefined ? screenScopes : [TemplateScope.Slice];\n }\n}\n\nfunction defaultSliceKinds(kind: TemplateCatalogKind): SliceKind[] {\n return kind === TemplateCatalogKind.DialogTemplate ? dialogSliceKinds : screenSliceKinds;\n}\n"],"names":["screenScopes","TemplateScope","Module","Feature","Subfeature","dialogSliceKinds","SliceKind","StateChange","screenSliceKinds","StateView","applicableTemplates","library","target","own","groupByCategory","applicableIn","blueprints","source","categories","length","push","blueprint","manifest","name","version","displayName","validateLayoutForTarget","layout","withDefaults","validateLayoutApplicability","scope","TemplateCatalogKind","Layout","metadata","validateScreenTemplateForTarget","template","problems","validateScreenTemplateApplicability","container","ScreenTemplate","chain","includes","fitsSlot","undefined","containerName","resolution","resolveScreenTemplates","slots","valid","unplaced","cycles","placements","some","placement","validateDialogTemplateForTarget","validateDialogTemplateApplicability","DialogTemplate","isBlueprint","referenceTo","TemplateReferenceSource","Blueprint","id","Own","applicable","layouts","package","packageVersion","kind","reference","screenTemplates","description","dialogTemplates","templates","categoryOf","category","trim","Set","map","filter","groups","uncategorized","Object","values","scopes","defaultScopes","Slice","sliceKind","Automation","kinds","sliceKinds","defaultSliceKinds","Application"],"mappings":";;;;;AAAA;AACA;AAWA,MAAMA,YAAAA,GAAe;AAACC,IAAAA,aAAAA,CAAcC,MAAM;AAAED,IAAAA,aAAAA,CAAcE,OAAO;AAAEF,IAAAA,aAAAA,CAAcG;AAAW,CAAA;AAC5F,MAAMC,gBAAAA,GAAmB;AAACC,IAAAA,SAAAA,CAAUC;AAAY,CAAA;AAChD,MAAMC,gBAAAA,GAAmB;AAACF,IAAAA,SAAAA,CAAUC,WAAW;AAAED,IAAAA,SAAAA,CAAUG;AAAU,CAAA;AAErE;;;;;;;;;;;;;;;AAeC,IACM,SAASC,mBAAAA,CAAoBC,OAAwB,EAAEC,MAAsB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YAAE,OAAO;AAACvD,gBAAAA,aAAAA,CAAcoF;AAAM,aAAA;AACrE,QAAA;YAAS,OAAOpD,QAAAA,EAAUwD,UAAAA,KAAe9C,SAAAA,GAAY3C,YAAAA,GAAe;AAACC,gBAAAA,aAAAA,CAAcoF;AAAM,aAAA;AAC7F;AACJ;AAEA,SAASK,kBAAkBvB,IAAyB,EAAA;AAChD,IAAA,OAAOA,IAAAA,KAASpC,mBAAAA,CAAoByB,cAAc,GAAGnD,gBAAAA,GAAmBG,gBAAAA;AAC5E;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"describeTemplateCatalog.d.ts","sourceRoot":"","sources":["../../../templates/describeTemplateCatalog.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"describeTemplateCatalog.d.ts","sourceRoot":"","sources":["../../../templates/describeTemplateCatalog.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAalD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,oBAAoB,EAAE,CA2ChH"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { PackageKind } from '@cratis/scene.model';
|
|
1
2
|
import { isVersionSatisfiedBy } from '../packageVersionRange.js';
|
|
2
3
|
import { TemplateCatalogKind } from './TemplateCatalogKind.js';
|
|
3
|
-
import { validateTemplateMetadata } from './validateTemplateMetadata.js';
|
|
4
|
+
import { validateTemplateMetadata, validateTemplateCategory } from './validateTemplateMetadata.js';
|
|
4
5
|
|
|
5
6
|
// Copyright (c) Cratis. All rights reserved.
|
|
6
7
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
@@ -10,7 +11,8 @@ import { validateTemplateMetadata } from './validateTemplateMetadata.js';
|
|
|
10
11
|
*
|
|
11
12
|
* A template is compatible when its metadata is complete and valid, the Scene version (when given) satisfies
|
|
12
13
|
* its Scene range, and every package it requires is among the given packages at a satisfying version and is
|
|
13
|
-
* either its own package or one that package depends on.
|
|
14
|
+
* either its own package or one that package depends on. A blueprint template without a category is a problem; an
|
|
15
|
+
* own template without one is a warning. Nothing is filtered out: a browser shows incompatible
|
|
14
16
|
* templates with their problems rather than hiding why they are unavailable.
|
|
15
17
|
*/ function describeTemplateCatalog(sources, sceneVersion) {
|
|
16
18
|
const versions = new Map(sources.map((source)=>[
|
|
@@ -36,10 +38,11 @@ import { validateTemplateMetadata } from './validateTemplateMetadata.js';
|
|
|
36
38
|
for (const { kind, template } of templates){
|
|
37
39
|
const metadata = template.metadata;
|
|
38
40
|
const describable = template;
|
|
39
|
-
const problems =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const problems = validateTemplateMetadata(template.name, metadata);
|
|
42
|
+
const warnings = [];
|
|
43
|
+
const missingCategory = validateTemplateCategory(template.name, metadata);
|
|
44
|
+
if (missingCategory) (source.manifest.kind === PackageKind.Blueprint ? problems : warnings).push(missingCategory);
|
|
45
|
+
problems.push(...requirementProblems(template.name, metadata, source.manifest, versions, sceneVersion));
|
|
43
46
|
entries.push({
|
|
44
47
|
package: source.manifest.name,
|
|
45
48
|
packageVersion: source.manifest.version,
|
|
@@ -50,12 +53,14 @@ import { validateTemplateMetadata } from './validateTemplateMetadata.js';
|
|
|
50
53
|
type: metadata?.type,
|
|
51
54
|
category: metadata?.category,
|
|
52
55
|
scopes: metadata?.scopes,
|
|
56
|
+
sliceKinds: metadata?.sliceKinds,
|
|
53
57
|
compatibility: metadata?.compatibility,
|
|
54
58
|
attribution: metadata?.attribution,
|
|
55
59
|
license: metadata?.license,
|
|
56
60
|
licenseUrl: metadata?.licenseUrl,
|
|
57
61
|
compatible: problems.length === 0,
|
|
58
|
-
problems
|
|
62
|
+
problems,
|
|
63
|
+
warnings
|
|
59
64
|
});
|
|
60
65
|
}
|
|
61
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"describeTemplateCatalog.js","sources":["../../../templates/describeTemplateCatalog.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ScenePackage, TemplateMetadata } from '@cratis/scene.model';\nimport { isVersionSatisfiedBy } from '../packageVersionRange';\nimport { TemplateCatalogEntry } from './TemplateCatalogEntry';\nimport { TemplateCatalogKind } from './TemplateCatalogKind';\nimport { TemplateSource } from './TemplateSource';\nimport { validateTemplateMetadata } from './validateTemplateMetadata';\n\n/**\n * Describes every template the given packages provide, in package then layout, screen template, dialog\n * template order, with its compatibility, attribution and license metadata and whether it can be used.\n *\n * A template is compatible when its metadata is complete and valid, the Scene version (when given) satisfies\n * its Scene range, and every package it requires is among the given packages at a satisfying version and is\n * either its own package or one that package depends on. Nothing is filtered out: a browser shows incompatible\n * templates with their problems rather than hiding why they are unavailable.\n */\nexport function describeTemplateCatalog(sources: TemplateSource[], sceneVersion?: string): TemplateCatalogEntry[] {\n const versions = new Map(sources.map(source => [source.manifest.name, source.manifest.version]));\n const entries: TemplateCatalogEntry[] = [];\n\n for (const source of sources) {\n const templates = [\n ...(source.layouts ?? []).map(template => ({ kind: TemplateCatalogKind.Layout, template })),\n ...(source.screenTemplates ?? []).map(template => ({ kind: TemplateCatalogKind.ScreenTemplate, template })),\n ...(source.dialogTemplates ?? []).map(template => ({ kind: TemplateCatalogKind.DialogTemplate, template })),\n ];\n\n for (const { kind, template } of templates) {\n const metadata = template.metadata;\n const describable = template as { displayName?: string; description?: string };\n const problems = [
|
|
1
|
+
{"version":3,"file":"describeTemplateCatalog.js","sources":["../../../templates/describeTemplateCatalog.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { PackageKind, ScenePackage, TemplateMetadata } from '@cratis/scene.model';\nimport { isVersionSatisfiedBy } from '../packageVersionRange';\nimport { TemplateCatalogEntry } from './TemplateCatalogEntry';\nimport { TemplateCatalogKind } from './TemplateCatalogKind';\nimport { TemplateSource } from './TemplateSource';\nimport { validateTemplateCategory, validateTemplateMetadata } from './validateTemplateMetadata';\n\n/**\n * Describes every template the given packages provide, in package then layout, screen template, dialog\n * template order, with its compatibility, attribution and license metadata and whether it can be used.\n *\n * A template is compatible when its metadata is complete and valid, the Scene version (when given) satisfies\n * its Scene range, and every package it requires is among the given packages at a satisfying version and is\n * either its own package or one that package depends on. A blueprint template without a category is a problem; an\n * own template without one is a warning. Nothing is filtered out: a browser shows incompatible\n * templates with their problems rather than hiding why they are unavailable.\n */\nexport function describeTemplateCatalog(sources: TemplateSource[], sceneVersion?: string): TemplateCatalogEntry[] {\n const versions = new Map(sources.map(source => [source.manifest.name, source.manifest.version]));\n const entries: TemplateCatalogEntry[] = [];\n\n for (const source of sources) {\n const templates = [\n ...(source.layouts ?? []).map(template => ({ kind: TemplateCatalogKind.Layout, template })),\n ...(source.screenTemplates ?? []).map(template => ({ kind: TemplateCatalogKind.ScreenTemplate, template })),\n ...(source.dialogTemplates ?? []).map(template => ({ kind: TemplateCatalogKind.DialogTemplate, template })),\n ];\n\n for (const { kind, template } of templates) {\n const metadata = template.metadata;\n const describable = template as { displayName?: string; description?: string };\n const problems = validateTemplateMetadata(template.name, metadata);\n const warnings: string[] = [];\n const missingCategory = validateTemplateCategory(template.name, metadata);\n if (missingCategory) (source.manifest.kind === PackageKind.Blueprint ? problems : warnings).push(missingCategory);\n problems.push(...requirementProblems(template.name, metadata, source.manifest, versions, sceneVersion));\n\n entries.push({\n package: source.manifest.name,\n packageVersion: source.manifest.version,\n kind,\n name: template.name,\n displayName: describable.displayName,\n description: describable.description,\n type: metadata?.type,\n category: metadata?.category,\n scopes: metadata?.scopes,\n sliceKinds: metadata?.sliceKinds,\n compatibility: metadata?.compatibility,\n attribution: metadata?.attribution,\n license: metadata?.license,\n licenseUrl: metadata?.licenseUrl,\n compatible: problems.length === 0,\n problems,\n warnings,\n });\n }\n }\n\n return entries;\n}\n\nfunction requirementProblems(\n name: string,\n metadata: TemplateMetadata | undefined,\n owner: ScenePackage,\n versions: Map<string, string>,\n sceneVersion: string | undefined,\n): string[] {\n const problems: string[] = [];\n const compatibility = metadata?.compatibility;\n if (!compatibility) return problems;\n\n if (sceneVersion !== undefined && compatibility.scene?.trim() && !isVersionSatisfiedBy(sceneVersion, compatibility.scene)) {\n problems.push(`Template '${name}' requires Scene ${compatibility.scene} but the host runs ${sceneVersion}`);\n }\n\n for (const requirement of compatibility.packages ?? []) {\n if (!requirement.name?.trim()) continue;\n if (requirement.name !== owner.name && !owner.dependencies.some(dependency => dependency.name === requirement.name)) {\n problems.push(`Template '${name}' requires package '${requirement.name}', which its package '${owner.name}' does not depend on`);\n }\n\n const version = versions.get(requirement.name);\n if (version === undefined) {\n problems.push(`Template '${name}' requires package '${requirement.name}', which is not available`);\n } else if (!isVersionSatisfiedBy(version, requirement.versionRange)) {\n problems.push(`Template '${name}' requires package '${requirement.name}' ${requirement.versionRange} but version ${version} is available`);\n }\n }\n\n return problems;\n}\n"],"names":["describeTemplateCatalog","sources","sceneVersion","versions","Map","map","source","manifest","name","version","entries","templates","layouts","template","kind","TemplateCatalogKind","Layout","screenTemplates","ScreenTemplate","dialogTemplates","DialogTemplate","metadata","describable","problems","validateTemplateMetadata","warnings","missingCategory","validateTemplateCategory","PackageKind","Blueprint","push","requirementProblems","package","packageVersion","displayName","description","type","category","scopes","sliceKinds","compatibility","attribution","license","licenseUrl","compatible","length","owner","undefined","scene","trim","isVersionSatisfiedBy","requirement","packages","dependencies","some","dependency","get","versionRange"],"mappings":";;;;;AAAA;AACA;AASA;;;;;;;;;AASC,IACM,SAASA,uBAAAA,CAAwBC,OAAyB,EAAEC,YAAqB,EAAA;AACpF,IAAA,MAA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,CAAK,oBAAoB,EAAE2C,WAAAA,CAAY3C,IAAI,CAAC,yBAAyB,CAAC,CAAA;AACrG,QAAA,CAAA,MAAO,IAAI,CAAC0C,oBAAAA,CAAqBzC,OAAAA,EAAS0C,WAAAA,CAAYM,YAAY,CAAA,EAAG;YACjElC,QAAAA,CAASO,IAAI,CAAC,CAAC,UAAU,EAAEtB,IAAAA,CAAK,oBAAoB,EAAE2C,WAAAA,CAAY3C,IAAI,CAAC,EAAE,EAAE2C,YAAYM,YAAY,CAAC,aAAa,EAAEhD,OAAAA,CAAQ,aAAa,CAAC,CAAA;AAC7I,QAAA;AACJ,IAAA;IAEA,OAAOc,QAAAA;AACX;;"}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
export * from './ApplicableTemplateSet';
|
|
1
2
|
export * from './TemplateCatalogEntry';
|
|
2
3
|
export * from './TemplateCatalogKind';
|
|
4
|
+
export * from './TemplateLibrary';
|
|
5
|
+
export * from './TemplateReferenceResolution';
|
|
3
6
|
export * from './TemplateSource';
|
|
7
|
+
export * from './TemplateTarget';
|
|
8
|
+
export * from './applicableTemplates';
|
|
4
9
|
export * from './describeTemplateCatalog';
|
|
10
|
+
export * from './resolveTemplateReference';
|
|
5
11
|
export * from './templateMetadataRules';
|
|
6
12
|
export * from './validateTemplateMetadata';
|
|
7
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../templates/index.ts"],"names":[],"mappings":"AAGA,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../templates/index.ts"],"names":[],"mappings":"AAGA,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC"}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
export * from './ApplicableTemplateSet';
|
|
1
2
|
export * from './TemplateCatalogEntry';
|
|
2
3
|
export * from './TemplateCatalogKind';
|
|
4
|
+
export * from './TemplateLibrary';
|
|
5
|
+
export * from './TemplateReferenceResolution';
|
|
3
6
|
export * from './TemplateSource';
|
|
7
|
+
export * from './TemplateTarget';
|
|
8
|
+
export * from './applicableTemplates';
|
|
4
9
|
export * from './describeTemplateCatalog';
|
|
10
|
+
export * from './resolveTemplateReference';
|
|
5
11
|
export * from './templateMetadataRules';
|
|
6
12
|
export * from './validateTemplateMetadata';
|
|
7
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../templates/index.ts"],"names":[],"mappings":"AAGA,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../templates/index.ts"],"names":[],"mappings":"AAGA,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TemplateReference } from '@cratis/scene.model';
|
|
2
|
+
import { TemplateLibrary } from './TemplateLibrary';
|
|
3
|
+
import { TemplateReferenceResolution } from './TemplateReferenceResolution';
|
|
4
|
+
export declare function resolveTemplateReference(reference: TemplateReference, library: TemplateLibrary): TemplateReferenceResolution;
|
|
5
|
+
//# sourceMappingURL=resolveTemplateReference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveTemplateReference.d.ts","sourceRoot":"","sources":["../../../templates/resolveTemplateReference.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAA2B,MAAM,qBAAqB,CAAC;AAGjF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,2BAA2B,EAA2B,MAAM,+BAA+B,CAAC;AAQrG,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,iBAAiB,EAAE,OAAO,EAAE,eAAe,GAAG,2BAA2B,CAsC5H"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { TemplateReferenceSource } from '@cratis/scene.model';
|
|
2
|
+
import { isValidVersionRange, isVersionSatisfiedBy } from '../packageVersionRange.js';
|
|
3
|
+
import { TemplateCatalogKind } from './TemplateCatalogKind.js';
|
|
4
|
+
import { TemplateReferenceStatus } from './TemplateReferenceResolution.js';
|
|
5
|
+
|
|
6
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
7
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
8
|
+
/**
|
|
9
|
+
* Resolves a template reference against the templates that exist, including the blueprint version pin. The C#
|
|
10
|
+
* engine (`TemplateReferenceResolver.Resolve`) reports the same outcomes and messages; both are asserted against
|
|
11
|
+
* `template-applicability-fixtures.json`.
|
|
12
|
+
*/ function resolveTemplateReference(reference, library) {
|
|
13
|
+
if (!reference.id?.trim()) {
|
|
14
|
+
return {
|
|
15
|
+
status: TemplateReferenceStatus.Malformed,
|
|
16
|
+
message: 'A template reference must name a template'
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (reference.source === TemplateReferenceSource.Own) {
|
|
20
|
+
if (reference.blueprint !== undefined || reference.version !== undefined) {
|
|
21
|
+
return {
|
|
22
|
+
status: TemplateReferenceStatus.Malformed,
|
|
23
|
+
message: `Own template reference '${reference.id}' must not name a blueprint or a version`
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return library.own ? find(reference.id, library.own, reference) : unknown(reference, undefined);
|
|
27
|
+
}
|
|
28
|
+
if (!reference.blueprint?.trim()) {
|
|
29
|
+
return {
|
|
30
|
+
status: TemplateReferenceStatus.Malformed,
|
|
31
|
+
message: `Blueprint template reference '${reference.id}' must name its blueprint`
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const blueprint = library.blueprints.find((source)=>source.manifest.name === reference.blueprint);
|
|
35
|
+
if (!blueprint) {
|
|
36
|
+
return {
|
|
37
|
+
status: TemplateReferenceStatus.UnknownBlueprint,
|
|
38
|
+
message: `Blueprint '${reference.blueprint}' referenced by template '${reference.id}' is not available`
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const installed = blueprint.manifest.version;
|
|
42
|
+
if (reference.version !== undefined) {
|
|
43
|
+
if (!isValidVersionRange(reference.version)) {
|
|
44
|
+
return {
|
|
45
|
+
status: TemplateReferenceStatus.Malformed,
|
|
46
|
+
package: blueprint.manifest.name,
|
|
47
|
+
packageVersion: installed,
|
|
48
|
+
message: `Template reference '${reference.id}' declares an invalid version range '${reference.version}'`
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (!isVersionSatisfiedBy(installed, reference.version)) {
|
|
52
|
+
return {
|
|
53
|
+
status: TemplateReferenceStatus.VersionNotSatisfied,
|
|
54
|
+
package: blueprint.manifest.name,
|
|
55
|
+
packageVersion: installed,
|
|
56
|
+
message: `Template '${reference.id}' was chosen from blueprint '${blueprint.manifest.name}' ${reference.version} but version ${installed} is installed`
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return find(reference.id, blueprint, reference);
|
|
61
|
+
}
|
|
62
|
+
function find(name, source, reference) {
|
|
63
|
+
const kind = kindOf(name, source);
|
|
64
|
+
return kind === undefined ? unknown(reference, source) : {
|
|
65
|
+
status: TemplateReferenceStatus.Resolved,
|
|
66
|
+
package: source.manifest.name,
|
|
67
|
+
packageVersion: source.manifest.version,
|
|
68
|
+
kind
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function unknown(reference, source) {
|
|
72
|
+
return {
|
|
73
|
+
status: TemplateReferenceStatus.UnknownTemplate,
|
|
74
|
+
package: source?.manifest.name,
|
|
75
|
+
packageVersion: source?.manifest.version,
|
|
76
|
+
message: reference.source === TemplateReferenceSource.Own ? `Own template '${reference.id}' does not exist` : `Blueprint '${reference.blueprint}' has no template '${reference.id}'`
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function kindOf(name, source) {
|
|
80
|
+
if (source.screenTemplates?.some((template)=>template.name === name)) return TemplateCatalogKind.ScreenTemplate;
|
|
81
|
+
if (source.dialogTemplates?.some((template)=>template.name === name)) return TemplateCatalogKind.DialogTemplate;
|
|
82
|
+
if (source.layouts?.some((layout)=>layout.name === name)) return TemplateCatalogKind.Layout;
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { resolveTemplateReference };
|
|
87
|
+
//# sourceMappingURL=resolveTemplateReference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveTemplateReference.js","sources":["../../../templates/resolveTemplateReference.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { TemplateReference, TemplateReferenceSource } from '@cratis/scene.model';\nimport { isValidVersionRange, isVersionSatisfiedBy } from '../packageVersionRange';\nimport { TemplateCatalogKind } from './TemplateCatalogKind';\nimport { TemplateLibrary } from './TemplateLibrary';\nimport { TemplateReferenceResolution, TemplateReferenceStatus } from './TemplateReferenceResolution';\nimport { TemplateSource } from './TemplateSource';\n\n/**\n * Resolves a template reference against the templates that exist, including the blueprint version pin. The C#\n * engine (`TemplateReferenceResolver.Resolve`) reports the same outcomes and messages; both are asserted against\n * `template-applicability-fixtures.json`.\n */\nexport function resolveTemplateReference(reference: TemplateReference, library: TemplateLibrary): TemplateReferenceResolution {\n if (!reference.id?.trim()) {\n return { status: TemplateReferenceStatus.Malformed, message: 'A template reference must name a template' };\n }\n\n if (reference.source === TemplateReferenceSource.Own) {\n if (reference.blueprint !== undefined || reference.version !== undefined) {\n return { status: TemplateReferenceStatus.Malformed, message: `Own template reference '${reference.id}' must not name a blueprint or a version` };\n }\n return library.own ? find(reference.id, library.own, reference) : unknown(reference, undefined);\n }\n\n if (!reference.blueprint?.trim()) {\n return { status: TemplateReferenceStatus.Malformed, message: `Blueprint template reference '${reference.id}' must name its blueprint` };\n }\n\n const blueprint = library.blueprints.find(source => source.manifest.name === reference.blueprint);\n if (!blueprint) {\n return { status: TemplateReferenceStatus.UnknownBlueprint, message: `Blueprint '${reference.blueprint}' referenced by template '${reference.id}' is not available` };\n }\n\n const installed = blueprint.manifest.version;\n if (reference.version !== undefined) {\n if (!isValidVersionRange(reference.version)) {\n return {\n status: TemplateReferenceStatus.Malformed, package: blueprint.manifest.name, packageVersion: installed,\n message: `Template reference '${reference.id}' declares an invalid version range '${reference.version}'`,\n };\n }\n if (!isVersionSatisfiedBy(installed, reference.version)) {\n return {\n status: TemplateReferenceStatus.VersionNotSatisfied, package: blueprint.manifest.name, packageVersion: installed,\n message: `Template '${reference.id}' was chosen from blueprint '${blueprint.manifest.name}' ${reference.version} but version ${installed} is installed`,\n };\n }\n }\n\n return find(reference.id, blueprint, reference);\n}\n\nfunction find(name: string, source: TemplateSource, reference: TemplateReference): TemplateReferenceResolution {\n const kind = kindOf(name, source);\n return kind === undefined\n ? unknown(reference, source)\n : { status: TemplateReferenceStatus.Resolved, package: source.manifest.name, packageVersion: source.manifest.version, kind };\n}\n\nfunction unknown(reference: TemplateReference, source: TemplateSource | undefined): TemplateReferenceResolution {\n return {\n status: TemplateReferenceStatus.UnknownTemplate,\n package: source?.manifest.name,\n packageVersion: source?.manifest.version,\n message: reference.source === TemplateReferenceSource.Own\n ? `Own template '${reference.id}' does not exist`\n : `Blueprint '${reference.blueprint}' has no template '${reference.id}'`,\n };\n}\n\nfunction kindOf(name: string, source: TemplateSource): TemplateCatalogKind | undefined {\n if (source.screenTemplates?.some(template => template.name === name)) return TemplateCatalogKind.ScreenTemplate;\n if (source.dialogTemplates?.some(template => template.name === name)) return TemplateCatalogKind.DialogTemplate;\n if (source.layouts?.some(layout => layout.name === name)) return TemplateCatalogKind.Layout;\n return undefined;\n}\n"],"names":["resolveTemplateReference","reference","library","id","trim","status","TemplateReferenceStatus","Malformed","message","source","TemplateReferenceSource","Own","blueprint","undefined","version","own","find","unknown","blueprints","manifest","name","UnknownBlueprint","installed","isValidVersionRange","package","packageVersion","isVersionSatisfiedBy","VersionNotSatisfied","kind","kindOf","Resolved","UnknownTemplate","screenTemplates","some","template","TemplateCatalogKind","ScreenTemplate","dialogTemplates","DialogTemplate","layouts","layout","Layout"],"mappings":";;;;;AAAA;AACA;AASA;;;;AAIC,IACM,SAASA,wBAAAA,CAAyBC,SAA4B,EAAEC,OAAwB,EAAA;AAC3F,IAAA,IAAI,CAACD,SAAAA,CAAUE,EAAE,EAAEC,IAAAA,EAAAA,EAAQ;QACvB,OAAO;AAAEC,YAAAA,MAAAA,EAAQC,wBAAwBC,SAAS;YAAEC,OAAAA,EAAS;AAA4C,SAAA;AAC7G,IAAA;AAEA,IAAA,IAAIP,SAAAA,CAAUQ,MAAM,KAAKC,uBAAAA,CAAwBC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from '@cratis/scene.model';
|
|
2
2
|
export declare function validateTemplateMetadata(name: string, metadata: TemplateMetadata | undefined): string[];
|
|
3
|
+
export declare const templateCategoryMissingCode = "templateCategoryMissing";
|
|
4
|
+
export declare function validateTemplateCategory(name: string, metadata: TemplateMetadata | undefined): string | undefined;
|
|
3
5
|
//# sourceMappingURL=validateTemplateMetadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateTemplateMetadata.d.ts","sourceRoot":"","sources":["../../../templates/validateTemplateMetadata.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AASvD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,GAAG,SAAS,GAAG,MAAM,EAAE,CA0CvG"}
|
|
1
|
+
{"version":3,"file":"validateTemplateMetadata.d.ts","sourceRoot":"","sources":["../../../templates/validateTemplateMetadata.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AASvD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,GAAG,SAAS,GAAG,MAAM,EAAE,CA0CvG;AAMD,eAAO,MAAM,2BAA2B,4BAA4B,CAAC;AAGrE,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAEjH"}
|
|
@@ -43,6 +43,13 @@ import { isAbsoluteHttpsUrl, isSpdxExpression } from './templateMetadataRules.js
|
|
|
43
43
|
}
|
|
44
44
|
return problems;
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* The diagnostic code reported for a template without a category. Category is required for blueprint templates
|
|
48
|
+
* (an error) and recommended for own templates (a warning).
|
|
49
|
+
*/ const templateCategoryMissingCode = 'templateCategoryMissing';
|
|
50
|
+
/** Checks that a template declares a browse category; returns the problem, or undefined when it does. */ function validateTemplateCategory(name, metadata) {
|
|
51
|
+
return metadata?.category?.trim() ? undefined : `Template '${name}' declares no category`;
|
|
52
|
+
}
|
|
46
53
|
|
|
47
|
-
export { validateTemplateMetadata };
|
|
54
|
+
export { templateCategoryMissingCode, validateTemplateCategory, validateTemplateMetadata };
|
|
48
55
|
//# sourceMappingURL=validateTemplateMetadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateTemplateMetadata.js","sources":["../../../templates/validateTemplateMetadata.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { TemplateMetadata } from '@cratis/scene.model';\nimport { isValidVersionRange } from '../packageVersionRange';\nimport { isAbsoluteHttpsUrl, isSpdxExpression } from './templateMetadataRules';\n\n/**\n * Checks that a template carries the compatibility, attribution and license metadata every shipped template\n * needs, and that each value is well formed. The C# engine (`TemplateMetadataValidation.Validate`) reports the\n * same problems in the same order; both are asserted against `template-metadata-fixtures.json`.\n */\nexport function validateTemplateMetadata(name: string, metadata: TemplateMetadata | undefined): string[] {\n const problems: string[] = [];\n const compatibility = metadata?.compatibility;\n\n if (!compatibility) {\n problems.push(`Template '${name}' declares no compatibility`);\n } else {\n if (!compatibility.scene?.trim()) {\n problems.push(`Template '${name}' declares no Scene version range`);\n } else if (!isValidVersionRange(compatibility.scene)) {\n problems.push(`Template '${name}' declares an invalid Scene version range '${compatibility.scene}'`);\n }\n\n for (const requirement of compatibility.packages ?? []) {\n if (!requirement.name?.trim()) {\n problems.push(`Template '${name}' declares a package requirement without a name`);\n } else if (!isValidVersionRange(requirement.versionRange)) {\n problems.push(`Template '${name}' declares an invalid version range '${requirement.versionRange}' for package '${requirement.name}'`);\n }\n }\n }\n\n const attribution = metadata?.attribution;\n if (!attribution?.author?.trim()) {\n problems.push(`Template '${name}' declares no author`);\n }\n\n if (attribution?.url !== undefined && !isAbsoluteHttpsUrl(attribution.url)) {\n problems.push(`Template '${name}' declares an attribution URL '${attribution.url}' that is not an absolute https URL`);\n }\n\n if (!metadata?.license?.trim()) {\n problems.push(`Template '${name}' declares no license`);\n } else if (!isSpdxExpression(metadata.license)) {\n problems.push(`Template '${name}' declares '${metadata.license}', which is not an SPDX license expression`);\n }\n\n if (metadata?.licenseUrl !== undefined && !isAbsoluteHttpsUrl(metadata.licenseUrl)) {\n problems.push(`Template '${name}' declares a license URL '${metadata.licenseUrl}' that is not an absolute https URL`);\n }\n\n return problems;\n}\n"],"names":["validateTemplateMetadata","name","metadata","problems","compatibility","push","scene","trim","isValidVersionRange","requirement","packages","versionRange","attribution","author","url","undefined","isAbsoluteHttpsUrl","license","isSpdxExpression","licenseUrl"],"mappings":";;;AAAA;AACA;AAMA;;;;AAIC,IACM,SAASA,wBAAAA,CAAyBC,IAAY,EAAEC,QAAsC,EAAA;AACzF,IAAA,MAAMC,WAAqB,EAAE;AAC7B,IAAA,MAAMC,gBAAgBF,QAAAA,EAAUE,aAAAA;AAEhC,IAAA,IAAI,CAACA,aAAAA,EAAe;AAChBD,QAAAA,QAAAA,CAASE,IAAI,CAAC,CAAC,UAAU,EAAEJ,IAAAA,CAAK,2BAA2B,CAAC,CAAA;IAChE,CAAA,MAAO;AACH,QAAA,IAAI,CAACG,aAAAA,CAAcE,KAAK,EAAEC,IAAAA,EAAAA,EAAQ;AAC9BJ,YAAAA,QAAAA,CAASE,IAAI,CAAC,CAAC,UAAU,EAAEJ,IAAAA,CAAK,iCAAiC,CAAC,CAAA;AACtE,QAAA,CAAA,MAAO,IAAI,CAACO,mBAAAA,CAAoBJ,aAAAA,CAAcE,KAAK,CAAA,EAAG;AAClDH,YAAAA,QAAAA,CAASE,IAAI,CAAC,CAAC,UAAU,EAAEJ,IAAAA,CAAK,2CAA2C,EAAEG,aAAAA,CAAcE,KAAK,CAAC,CAAC,CAAC,CAAA;AACvG,QAAA;AAEA,QAAA,KAAK,MAAMG,WAAAA,IAAeL,aAAAA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d,QAAAA,QAAAA,CAASE,IAAI,CAAC,CAAC,UAAU,EAAEJ,IAAAA,CAAK,YAAY,EAAEC,QAAAA,CAASe,OAAO,CAAC,0CAA0C,CAAC,CAAA;AAC9G,IAAA;AAEA,IAAA,IAAIf,UAAUiB,UAAAA,KAAeJ,SAAAA,IAAa,CAACC,kBAAAA,CAAmBd,QAAAA,CAASiB,UAAU,CAAA,EAAG;AAChFhB,QAAAA,QAAAA,CAASE,IAAI,CAAC,CAAC,UAAU,EAAEJ,IAAAA,CAAK,0BAA0B,EAAEC,QAAAA,CAASiB,UAAU,CAAC,mCAAmC,CAAC,CAAA;AACxH,IAAA;IAEA,OAAOhB,QAAAA;AACX;;"}
|
|
1
|
+
{"version":3,"file":"validateTemplateMetadata.js","sources":["../../../templates/validateTemplateMetadata.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { TemplateMetadata } from '@cratis/scene.model';\nimport { isValidVersionRange } from '../packageVersionRange';\nimport { isAbsoluteHttpsUrl, isSpdxExpression } from './templateMetadataRules';\n\n/**\n * Checks that a template carries the compatibility, attribution and license metadata every shipped template\n * needs, and that each value is well formed. The C# engine (`TemplateMetadataValidation.Validate`) reports the\n * same problems in the same order; both are asserted against `template-metadata-fixtures.json`.\n */\nexport function validateTemplateMetadata(name: string, metadata: TemplateMetadata | undefined): string[] {\n const problems: string[] = [];\n const compatibility = metadata?.compatibility;\n\n if (!compatibility) {\n problems.push(`Template '${name}' declares no compatibility`);\n } else {\n if (!compatibility.scene?.trim()) {\n problems.push(`Template '${name}' declares no Scene version range`);\n } else if (!isValidVersionRange(compatibility.scene)) {\n problems.push(`Template '${name}' declares an invalid Scene version range '${compatibility.scene}'`);\n }\n\n for (const requirement of compatibility.packages ?? []) {\n if (!requirement.name?.trim()) {\n problems.push(`Template '${name}' declares a package requirement without a name`);\n } else if (!isValidVersionRange(requirement.versionRange)) {\n problems.push(`Template '${name}' declares an invalid version range '${requirement.versionRange}' for package '${requirement.name}'`);\n }\n }\n }\n\n const attribution = metadata?.attribution;\n if (!attribution?.author?.trim()) {\n problems.push(`Template '${name}' declares no author`);\n }\n\n if (attribution?.url !== undefined && !isAbsoluteHttpsUrl(attribution.url)) {\n problems.push(`Template '${name}' declares an attribution URL '${attribution.url}' that is not an absolute https URL`);\n }\n\n if (!metadata?.license?.trim()) {\n problems.push(`Template '${name}' declares no license`);\n } else if (!isSpdxExpression(metadata.license)) {\n problems.push(`Template '${name}' declares '${metadata.license}', which is not an SPDX license expression`);\n }\n\n if (metadata?.licenseUrl !== undefined && !isAbsoluteHttpsUrl(metadata.licenseUrl)) {\n problems.push(`Template '${name}' declares a license URL '${metadata.licenseUrl}' that is not an absolute https URL`);\n }\n\n return problems;\n}\n\n/**\n * The diagnostic code reported for a template without a category. Category is required for blueprint templates\n * (an error) and recommended for own templates (a warning).\n */\nexport const templateCategoryMissingCode = 'templateCategoryMissing';\n\n/** Checks that a template declares a browse category; returns the problem, or undefined when it does. */\nexport function validateTemplateCategory(name: string, metadata: TemplateMetadata | undefined): string | undefined {\n return metadata?.category?.trim() ? undefined : `Template '${name}' declares no category`;\n}\n"],"names":["validateTemplateMetadata","name","metadata","problems","compatibility","push","scene","trim","isValidVersionRange","requirement","packages","versionRange","attribution","author","url","undefined","isAbsoluteHttpsUrl","license","isSpdxExpression","licenseUrl","templateCategoryMissingCode","validateTemplateCategory","category"],"mappings":";;;AAAA;AACA;AAMA;;;;AAIC,IACM,SAASA,wBAAAA,CAAyBC,IAAY,EAAEC,QAAsC,EAAA;AACzF,IAAA,MAAMC,WAAqB,EAAE;AAC7B,IAAA,MAAMC,gBAAgBF,QAAAA,EAAUE,aAAAA;AAEhC,IAAA,IAAI,CAACA,aAAAA,EAAe;AAChBD,QAAAA,QAAAA,CAASE,IAAI,CAAC,CAAC,UAAU,EAAEJ,IAAAA,CAAK,2BAA2B,CAAC,CAAA;IAChE,CAAA,MAAO;AACH,QAAA,IAAI,CA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