Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(daemon): Make endo formula numbered #2066

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/daemon/src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,11 @@ const makeEndoBootstrap = (
) => {
const { type: formulaType, number: formulaNumber } =
parseFormulaIdentifier(formulaIdentifier);
if (formulaIdentifier === 'endo') {
if (formulaType === 'endo-id512') {
if (formulaNumber !== zero512) {
throw Error('Invalid endo-id512 formula number.');
}

// TODO reframe "cancelled" as termination of the "endo" object and
// ensure that all values ultimately depend on "endo".
// Behold, self-referentiality:
Expand Down Expand Up @@ -449,6 +453,7 @@ const makeEndoBootstrap = (
);
return { external, internal: undefined };
} else if (formulaType === 'host-id512') {
const endoFormulaIdentifier = `endo-id512:${zero512}`;
const storeFormulaIdentifier = `pet-store-id512:${formulaNumber}`;
const inspectorFormulaIdentifier = `pet-inspector-id512:${formulaNumber}`;
const workerFormulaIdentifier = `worker-id512:${formulaNumber}`;
Expand All @@ -458,6 +463,7 @@ const makeEndoBootstrap = (
// eslint-disable-next-line no-use-before-define
return makeIdentifiedHost(
formulaIdentifier,
endoFormulaIdentifier,
storeFormulaIdentifier,
inspectorFormulaIdentifier,
workerFormulaIdentifier,
Expand Down
13 changes: 4 additions & 9 deletions packages/daemon/src/formula-identifier.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
const { quote: q } = assert;

const numberlessFormulasIdentifiers = new Set(['endo']);

/**
* @param {string} formulaIdentifier
* @returns {import("./types").FormulaIdentifierRecord}
*/
export const parseFormulaIdentifier = formulaIdentifier => {
const delimiterIndex = formulaIdentifier.indexOf(':');
if (delimiterIndex < 0) {
if (numberlessFormulasIdentifiers.has(formulaIdentifier)) {
return { type: formulaIdentifier, number: '' };
} else {
throw new TypeError(
`Formula identifier must have a colon: ${q(formulaIdentifier)}`,
);
}
throw new TypeError(
`Formula identifier must have a colon: ${q(formulaIdentifier)}`,
);
}

const type = formulaIdentifier.slice(0, delimiterIndex);
const number = formulaIdentifier.slice(delimiterIndex + 1);
return { type, number };
Expand Down
4 changes: 3 additions & 1 deletion packages/daemon/src/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const makeHostMaker = ({
}) => {
/**
* @param {string} hostFormulaIdentifier
* @param {string} endoFormulaIdentifier
* @param {string} storeFormulaIdentifier
* @param {string} inspectorFormulaIdentifier
* @param {string} mainWorkerFormulaIdentifier
Expand All @@ -25,6 +26,7 @@ export const makeHostMaker = ({
*/
const makeIdentifiedHost = async (
hostFormulaIdentifier,
endoFormulaIdentifier,
storeFormulaIdentifier,
inspectorFormulaIdentifier,
mainWorkerFormulaIdentifier,
Expand Down Expand Up @@ -63,9 +65,9 @@ export const makeHostMaker = ({
selfFormulaIdentifier: hostFormulaIdentifier,
specialNames: {
SELF: hostFormulaIdentifier,
ENDO: endoFormulaIdentifier,
INFO: inspectorFormulaIdentifier,
NONE: leastAuthorityFormulaIdentifier,
ENDO: 'endo',
},
terminator,
});
Expand Down
Loading