Skip to content

Commit

Permalink
Patch Restored DotPath v0.1.63
Browse files Browse the repository at this point in the history
  • Loading branch information
REllEK-IO committed May 9, 2024
1 parent 4e5770c commit a0e2927
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 22 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ When in doubt simplify.
* [Unified Turing Machine](https://github.com/Phuire-Research/Stratimux/blob/main/The-Unified-Turing-Machine.md) - The governing concept for this entire framework.

## Change Log ![Tests](https://github.com/Phuire-Research/Stratimux/actions/workflows/node.js.yml/badge.svg)
### **BREAKING** Strong Fast Lock Step v0.1.62
### Patch v0.1.62 5/09/2024
* Restored DotPath, a type used in the selector creators used to guide the creation of a dot path string.
### **BREAKING** Strong Fast Lock Step v0.1.62 5/08/2024
* Devised a means to ensure a lock step execution of incoming actions
* Due to each stage being ran once regardless of their selector being changed, some plans may receive the wrong value if not determining if that stage has been ran for the first time. See priority.test.ts for the example: if (changes.length > 0) {//}
* This also impacted the *axiumWaitForOpenThenIterate* helper function, but now works as intended via no longer checking for the latest lastStrategy change.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "stratimux",
"license": "GPL-3.0",
"version": "0.1.62",
"version": "0.1.63",
"description": "Unified Turing Machine",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ export {
createUnifiedKeyedSelector,
createAdvancedKeys,
select,
// DotPath
} from './model/selector';
export type {
DotPath
} from './model/dotPath';
export { PrincipleFunction, principle } from './model/principle';
export { createActionController$, actionController } from './model/actionController';
export type { dispatchOptions, Staging, UnifiedSubject, StagePlanner, NamedStagePlanner } from './model/stagePlanner';
Expand Down
183 changes: 183 additions & 0 deletions src/model/dotPath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*<$
For the asynchronous graph programming framework Stratimux, define the DotPath model file.
$>*/
/*<#*/
type Key = string | number | symbol;

type Join<L extends Key | undefined, R extends Key | undefined> = L extends
| string
| number
? R extends string | number
? `${L}.${R}`
: L
: R extends string | number
? R
: undefined;

type Union<
L extends unknown | undefined,
R extends unknown | undefined
> = L extends undefined
? R extends undefined
? undefined
: R
: R extends undefined
? L
: L | R;

// Use this type to define object types you want to skip (no path-scanning)
type ObjectsToIgnore = { new(...parms: any[]): any } | Date | Array<any>

type ValidObject<T> = T extends object
? T extends ObjectsToIgnore
? false & 1
: T
: false & 1;

export type DotPath<
T extends object,
Prev extends Key | undefined = undefined,
Path extends Key | undefined = undefined,
PrevTypes extends object = T
> = string &
{
[K in keyof T]:
// T[K] is a type already checked?
T[K] extends PrevTypes | T
// Return all previous paths.
? Union<Union<Prev, Path>, Join<Path, K>>
: // T[K] is an object?.
Required<T>[K] extends ValidObject<Required<T>[K]>
? // Continue extracting
DotPathOne<Required<T>[K], Union<Prev, Path>, Join<Path, K>, PrevTypes | T>
: // Return all previous paths, including current key.
Union<Union<Prev, Path>, Join<Path, K>>;
}[keyof T];

type DotPathOne<
T extends object,
Prev extends Key | undefined = undefined,
Path extends Key | undefined = undefined,
PrevTypes extends object = T
> = string &
{
[K in keyof T]:
T[K] extends PrevTypes | T
? Union<Union<Prev, Path>, Join<Path, K>>
:
Required<T>[K] extends ValidObject<Required<T>[K]>
?
DotPathTwo<Required<T>[K], Union<Prev, Path>, Join<Path, K>, PrevTypes | T>
:
Union<Union<Prev, Path>, Join<Path, K>>;
}[keyof T];

type DotPathTwo<
T extends object,
Prev extends Key | undefined = undefined,
Path extends Key | undefined = undefined,
PrevTypes extends object = T
> = string &
{
[K in keyof T]:
T[K] extends PrevTypes | T
? Union<Union<Prev, Path>, Join<Path, K>>
:
Required<T>[K] extends ValidObject<Required<T>[K]>
?
DotPathThree<Required<T>[K], Union<Prev, Path>, Join<Path, K>, PrevTypes | T>
:
Union<Union<Prev, Path>, Join<Path, K>>;
}[keyof T];

type DotPathThree<
T extends object,
Prev extends Key | undefined = undefined,
Path extends Key | undefined = undefined,
PrevTypes extends object = T
> = string &
{
[K in keyof T]:
T[K] extends PrevTypes | T
? Union<Union<Prev, Path>, Join<Path, K>>
:
Required<T>[K] extends ValidObject<Required<T>[K]>
?
DotPathFour<Required<T>[K], Union<Prev, Path>, Join<Path, K>, PrevTypes | T>
:
Union<Union<Prev, Path>, Join<Path, K>>;
}[keyof T];

type DotPathFour<
T extends object,
Prev extends Key | undefined = undefined,
Path extends Key | undefined = undefined,
PrevTypes extends object = T
> = string &
{
[K in keyof T]:
T[K] extends PrevTypes | T
? Union<Union<Prev, Path>, Join<Path, K>>
:
Required<T>[K] extends ValidObject<Required<T>[K]>
?
DotPathFive<Required<T>[K], Union<Prev, Path>, Join<Path, K>, PrevTypes | T>
:
Union<Union<Prev, Path>, Join<Path, K>>;
}[keyof T];

type DotPathFive<
T extends object,
Prev extends Key | undefined = undefined,
Path extends Key | undefined = undefined,
PrevTypes extends object = T
> = string &
{
[K in keyof T]:
T[K] extends PrevTypes | T
? Union<Union<Prev, Path>, Join<Path, K>>
:
Required<T>[K] extends ValidObject<Required<T>[K]>
?
DotPathSix<Required<T>[K], Union<Prev, Path>, Join<Path, K>, PrevTypes | T>
:
Union<Union<Prev, Path>, Join<Path, K>>;
}[keyof T];

type DotPathSix<
T extends object,
Prev extends Key | undefined = undefined,
Path extends Key | undefined = undefined,
PrevTypes extends object = T
> = string &
{
[K in keyof T]:
T[K] extends PrevTypes | T
? Union<Union<Prev, Path>, Join<Path, K>>
:
Required<T>[K] extends ValidObject<Required<T>[K]>
?
DotPathSevenEnd<Required<T>[K], Union<Prev, Path>, Join<Path, K>, PrevTypes | T>
:
Union<Union<Prev, Path>, Join<Path, K>>;
}[keyof T];

// Beyond this point will trigger TS excessively deep error or circular reference.
type DotPathSevenEnd<
T extends object,
Prev extends Key | undefined = undefined,
Path extends Key | undefined = undefined,
PrevTypes extends object = T
> = string &
{
[K in keyof T]:
T[K] extends PrevTypes | T
? Union<Union<Prev, Path>, Join<Path, K>>
:
Required<T>[K] extends ValidObject<Required<T>[K]>
?
Union<Union<Prev, Path>, Join<Path, K>>
:
Union<Union<Prev, Path>, Join<Path, K>>;
}[keyof T];
/*#>*/
37 changes: 20 additions & 17 deletions src/model/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ $>*/
/*<#*/
import { Action } from './action';
import { Concept, Concepts } from './concept';
import { DotPath } from './dotPath';

/**
* Will have such be a list of state keys separated by spaces until someone yells at me to change this.
Expand All @@ -18,41 +19,43 @@ export type KeyedSelector = {
setKeys?: (number | string)[]
setSelector?: SelectorFunction
};

/**
* Will create a new KeyedSelector based on a concept name comparison during runtime, mainly used for external usage
* @param keys - type string - Format is 'key0.key1.key3' for deep nested key values
* Originally used a DotPath<T> parameter to ease the developer experience, but recent versions made the approach unfeasible
*/
export const createConceptKeyedSelector = (conceptName: string, keys: string, setKeys?: (number|string)[]): KeyedSelector => {
const selectorBase = [conceptName, ...keys.split('.')];
if (setKeys) {
export const createConceptKeyedSelector =
<T extends object>(conceptName: string, keys: DotPath<T>, setKeys?: (number|string)[]): KeyedSelector => {
const selectorBase = [conceptName, ...keys.split('.')];
if (setKeys) {
return {
conceptName,
conceptSemaphore: -1,
keys: conceptName + '.' + keys,
selector: creation(selectorBase, selectorBase.length - 1, selectorBase.length) as SelectorFunction,
setKeys,
setSelector: setCreation(setKeys, setKeys.length - 1, setKeys.length)
};
}
return {
conceptName,
conceptSemaphore: -1,
keys: conceptName + '.' + keys,
selector: creation(selectorBase, selectorBase.length - 1, selectorBase.length) as SelectorFunction,
setKeys,
setSelector: setCreation(setKeys, setKeys.length - 1, setKeys.length)
setKeys
};
}
return {
conceptName,
conceptSemaphore: -1,
keys: conceptName + '.' + keys,
selector: creation(selectorBase, selectorBase.length - 1, selectorBase.length) as SelectorFunction,
setKeys
};
};

/**
* Will create a new KeyedSelector during runtime, for usage throughout Stratimux
* @param keys - type string - Format is 'key0.key1.key3' for deep nested key values
* Originally used a DotPath<T> parameter to ease the developer experience, but recent versions made the approach unfeasible
*/
export const createUnifiedKeyedSelector = (
export const createUnifiedKeyedSelector = <T extends object>(
concepts: Concepts,
semaphore: number,
keys: string,
keys: DotPath<T>,
setKeys?: (number | string)[]
): KeyedSelector | undefined => {
const concept = concepts[semaphore];
Expand Down Expand Up @@ -280,8 +283,8 @@ export function selectConcept(concepts: Concepts, name: string): Concept | undef
* @param arr a series of keys that points to your targeted slice
* @returns DotPath<T extends object>
*/
export function createAdvancedKeys(arr: unknown[]): string {
return arr.join('.') as string;
export function createAdvancedKeys<T extends object>(arr: unknown[]): DotPath<T> {
return arr.join('.') as DotPath<T>;
}

//createConceptKeyedSelector<{something: unknown}>('something', 'something.1' as DotPath<{something:unknown}>);
Expand Down
4 changes: 2 additions & 2 deletions src/test/selector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ test('Axium Unified Selector Test', (done) => {
const concepts: Concepts = {
0: experiment
};
const selector = select.createUnifiedKeyedSelector(concepts, 0, 'anything.something.somethingArray', [10, 9, 8, 7]);
const conceptSelector = select.createConceptKeyedSelector(experimentName, 'anything.something.somethingElse');
const selector = select.createUnifiedKeyedSelector<DeepNested>(concepts, 0, 'anything.something.somethingArray', [10, 9, 8, 7]);
const conceptSelector = select.createConceptKeyedSelector<DeepNested>(experimentName, 'anything.something.somethingElse');
if (selector) {
const slices = select.set<string[]>(concepts, selector);
console.log('CHECK SLICES', slices);
Expand Down

0 comments on commit a0e2927

Please sign in to comment.