mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 00:02:25 +00:00
The core layer lifecycle imported the whole Data Library manifest contract only to check the lib- prefix, so the layer-lifecycle package owned a feature module. The namespace rule (prefix, entry id pattern, the two id helpers) now lives in src/data/libraryLayerIds.js, which the lifecycle owns; the manifest contract imports and re-exports it, so library callers are unchanged.
23 lines
851 B
JavaScript
23 lines
851 B
JavaScript
/**
|
||
* The Data Library's layer namespace, owned by the layer lifecycle: the
|
||
* manager accepts a late registration only under `lib-<entry id>`, and the
|
||
* library names its layers with the same rule.
|
||
*/
|
||
|
||
/** A library entry id: lowercase, digits and hyphens, 3–48 characters. */
|
||
export const LIBRARY_ID_PATTERN = /^[a-z0-9][a-z0-9-]{2,47}$/;
|
||
export const LIBRARY_LAYER_PREFIX = 'lib-';
|
||
|
||
/** The manager id a library entry's layer registers under. */
|
||
export function libraryLayerId(entryId) {
|
||
return `${LIBRARY_LAYER_PREFIX}${entryId}`;
|
||
}
|
||
|
||
/** The entry id behind a library layer id, or null. */
|
||
export function libraryEntryIdOf(layerId) {
|
||
if (typeof layerId !== 'string' || !layerId.startsWith(LIBRARY_LAYER_PREFIX))
|
||
return null;
|
||
const id = layerId.slice(LIBRARY_LAYER_PREFIX.length);
|
||
return LIBRARY_ID_PATTERN.test(id) ? id : null;
|
||
}
|