From 6aa80f485510ac14485583cd956228fd30683760 Mon Sep 17 00:00:00 2001 From: REllEK-IO Date: Mon, 13 May 2024 19:00:39 -0700 Subject: [PATCH] v0.1.66 --- Concept.md | 6 +- README.md | 5 + package.json | 2 +- src/concepts/axium/axium.principle.ts | 7 +- src/concepts/ownership/ownership.principle.ts | 2 +- src/model/action.ts | 106 ++++++++++-------- src/model/actionStrategy.ts | 67 ++++++----- src/model/principle.ts | 4 +- src/test/actionController.test.ts | 6 +- src/test/ownership.test.ts | 2 +- src/test/priority/priorityAction.test.ts | 16 +-- 11 files changed, 132 insertions(+), 91 deletions(-) diff --git a/Concept.md b/Concept.md index 4f480b6..2d43843 100644 --- a/Concept.md +++ b/Concept.md @@ -69,14 +69,14 @@ export type PrincipleFunction = ( observer: Subscriber, concepts: Concepts, concept$: UnifiedSubject, - semaphore: number + conceptSemaphore: number ) => void; export function createPrinciple$( principleFunc: PrincipleFunction, concepts: Concepts, concepts$: UnifiedSubject, - semaphore: number + conceptSemaphore: number ): Observable; ``` Concept's principle, governs a specific set of instructions that would allow for the functionality of other libraries not designed specifically for this system. Otherwise these act as action emitters of some value being watched off premise or subscribed to within the axium. @@ -91,7 +91,7 @@ As this functionality lacks the addition of some abstraction to hand hold the us Later we may create specific types of principles to handle the nuances of repeating the same functionality over and over again. But likewise that is not the scope of this release. -*Note the semaphore is specifically in utilization with "selectUnifiedState(concepts, semaphore)" to select your Concept's state regardless of its current state of unification.* +*Note the concept semaphore is specifically in utilization with "selectUnifiedState(concepts, semaphore)" to select your Concept's state regardless of its current state of unification.* ## Mode - The point of Recursion ```typescript diff --git a/README.md b/README.md index 292463c..f74b5cd 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,11 @@ 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** v0.1.66 5/13/2024 +* Revamped the Action Creator Functions to follow behind the current creator with an **options** parameter design choice. + * Note pure action creators will not provide an option for payload +* Cascaded priority to ActionStrategies to allow for planning priority ahead of time. +* Updated the PrincipleFunction documentation to have the semaphore parameter to now be conceptSemaphore. This allows for an easy drop in into the options parameter. ### v0.1.65 5/13/2024 * Removed one more level of deepness from DotPath(6 levels now), projects should now compile without the excessively deep error. ### v0.1.64 5/13/2024 diff --git a/package.json b/package.json index dd56004..84895ab 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "stratimux", "license": "GPL-3.0", - "version": "0.1.65", + "version": "0.1.66", "description": "Unified Turing Machine", "main": "dist/index.js", "module": "dist/index.mjs", diff --git a/src/concepts/axium/axium.principle.ts b/src/concepts/axium/axium.principle.ts index 273b64a..9116dd8 100644 --- a/src/concepts/axium/axium.principle.ts +++ b/src/concepts/axium/axium.principle.ts @@ -21,7 +21,7 @@ export const axiumPrinciple: PrincipleFunction = ( observer: Subscriber, concepts: Concepts, concepts$: UnifiedSubject, - semaphore: number + conceptSemaphore: number ) => { let allowAdd = true; let allowRemove = true; @@ -174,8 +174,9 @@ export const axiumPrinciple: PrincipleFunction = ( ]); observer.next(strategy.begin(strategy.create({ topic: 'Register Axium Add/Remove Plans', - initialNode: createActionNode(axiumRegisterStagePlanner({conceptName: axiumName, stagePlanner: addConceptsPlan}, semaphore), { - successNode: createActionNode(axiumRegisterStagePlanner({conceptName: axiumName, stagePlanner: removeConceptsPlan}, semaphore), { + initialNode: createActionNode(axiumRegisterStagePlanner({conceptName: axiumName, stagePlanner: addConceptsPlan}, {conceptSemaphore}), { + successNode: + createActionNode(axiumRegisterStagePlanner({conceptName: axiumName, stagePlanner: removeConceptsPlan}, {conceptSemaphore}), { successNode: null, failureNode: null }), diff --git a/src/concepts/ownership/ownership.principle.ts b/src/concepts/ownership/ownership.principle.ts index 71e7600..8def159 100644 --- a/src/concepts/ownership/ownership.principle.ts +++ b/src/concepts/ownership/ownership.principle.ts @@ -82,7 +82,7 @@ export const ownershipPrinciple: PrincipleFunction = ( } } if (payload.badActions.length > 0) { - newAction = createAction(axiumBadActionType, payload); + newAction = createAction(axiumBadActionType, {payload}); ownershipState.pendingActions = newPending; concepts$.next(concepts); observer.next(newAction); diff --git a/src/model/action.ts b/src/model/action.ts index 71cb140..e4edee0 100644 --- a/src/model/action.ts +++ b/src/model/action.ts @@ -32,6 +32,29 @@ export type Action = { priority?: number; }; +export type ActionOptions = { + semaphore?: [number, number, number, number]; + conceptSemaphore?: number; + strategy?: ActionStrategy; + keyedSelectors?: KeyedSelector[]; + agreement?: number; + expiration?: number; + axium?: string; + priority?: number; +}; + +export type ActionWithPayloadOptions = { + semaphore?: [number, number, number, number]; + conceptSemaphore?: number; + payload?: Record; + strategy?: ActionStrategy; + keyedSelectors?: KeyedSelector[]; + agreement?: number; + expiration?: number; + axium?: string; + priority?: number; +}; + const createPayload = >(payload: T) => payload; export function primeAction(concepts: Concepts, action: Action): Action { @@ -167,52 +190,50 @@ function getSpecialSemaphore(type: ActionType) { } } -export function createAction>( +export function createAction( type: ActionType, - payload?: T, - keyedSelectors?: KeyedSelector[], - agreement?: number, - _semaphore?: [number, number, number, number], - conceptSemaphore?: number, - priority?: number + options?: ActionWithPayloadOptions, ): Action { const special = getSpecialSemaphore(type); - const semaphore = _semaphore !== undefined ? _semaphore : [0, 0, -1, special] as [number, number, number, number]; - return { - type, - semaphore, - payload, - keyedSelectors, - agreement, - expiration: Date.now() + (agreement !== undefined ? agreement : 5000), - conceptSemaphore, - priority - }; + const semaphore = options?.semaphore !== undefined ? options.semaphore : [0, 0, -1, special] as [number, number, number, number]; + if (options) { + const { + payload, + keyedSelectors, + agreement, + conceptSemaphore, + priority + } = options; + return { + type, + semaphore, + payload, + keyedSelectors, + agreement, + expiration: Date.now() + (agreement !== undefined ? agreement : 5000), + conceptSemaphore, + priority + }; + } else { + return { + type, + semaphore, + expiration: Date.now() + 5000, + }; + } } export type ActionCreator = ( - conceptSemaphore?: number, - keyedSelectors?: KeyedSelector[], - agreement?: number, - qualitySemaphore?: [number, number, number, number] + options?: ActionOptions ) => Action; export function prepareActionCreator(actionType: ActionType) { return ( - conceptSemaphore?: number, - keyedSelectors?: KeyedSelector[], - agreement?: number, - qualitySemaphore?: [number, number, number, number], - priority?: number + options?: ActionOptions ) => { return createAction( actionType, - undefined, - keyedSelectors, - agreement, - qualitySemaphore, - conceptSemaphore, - priority + options ); }; } @@ -220,24 +241,21 @@ export function prepareActionCreator(actionType: ActionType) { export function prepareActionWithPayloadCreator>(actionType: ActionType) { return ( payload: T, - conceptSemaphore?: number, - keyedSelectors?: KeyedSelector[], - agreement?: number, - semaphore?: [number, number, number, number], - priority?: number + options?: ActionOptions ): Action => { + const opt: ActionWithPayloadOptions = { + ...options, + payload + }; return createAction( actionType, - payload, keyedSelectors, agreement, semaphore, conceptSemaphore, priority); + opt + ); }; } export type ActionCreatorWithPayload = ( payload: T, - conceptSemaphore?: number, - keyedSelectors?: KeyedSelector[], - agreement?: number, - semaphore?: [number, number, number, number], - priority?: number + options?: ActionWithPayloadOptions ) => Action; /** diff --git a/src/model/actionStrategy.ts b/src/model/actionStrategy.ts index 647a735..2613ebd 100644 --- a/src/model/actionStrategy.ts +++ b/src/model/actionStrategy.ts @@ -135,12 +135,14 @@ export const createActionNodeFromStrategy = (strategy: ActionStrategy): ActionNo } else { action = createAction( currentNode.actionType, - currentNode.payload, - currentNode.keyedSelectors, - currentNode.agreement, - currentNode.semaphore, - currentNode.conceptSemaphore, - currentNode.priority + { + payload: currentNode.payload, + keyedSelectors: currentNode.keyedSelectors, + agreement: currentNode.agreement, + semaphore: currentNode.semaphore, + conceptSemaphore: currentNode.conceptSemaphore, + priority: currentNode.priority + } ); } return createActionNode(action, { @@ -235,11 +237,17 @@ export function createStrategy( } export const strategyBegin = (strategy: ActionStrategy, data?: Record): Action => { + const currentNode = strategy.currentNode; strategy.currentNode.action = createAction( - strategy.currentNode.actionType, - strategy.currentNode.payload, - strategy.currentNode.keyedSelectors, - strategy.currentNode.agreement + currentNode.actionType, + { + payload: currentNode.payload, + keyedSelectors: currentNode.keyedSelectors, + agreement: currentNode.agreement, + semaphore: currentNode.semaphore, + conceptSemaphore: currentNode.conceptSemaphore, + priority: currentNode.priority + } ); strategy.currentNode.action.strategy = { ...strategy, @@ -273,11 +281,14 @@ export const strategySuccess = (_strategy: ActionStrategy, data?: Record { return new Observable(function (obs: Subscriber) { - principleFunc(obs, concepts, concepts$, semaphore); + principleFunc(obs, concepts, concepts$, conceptSemaphore); }); } diff --git a/src/test/actionController.test.ts b/src/test/actionController.test.ts index 94b6145..029e260 100644 --- a/src/test/actionController.test.ts +++ b/src/test/actionController.test.ts @@ -7,7 +7,7 @@ import { axiumBadActionType } from '../concepts/axium/qualities/badAction.quali import { axiumLog, axiumLogType } from '../concepts/axium/qualities/log.quality'; test('ActionController Expired Test', (done) => { - const act = axiumLog(undefined, undefined, 200); + const act = axiumLog({agreement: 200}); const cont = new ActionController(act); cont.subscribe(union => { expect(union[0].type).toBe(axiumBadActionType); @@ -16,7 +16,7 @@ test('ActionController Expired Test', (done) => { }); test('ActionController Next Test', (done) => { - const act = axiumLog(undefined, undefined, 200); + const act = axiumLog({agreement: 200}); const cont = new ActionController(act); cont.subscribe(union => { expect(union[0].type).toBe(axiumLogType); @@ -26,7 +26,7 @@ test('ActionController Next Test', (done) => { }); test('ActionController createActionController$ Test', (done) => { - const act = axiumLog(undefined, undefined, 200); + const act = axiumLog({agreement: 200}); const cont = createActionController$(act, (controller, action) => { controller.fire(action); }); diff --git a/src/test/ownership.test.ts b/src/test/ownership.test.ts index d8dfdd8..537880a 100644 --- a/src/test/ownership.test.ts +++ b/src/test/ownership.test.ts @@ -56,7 +56,7 @@ test('Ownership Test', (done) => { const ownership = selectState(cpts, ownershipName); if (ownership) { console.log('Stage 2', ownership.ownershipLedger, ownership.pendingActions); - dispatch(counterSetCount({newCount: 1000}, undefined, undefined, 7000), { iterateStage: true}); + dispatch(counterSetCount({newCount: 1000}, {agreement: 7000} ), { iterateStage: true}); } }), createStage((cpts, dispatch) => { diff --git a/src/test/priority/priorityAction.test.ts b/src/test/priority/priorityAction.test.ts index 383cabb..fb54b69 100644 --- a/src/test/priority/priorityAction.test.ts +++ b/src/test/priority/priorityAction.test.ts @@ -123,16 +123,16 @@ test('Priority Action Manual Test', (done) => { body.push(kick); const one = counterSetCount({ newCount: 1 - }, undefined, undefined, undefined, undefined, 100); + }, {priority: 100}); const two = counterSetCount({ newCount: 2 - }, undefined, undefined, undefined, undefined, 50); + }, {priority: 50}); const three = counterSetCount({ newCount: 3 - }, undefined, undefined, undefined, undefined, 75); + }, {priority: 75}); const four = counterSetCount({ newCount: 4 - }, undefined, undefined, undefined, undefined, 25); + }, {priority: 25}); handlePriority(axiumState, one); expect(body[0].type).toBe(one.type); expect(body[1].type).toBe(kick.type); @@ -162,16 +162,16 @@ test('Priority Action Close Test', (done) => { body.push(kick); const one = counterSetCount({ newCount: 1 - }, undefined, undefined, undefined, undefined, 100); + }, {priority: 100}); const two = counterSetCount({ newCount: 2 - }, undefined, undefined, undefined, undefined, 50); + }, {priority: 50}); const three = counterSetCount({ newCount: 3 - }, undefined, undefined, undefined, undefined, 75); + }, {priority: 75}); const four = counterSetCount({ newCount: 4 - }, undefined, undefined, undefined, undefined, 25); + }, {priority: 25}); handlePriority(axiumState, one); expect(body[0].type).toBe(one.type); expect(body[1].type).toBe(kick.type);