diff --git a/pkg/nodejs/@datasworn/core/dist/Id/Utils.d.ts b/pkg/nodejs/@datasworn/core/dist/Id/Utils.d.ts index b61da5e83..5fdf81e8f 100644 --- a/pkg/nodejs/@datasworn/core/dist/Id/Utils.d.ts +++ b/pkg/nodejs/@datasworn/core/dist/Id/Utils.d.ts @@ -85,4 +85,6 @@ export type ExtractAncestorCollectionPathElements = T extends [infer U] ? U : T extends [...T[number][], infer U] ? U : never; +export type DropLast = T extends [T[number]] ? [] : T extends [...infer U extends T[number][], T[number]] ? U : never; export type { AnyCollectionType as AnyCollection, AnyCollectableType as AnyCollectable, NonCollectableType as AnyNonCollectable } from './TypeMaps.js'; diff --git a/pkg/nodejs/@datasworn/core/dist/Id/test.js b/pkg/nodejs/@datasworn/core/dist/Id/test.js index 8d635ea18..7f57ab5fc 100644 --- a/pkg/nodejs/@datasworn/core/dist/Id/test.js +++ b/pkg/nodejs/@datasworn/core/dist/Id/test.js @@ -1,17 +1,21 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const IdParser_js_1 = require("../IdParser.js"); -const recursiveCollectionId = 'sundered_isles/collections/oracles/core'; -const recursiveCollectableId = 'sundered_isles/oracles/core/action'; -const nonRecursiveCollectionId = 'starforged/collections/moves/combat'; -const nonRecursiveCollectableId = 'starforged/moves/combat/strike'; -const nonCollectableId = 'delve/site_themes/hallowed'; -const testParse = [ - IdParser_js_1.IdParser.from(recursiveCollectableId), - IdParser_js_1.IdParser.from(nonRecursiveCollectionId), - IdParser_js_1.IdParser.from(recursiveCollectionId), - IdParser_js_1.IdParser.from(nonRecursiveCollectableId), - IdParser_js_1.IdParser.from(nonCollectableId) -]; -for (const id of testParse) +const recursiveCollectionString = 'sundered_isles/collections/oracles/core'; +const recursiveCollectableString = 'sundered_isles/oracles/core/action'; +const nonRecursiveCollectionString = 'starforged/collections/moves/combat'; +const nonRecursiveCollectableString = 'starforged/moves/combat/strike'; +const nonCollectableString = 'delve/site_themes/hallowed'; +const recursiveCollectableId = IdParser_js_1.IdParser.from(recursiveCollectableString); +const nonRecursiveCollectionId = IdParser_js_1.IdParser.from(nonRecursiveCollectionString); +const recursiveCollectionId = IdParser_js_1.IdParser.from(recursiveCollectionString); +const nonRecursiveCollectableId = IdParser_js_1.IdParser.from(nonRecursiveCollectableString); +const nonCollectableId = IdParser_js_1.IdParser.from(nonCollectableString); +for (const id of [ + recursiveCollectableId, + recursiveCollectionId, + nonRecursiveCollectableId, + nonRecursiveCollectionId, + nonCollectableId +]) console.log(id.toString(), id.toPath().join('.')); diff --git a/pkg/nodejs/@datasworn/core/dist/IdParser.d.ts b/pkg/nodejs/@datasworn/core/dist/IdParser.d.ts index 9ffb4b994..2753d7e1b 100644 --- a/pkg/nodejs/@datasworn/core/dist/IdParser.d.ts +++ b/pkg/nodejs/@datasworn/core/dist/IdParser.d.ts @@ -4,7 +4,7 @@ import ObjectGlobber from './ObjectGlobPath/ObjectGlobber.js'; import type * as Strings from './Id/Strings.js'; import { type CollectableType, type CollectionSubtype, type TypeForTypeComposite } from './Id/TypeMaps.js'; import type * as Utils from './Id/Utils.js'; -type DataswornTree = Record | Map; +export type DataswornTree = Record | Map; /** * Creates, parses, and locates Datasworn IDs in the Datasworn tree. Id utilities are collected here as static methods. * @see @@ -159,8 +159,6 @@ declare namespace IdParser { }; type ToStringArray = [RulesPackage, ...TypeKeys, ...PathKeys]; type ToString = Utils.Join, CONST.Sep>; - type Last = T extends [infer U] ? U : T extends [...T[number][], infer U] ? U : never; - type DropLast = T extends [T[number]] ? [] : T extends [...infer U extends T[number][], T[number]] ? U : never; type AnyParsedId = IdParser.Parsed | IdParser.Parsed | IdParser.Parsed; } declare abstract class CollectionId extends IdParser = T extends `${infer RulesPackage}${CONST.Sep}${infer Type extends TypeElements.Collectable.Recursive}${infer AncestorPath extends `${CONST.Sep}${string}`}${CONST.Sep}${infer Key}` ? RecursiveCollectableId, Key> & { + type FromString = T extends `${infer RulesPackage}${CONST.Sep}${infer Type extends TypeElements.Collectable.Recursive}${CONST.Sep}${string}` ? RecursiveCollectableId, Utils.ExtractKey> & { id: T; } : never; } @@ -350,7 +348,7 @@ declare class RecursiveCollectionId, IdParser.Last>; + getParentCollectionId(): AncestorKeys extends [] ? never : RecursiveCollectionId, Utils.Last>; get canHaveCollectionChild(): AncestorKeys extends string[] & { length: 1 | 2; } ? true : false; diff --git a/src/pkg-core/Id/Utils.ts b/src/pkg-core/Id/Utils.ts index 7810fcc1d..3bb3e84fc 100644 --- a/src/pkg-core/Id/Utils.ts +++ b/src/pkg-core/Id/Utils.ts @@ -437,6 +437,19 @@ export type ExtractAncestorCollectionPathElements< ? U : never +export type Last = T extends [infer U] + ? U + : T extends [...T[number][], infer U] + ? U + : never + +export type DropLast = T extends [T[number]] + ? [] + : T extends [...infer U extends T[number][], T[number]] + ? U + : never + + type fff = ExtractAncestorPathElements<'sundered_isles/oracles/core/action'> export type { diff --git a/src/pkg-core/Id/test.ts b/src/pkg-core/Id/test.ts index bdc7d96da..576884252 100644 --- a/src/pkg-core/Id/test.ts +++ b/src/pkg-core/Id/test.ts @@ -1,23 +1,30 @@ import type * as Strings from './Strings.js' import { IdParser } from '../IdParser.js' -const recursiveCollectionId = +const recursiveCollectionString = 'sundered_isles/collections/oracles/core' satisfies Strings.RecursiveCollectionId -const recursiveCollectableId = +const recursiveCollectableString = 'sundered_isles/oracles/core/action' satisfies Strings.RecursiveCollectableId -const nonRecursiveCollectionId = +const nonRecursiveCollectionString = 'starforged/collections/moves/combat' satisfies Strings.NonRecursiveCollectionId -const nonRecursiveCollectableId = +const nonRecursiveCollectableString = 'starforged/moves/combat/strike' satisfies Strings.NonRecursiveCollectableId -const nonCollectableId = +const nonCollectableString = 'delve/site_themes/hallowed' satisfies Strings.NonCollectableId -const testParse = [ - IdParser.from(recursiveCollectableId), - IdParser.from(nonRecursiveCollectionId), - IdParser.from(recursiveCollectionId), - IdParser.from(nonRecursiveCollectableId), - IdParser.from(nonCollectableId) -] -for (const id of testParse) console.log(id.toString(), id.toPath().join('.')) +const recursiveCollectableId = IdParser.from(recursiveCollectableString) +const nonRecursiveCollectionId = IdParser.from(nonRecursiveCollectionString) +const recursiveCollectionId = IdParser.from(recursiveCollectionString) + +const nonRecursiveCollectableId = IdParser.from(nonRecursiveCollectableString) +const nonCollectableId = IdParser.from(nonCollectableString) + +for (const id of [ + recursiveCollectableId, + recursiveCollectionId, + nonRecursiveCollectableId, + nonRecursiveCollectionId, + nonCollectableId +]) + console.log(id.toString(), id.toPath().join('.')) diff --git a/src/pkg-core/IdParser.ts b/src/pkg-core/IdParser.ts index 796f98412..e568ac416 100644 --- a/src/pkg-core/IdParser.ts +++ b/src/pkg-core/IdParser.ts @@ -12,7 +12,7 @@ import { } from './Id/TypeMaps.js' import type * as Utils from './Id/Utils.js' -type DataswornTree = +export type DataswornTree = | Record | Map @@ -720,18 +720,6 @@ namespace IdParser { PathKeys extends Utils.AnyPathKeys > = Utils.Join, CONST.Sep> - export type Last = T extends [infer U] - ? U - : T extends [...T[number][], infer U] - ? U - : never - - export type DropLast = T extends [T[number]] - ? [] - : T extends [...infer U extends T[number][], T[number]] - ? U - : never - export type AnyParsedId = | IdParser.Parsed | IdParser.Parsed @@ -1052,13 +1040,12 @@ interface RecursiveCollectableId< namespace RecursiveCollectableId { export type FromString = T extends `${infer RulesPackage}${CONST.Sep}${infer Type extends - TypeElements.Collectable.Recursive}${infer AncestorPath extends - `${CONST.Sep}${string}`}${CONST.Sep}${infer Key}` + TypeElements.Collectable.Recursive}${CONST.Sep}${string}` ? RecursiveCollectableId< RulesPackage, Type, - Utils.Split, - Key + Utils.ExtractAncestorPathElements, + Utils.ExtractKey > & { id: T } @@ -1135,8 +1122,8 @@ class RecursiveCollectionId< const result = new RecursiveCollectionId< RulesPackage, Subtype, - IdParser.DropLast, - IdParser.Last + Utils.DropLast, + Utils.Last >(this.rulesPackage, this.subtype, ...(this.ancestorCollectionKeys as any)) return result as AncestorKeys extends [] ? never : typeof result