Skip to content

Commit

Permalink
Merge pull request #67 from Phuire-Research/ownershipExperiment
Browse files Browse the repository at this point in the history
Improved ticketing system for off premise, plus notes
  • Loading branch information
REllEK-IO authored Oct 5, 2023
2 parents 772616e + 44bd4e2 commit ccd7b70
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 32 deletions.
2 changes: 0 additions & 2 deletions SpatialOwnership.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ export type OwnershipState = {
initialized: boolean;
ownershipLedger: OwnershipLedger;
pendingActions: Action[],
ticker: number;
isResponsibleForMode: boolean;
}
```
* initialized - Value to control when your principles or external subscriptions should engage with the Ownership Concept. It simply notes when the principles are active.
* ownershipLedger - Is a simple map that use a key that is informed by a KeyedSelector and value that is a populated ownership ticket.
* ticker - Starting at 0, this will update for each ticket and stub relationship created within this system and corresponds to the ticket number value.
* isResponsibleForMode - The just in case your choose to implement your own mode that would require ownership, and can be set to false via the createOwnershipConcept function. Note that you must create your own initialization strategy to set your own Mode.
### Useful Ownership Qualities
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@phuire/strx",
"version": "0.0.17",
"version": "0.0.18",
"description": "Unified Turing Machine",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
9 changes: 6 additions & 3 deletions src/concepts/axium/axium.concept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export type NamedSubscriber = {
}

export type AxiumState = {
// Would be unique identifier on a network
name: string;
open: boolean;
logging: boolean;
dialog: string;
Expand All @@ -52,8 +54,9 @@ export type AxiumState = {

export const axiumName = 'axium';

const createAxiumState = (storeDialog?: boolean, logging?: boolean): AxiumState => {
const createAxiumState = (name: string, storeDialog?: boolean, logging?: boolean): AxiumState => {
return {
name,
open: false,
logging: logging ? logging : false,
dialog: '',
Expand All @@ -76,10 +79,10 @@ const createAxiumState = (storeDialog?: boolean, logging?: boolean): AxiumState
};
};

export const createAxiumConcept = (storeDialog?: boolean, logging?: boolean): Concept => {
export const createAxiumConcept = (name: string, storeDialog?: boolean, logging?: boolean): Concept => {
return createConcept(
axiumName,
createAxiumState(storeDialog, logging),
createAxiumState(name, storeDialog, logging),
[
openQuality,
badActionQuality,
Expand Down
2 changes: 0 additions & 2 deletions src/concepts/ownership/ownership.concept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type OwnershipState = {
initialized: boolean;
ownershipLedger: OwnershipLedger;
pendingActions: Action[],
ticker: number;
isResponsibleForMode: boolean;
}

Expand All @@ -28,7 +27,6 @@ const createOwnershipState = (isResponsibleForMode?: boolean): OwnershipState =>
initialized: false,
ownershipLedger: createOwnershipLedger(),
pendingActions: [],
ticker: 0,
isResponsibleForMode: isResponsibleForMode ? isResponsibleForMode : true
};
};
Expand Down
15 changes: 9 additions & 6 deletions src/concepts/ownership/ownership.mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const ownershipMode: Mode = (
// If generation is set to -1, then the action is not primed.
// Therefore we pass straight to finalMode which will recall this Mode after priming the action.
// This guarantees that action beyond this function will have a semaphore not set to [0, 0, -1, 0]
if (action.semaphore[3] !== 3 && action.semaphore[2] !== axiumState.generation) {
if (action.semaphore[3] !== 3 && action.semaphore[3] !== 1 && action.semaphore[2] !== axiumState.generation) {
// Check In Logic
const shouldBlock = ownershipShouldBlock(concepts, action);
if (shouldBlock) {
Expand Down Expand Up @@ -68,14 +68,17 @@ export const ownershipMode: Mode = (
finalMode([action, concepts, action$, concepts$]);
}
// Logical Determination: axiumConcludeType
} else if (action.semaphore[3] !== 3) {
} else if (action.semaphore[3] !== 3 && action.semaphore[1] !== 1) {
finalMode([action, concepts, action$, concepts$]);
}

// Logical Determination: axiumConcludeType
if (action.strategy?.stubs && action.semaphore[3] === 3) {
// Logical Determination: axiumConcludeType, axiumBadActionType
} else if (action.strategy?.stubs && (action.semaphore[3] === 3 || action.semaphore[3] === 1)) {
concepts = clearStubs(concepts, action.strategy);
concepts$.next(concepts);
if (action.semaphore[3] === 1) {
finalMode([action, concepts, action$, concepts$]);
}
} else if (action.semaphore[3] === 1) {
finalMode([action, concepts, action$, concepts$]);
}
const ownership = selectState<OwnershipState>(concepts, ownershipName);
};
19 changes: 16 additions & 3 deletions src/model/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,40 @@ export type Action = {
strategy?: ActionStrategy;
keyedSelectors?: KeyedSelector[];
expiration: number;
axium?: string;
};

export function primeAction(concepts: Concept[], action: Action): Action {
for (const concept of concepts) {
const semaphore = getSemaphore(concepts, concept.name, action.type);
if (semaphore[2] !== -1) {
let axium;
if (action.axium) {
axium = action.axium;
} else {
axium = (concepts[0].state as AxiumState).name;
}
const newAction = {
...action,
semaphore: semaphore,
axium,
};
if (newAction.strategy) {
newAction.strategy.currentNode.action = newAction;
}
return newAction;
}
}
return {
const badAction: Action = {
type: axiumBadActionType,
semaphore: [0, 0, -1, getSpecialSemaphore(axiumBadActionType)],
expiration: Date.now() + 5000
semaphore: getSemaphore(concepts, concepts[0].name, axiumBadActionType),
expiration: Date.now() + 5000,
};
if (action.strategy) {
badAction.strategy = action.strategy;
badAction.strategy.currentNode.action = badAction;
}
return badAction;
}

export function getSemaphore(concepts: Concept[], conceptName: string, actionType: ActionType): [number, number, number, number] {
Expand Down
4 changes: 2 additions & 2 deletions src/model/axium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export const defaultMethodSubscription = (action$: Subject<Action>, action: Acti
}
};

export function createAxium(initialConcepts: Concept[], logging?: boolean, storeDialog?: boolean) {
const concepts: Concept[] = [createAxiumConcept(logging, storeDialog), ...initialConcepts];
export function createAxium(name: string, initialConcepts: Concept[], logging?: boolean, storeDialog?: boolean) {
const concepts: Concept[] = [createAxiumConcept(name, logging, storeDialog), ...initialConcepts];
let axiumState = concepts[0].state as AxiumState;
axiumState.cachedSemaphores = createCacheSemaphores(concepts);
concepts.forEach((concept, _index) => {
Expand Down
18 changes: 13 additions & 5 deletions src/model/ownership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import { OwnershipState, ownershipName } from '../concepts/ownership/ownership.c
import { Concept } from './concept';
import { selectState } from './selector';
import { ActionNode, ActionStrategy } from './actionStrategy';
import { AxiumState } from '../concepts/axium/axium.concept';
import { randomUUID } from 'crypto';

export type OwnershipLedger = Map<string, OwnershipTicket[]>;

export type OwnershipTicket = {
ticket: number;
ticket: string;
// new Date().now() + Agreement
expiration: number;
}

export type OwnershipTicketStub = {
key: string,
ticket: number,
ticket: string,
}

export const createOwnershipLedger = (): OwnershipLedger => ( new Map<string, OwnershipTicket[]>());
Expand Down Expand Up @@ -143,16 +145,22 @@ export const checkIn =
}
if (!found) {
const expiration = action.expiration;
const axiumState = concepts[0].state as AxiumState;
// This can be improved by checking to see if UUID does not exist on ledger.
// Likewise would be proven to halt beyond @100%.
// Via the handling the axium name to be that of a guaranteed unique network identifier.
// In addition to authentication with incoming actions.
// As the benefit is knowing that all UUIDs have an expiration and are bound to their origin.
const ticket = axiumState.name + randomUUID();
const newTicketStub = {
key,
ticket: ownershipState.ticker,
ticket,
expiration
};
const newTicket = {
ticket: ownershipState.ticker,
ticket,
expiration
};
ownershipState.ticker += 1;
strategy.stubs?.push(newTicketStub);
if (entry) {
entry.push(newTicket);
Expand Down
2 changes: 1 addition & 1 deletion src/test/addConcepts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AxiumState } from '../concepts/axium/axium.concept';
import { countingTopic } from '../concepts/counter/strategies/counting.strategy';

test('Axium add Concepts Strategy Test', (done) => {
const axium = createAxium([], true, true);
const axium = createAxium('axiumAddConceptTest',[], true, true);
const staged = axium.stage('Add Concepts Stage',[
(concepts, dispatch) => {
dispatch(
Expand Down
2 changes: 1 addition & 1 deletion src/test/chain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { counterAdd } from '../concepts/counter/qualities/add.quality';
import { counterSubtract } from '../concepts/counter/qualities/subtract.quality';

test('Axium Test', (done) => {
const axium = createAxium([createCounterConcept(), createChainConcept()], true, true);
const axium = createAxium('chainConceptTest', [createCounterConcept(), createChainConcept()], true, true);
let count = 0;
let willDispatch = true;
const sub = axium.subscribe((concepts: Concept[]) => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ownership.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { counterSetCount } from '../concepts/counter/qualities/setCount.quality'
test('Ownership Test', (done) => {
const orderOfTopics: string[] = [];
let finalRun = true;
const axium = createAxium([createOwnershipConcept(), createCounterConcept(), createExperimentConcept()], true, true);
const axium = createAxium('ownershipTest', [createOwnershipConcept(), createCounterConcept(), createExperimentConcept()], true, true);
const staged = axium.stage(
'Testing Ownership Staging', [
(cpts, dispatch) => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/removeConcepts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { AxiumState } from '../concepts/axium/axium.concept';

test('Axium remove Concepts Strategy Test', (done) => {
const axium = createAxium([createCounterConcept()], true, true);
const axium = createAxium('axiumRemoveConceptsTest', [createCounterConcept()], true, true);
const staged = axium.stage('Remove Concepts Stage',[
(concepts, dispatch) => {
dispatch(
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 @@ -8,7 +8,7 @@ test('Axium Selector Test', (done) => {
const counter = createCounterConcept();
const counterState = counter.state as Counter;
counterState.count = 10;
const axium = createAxium([counter], true, true);
const axium = createAxium('axiumSelectorTest', [counter], true, true);
const sub = axium.subscribe((concepts: Concept[]) => {
const state = selectState<Counter>(concepts, counterName);
// const count = selectSlice<number>(concepts, counterSelectCount);
Expand All @@ -22,7 +22,7 @@ test('Axium Selector State Slice Test', (done) => {
const counter = createCounterConcept();
const counterState = counter.state as Counter;
counterState.count = 10;
const axium = createAxium([counter], true, true);
const axium = createAxium('axiumSelectorStateSlicedTest', [counter], true, true);
const sub = axium.subscribe((concepts: Concept[]) => {
const count = selectSlice<number>(concepts, counterSelectCount);
expect(count).toBe(10);
Expand Down
2 changes: 1 addition & 1 deletion src/test/stageDisptachOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { counterSelectCount } from '../concepts/counter/counter.selector';

test('Axium Stage Dispatch Options Test', (done) => {
let runCount = 0;
const axium = createAxium([createCounterConcept()], true);
const axium = createAxium('axiumStageDispatchOptionsTest', [createCounterConcept()], true);
axium.subscribe((concepts) => {
const axiumState = concepts[0].state as AxiumState;
if (axiumState.badStages.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/strategy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AxiumState } from '../concepts/axium/axium.concept';
import { countingTopic } from '../concepts/counter/strategies/counting.strategy';

test('Axium Counting Strategy Test', (done) => {
const axium = createAxium([createCounterConcept()], true, true);
const axium = createAxium('axiumStrategyTest', [createCounterConcept()], true, true);
const staged = axium.stage('Counting Strategy Stage',
[
(_, dispatch) => {
Expand Down

0 comments on commit ccd7b70

Please sign in to comment.