@datasworn/core
Version:
Typings and JSON schema common to Datasworn. This is a pre-release package, provided for developer feedback. It will almost certainly receive breaking changes.
46 lines (45 loc) • 2.35 kB
TypeScript
import type ObjectGlobber from './ObjectGlobber.js';
import type * as Id from '../Id/index.js';
import type CONST from '../IdElements/CONST.js';
export type PathForId<T extends Id.AnyId> = (T extends Id.RecursiveCollectionId ? RecursiveCollectionPath<T> : T extends Id.RecursiveCollectableId ? RecursiveCollectablePath<T> : T extends Id.NonRecursiveCollectionId ? NonRecursiveCollectionPath<T> : T extends Id.NonRecursiveCollectableId ? NonRecursiveCollectablePath<T> : T extends Id.NonCollectableId ? NonCollectablePath<T> : never) & PropertyKey[];
export type PathForType<T extends Id.Utils.AnyIdentified> = PathForId<Id.Utils.IdForType<T>>;
type RulesPackageIdWildcard = Id.RulesPackageId | typeof ObjectGlobber.WILDCARD;
type DictKeyWildcard = Id.DictKey | typeof ObjectGlobber.WILDCARD;
type DictKeyGlobstar = Id.DictKey | typeof ObjectGlobber.GLOBSTAR;
export type NonCollectablePath<T extends Id.NonCollectableId = Id.NonCollectableId> = [
RulesPackageIdWildcard,
Id.Utils.ExtractTypeElements<T>,
DictKeyWildcard
];
export type NonRecursiveCollectionPath<T extends Id.NonRecursiveCollectionId = Id.NonRecursiveCollectionId> = [
RulesPackageIdWildcard,
Id.Utils.ExtractCollectedTypeElement<T>,
DictKeyWildcard
];
export type NonRecursiveCollectablePath<T extends Id.NonRecursiveCollectableId = Id.NonRecursiveCollectableId> = [
RulesPackageIdWildcard,
Id.Utils.ExtractCollectableTypeElement<T>,
DictKeyWildcard,
CONST.ContentsKey,
DictKeyWildcard
];
type RecursiveCollectionKeys = [DictKeyGlobstar] | [DictKeyWildcard, CONST.CollectionsKey, DictKeyGlobstar] | [DictKeyGlobstar, CONST.CollectionsKey, DictKeyWildcard] | [DictKeyWildcard] | [DictKeyWildcard, CONST.CollectionsKey, DictKeyWildcard] | [
DictKeyWildcard,
CONST.CollectionsKey,
DictKeyWildcard,
CONST.CollectionsKey,
DictKeyWildcard
];
export type RecursiveCollectionPath<T extends Id.RecursiveCollectionId = Id.RecursiveCollectionId> = [
RulesPackageIdWildcard,
Id.Utils.ExtractCollectedTypeElement<T>,
...RecursiveCollectionKeys
];
export type RecursiveCollectablePath<T extends Id.RecursiveCollectableId = Id.RecursiveCollectableId> = [
RulesPackageIdWildcard,
Id.Utils.ExtractCollectableTypeElement<T>,
...RecursiveCollectionKeys,
CONST.ContentsKey,
DictKeyWildcard
];
export {};