Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | 2x 2x 2x 17x 4x 13x 13x 6x 7x 1x 1x 1x 3x 8x 8x 8x 9x 9x 8x 8x 8x 7x 1x 9x 9x 9x 9x 7x 9x 9x 9x 9x 9x 1x 8x 8x 9x 4x 8x 7x 7x 9x 4x 4x 9x | import { toUniqueStringArray } from '@src/utilities/array';
import {
ShaclValidationProfile,
ShaclValidationSettings,
generateProfileId,
} from '../shacl-validation-configuration';
/**
* The display name given to the profile created from the legacy `defaults` list.
*/
export const LEGACY_DEFAULT_PROFILE_NAME = 'Default';
/**
* The stable id of the profile created from the legacy `defaults` list.
*/
export const LEGACY_DEFAULT_PROFILE_ID = generateProfileId(LEGACY_DEFAULT_PROFILE_NAME, []);
/**
* The catch-all `includeFiles` entry that replaces the legacy "defaults apply
* everywhere" behavior: it matches every recognized RDF file in the workspace.
*/
export const LEGACY_DEFAULT_PATHS_KEY = '**/*';
/**
* Legacy per-graph include/exclude configuration (pre-profiles model).
*/
interface LegacyShaclGraphShapeConfiguration {
includeDefaults?: boolean;
includeShapes?: string[];
excludeShapes?: string[];
}
/**
* Legacy `mentor.shacl.validation` value (pre-profiles model): a flat list of
* default shape files plus per-graph include/exclude overrides.
*/
export interface LegacyShaclValidationConfiguration {
defaults?: string[];
graphs?: Record<string, LegacyShaclGraphShapeConfiguration>;
}
/**
* Returns true when a settings value uses the legacy `{ defaults, graphs }`
* shape rather than the profile-based `{ profiles }` shape.
*/
export function isLegacyShaclValidationConfig(value: unknown): value is LegacyShaclValidationConfiguration {
if (typeof value !== 'object' || value === null) {
return false;
}
const candidate = value as Record<string, unknown>;
if ('profiles' in candidate || 'documents' in candidate || 'paths' in candidate) {
return false;
}
return 'defaults' in candidate || 'graphs' in candidate;
}
/**
* Resolves the effective shapes of a legacy graph entry using the old
* include/exclude precedence (exclusions win over inclusions).
*/
function resolveLegacyEffectiveShapes(
defaults: readonly string[],
config: LegacyShaclGraphShapeConfiguration
): string[] {
const includeDefaults = config.includeDefaults !== false;
const exclude = new Set(toUniqueStringArray(config.excludeShapes));
const candidates = [
...(includeDefaults ? defaults : []),
...toUniqueStringArray(config.includeShapes),
];
return toUniqueStringArray(candidates.filter(shape => !exclude.has(shape)));
}
/**
* Converts a legacy graph key (a canonical `workspace:///...` URI, optionally
* `#fragment`-qualified) to the bare workspace-relative document key format.
* Non-workspace keys are kept unchanged and become inert entries.
*/
function toBareDocumentKey(key: string): string {
const match = /^workspace:\/{1,3}/.exec(key);
Iif (!match) {
return key;
}
const decode = (value: string) => {
try {
return decodeURIComponent(value);
} catch {
return value;
}
};
const rest = key.slice(match[0].length);
const hashIndex = rest.indexOf('#');
if (hashIndex < 0) {
return decode(rest);
}
return `${decode(rest.slice(0, hashIndex))}#${decode(rest.slice(hashIndex + 1))}`;
}
/**
* Converts a legacy `{ defaults, graphs }` configuration into the
* self-contained profile model (`{ profiles }`, each profile owning its
* `includeFiles`/`excludeFiles`):
*
* - A non-empty `defaults` list becomes a profile named "Default" with a
* catch-all `**\/*` include entry, preserving the "defaults apply
* everywhere" behavior.
* - Graph entries equivalent to implicit defaults behavior are dropped.
* - Entries that add shapes on top of the defaults become an auto profile
* named after the document's bare relative path, applied to exactly that
* path (the catch-all still contributes the defaults).
* - Entries that suppress the defaults (`includeDefaults: false` or
* exclusions) additionally append the document's path to the Default
* profile's `excludeFiles`; exclusions are fully resolved and frozen as the
* auto profile's shapes, since per-shape exclusion is not representable.
*/
export function migrateLegacyShaclValidationConfig(legacy: LegacyShaclValidationConfiguration): ShaclValidationSettings {
const profiles: Record<string, ShaclValidationProfile> = {};
const defaults = toUniqueStringArray(legacy.defaults);
const defaultExclusions: string[] = [];
if (defaults.length > 0) {
profiles[LEGACY_DEFAULT_PROFILE_ID] = {
name: LEGACY_DEFAULT_PROFILE_NAME,
shapes: defaults,
includeFiles: [LEGACY_DEFAULT_PATHS_KEY],
};
}
for (const [key, graphConfig] of Object.entries(legacy.graphs ?? {})) {
const includeDefaults = graphConfig?.includeDefaults !== false;
const includeShapes = toUniqueStringArray(graphConfig?.includeShapes);
const excludeShapes = toUniqueStringArray(graphConfig?.excludeShapes);
if (includeDefaults && includeShapes.length === 0 && excludeShapes.length === 0) {
// Implicit defaults behavior — covered by the catch-all Default profile.
continue;
}
const documentKey = toBareDocumentKey(key);
// Entries with exclusions freeze the fully-resolved selection; the defaults
// must then be suppressed for the document so they do not re-apply via the
// catch-all.
const shapes = excludeShapes.length > 0
? resolveLegacyEffectiveShapes(defaults, graphConfig)
: includeShapes;
if (defaults.length > 0 && (!includeDefaults || excludeShapes.length > 0)) {
defaultExclusions.push(documentKey);
}
if (shapes.length > 0) {
const id = generateProfileId(documentKey, Object.keys(profiles));
profiles[id] = { name: documentKey, shapes, includeFiles: [documentKey] };
}
}
if (defaultExclusions.length > 0) {
const defaultProfile = profiles[LEGACY_DEFAULT_PROFILE_ID];
defaultProfile.excludeFiles = [...(defaultProfile.excludeFiles ?? []), ...defaultExclusions];
}
return Object.keys(profiles).length > 0 ? { profiles } : {};
}
|