npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mark1russell7/stack-placement

v0.1.8

Published

The placement of the parts of a system stack as a query: a candidate for each slot, the chance that a function works, the cost, and the front of the two. An add-on of system-stack.

Readme

@mark1russell7/stack-placement

The placement of the parts of a system stack as a query. A layer gives the candidates of each slot. The package finds the choices that no other choice beats on the expected cost and on the chance that a function works.

It is the placement add-on of @mark1russell7/system-stack. The search comes from @mark1russell7/strategy-search.

The add-on knows no other add-on. The caller gives the joiners and the measures of the chance and of the bound. A host, a site or a test makes them, for example from @mark1russell7/stack-risk and @mark1russell7/stack-spend.

Nobody picks a placement by hand. Each choice is a stack, and the front is a result of a query over the candidates. When a price or a chance changes, the front changes.

Each function is a plain function with no clock and no network.

The rule

A slot is a part that the base stack needs, for example a copy of a program. Each candidate of a slot is a stack fragment that gives that part, with its chances, its costs and its expected cost of a month.

A part of two or more candidates, for example a provider or a region, is in a shared fragment. A placed stack has each shared fragment one time. Thus two copies on one provider share one cause of failure, and the chance shows it.

The front has each choice that keeps the limits and that no other choice beats. A choice beats a different choice when it is as good on the cost and on the chance, and better on one of them.

The entries

| Entry | What it has | | --- | --- | | @mark1russell7/stack-placement | The records of a layer, the placed stack of a choice, the plan, the gate, the join and a sample. | | @mark1russell7/stack-placement/schema | placementSchema, the zod schema of a layer, and parsePlacement. | | @mark1russell7/stack-placement/add-on | placementAddOn, the add-on in the form of the layer contract of the core. |

The root entry has no schema library. Thus a page that only shows a plan gets no zod.

Install

npm install @mark1russell7/stack-placement @mark1russell7/system-stack

The examples of this file also use the add-ons of risk and spend for the measures:

npm install @mark1russell7/stack-risk @mark1russell7/stack-spend

A layer

A placement layer has the format placement/1. A stack keeps it in Stack.layers, with the key placement/1.

import type { PlacementLayer } from "@mark1russell7/stack-placement";

const layer: PlacementLayer = {
  schema: "placement/1",
  part: "send",
  currency: "USD",
  slots: [
    { id: "copy-a", candidates: [/* one candidate for each offer */] },
    { id: "copy-b", optional: true, candidates: [/* one candidate for each offer */] },
  ],
  shared: [/* one fragment for each provider */],
  limits: { cost: 25, chance: 0.999 },
};

SAMPLE_PLACEMENT of the package is a full layer. It has two slots, two candidates for each slot, and two providers. SAMPLE_BASE is its base stack.

| Field of a layer | What it is | | --- | --- | | part | The id of the part to keep in work, for example a function of the system. It is a part of the base stack. | | currency | The currency of each cost. | | slots | The slots. Each slot is one stage of the search. | | shared | The shared fragments. | | limits | The largest expected cost (cost), the largest bound of the cost (bound), and the smallest chance (chance). |

| Field of a slot | What it is | | --- | --- | | id | The id of the part of the slot. A part of the base stack names it in a need. | | candidates | The candidates of the slot. | | optional | With true, a choice can leave the slot empty. |

| Field of a candidate | What it is | | --- | --- | | key | The key of the candidate in its slot. | | stack | The stack fragment. It has the part of the slot, and its layers, for example risk/1 and spend/1. | | cost | The expected cost of a month. | | uses | The id of each shared fragment that the candidate needs. | | source | The source of the candidate, for example the id of an offer. |

The placed stack

placedStack(layer, stack, choice, joiners) gives the stack of one choice. joinStacks of the core joins the base stack, the chosen candidates and their shared fragments. Each add-on of joiners joins its layer.

import { placedStack, SAMPLE_BASE, SAMPLE_PLACEMENT, SAMPLE_TODAY } from "@mark1russell7/stack-placement";
import { riskAddOn } from "@mark1russell7/stack-risk/add-on";
import { spendAddOn } from "@mark1russell7/stack-spend/add-on";

const joiners = [riskAddOn({ today: SAMPLE_TODAY }), spendAddOn({ today: SAMPLE_TODAY })];
const placed = placedStack(SAMPLE_PLACEMENT, SAMPLE_BASE, { "copy-a": "small-x", "copy-b": "small-x" }, joiners);
// placed.ok === true
// placed.stack.parts.map((part) => part.id) => ["send", "copy-a", "copy-b", "provider-x"]
// placed.cost => 10

A fault of the choice gives no stack. The codes are slot-unknown, slot-empty, candidate-unknown and shared-unknown.

The measures

The caller gives the measures in the options of a plan. Each measure gets a placed stack.

| Option | What it gives | | --- | --- | | chance | The chance that the part of the layer works: a number, or a ChanceReading with the most important parts and the assumed parts. It is necessary. | | bound | A BoundReading: the largest cost of a month, and the part of each service with no bound. A layer with the limit bound needs it. | | cost | The expected cost of a month. The default is the sum of the costs of the chosen candidates and of their shared fragments. |

  • A chance of NaN tells that the measure cannot decide, for example at the end of a budget of steps. The search counts the choice as unread.
  • A measure that throws a RangeError refuses the placed stack. The choice gets the break measure.
  • A value out of its range also gets the break measure: a chance that is not from 0 to 1, or a negative cost.
  • An error that is not a RangeError goes to the caller.

This example makes the measures from the add-ons of risk and spend:

import { RISK_SCHEMA, worksChance } from "@mark1russell7/stack-risk";
import { monthTotal } from "@mark1russell7/stack-spend";
import { readLayer, type Stack, type StackJoiner } from "@mark1russell7/system-stack";
import type { BoundReading, ChanceReading } from "@mark1russell7/stack-placement";

const [risk, spend] = joiners;

function layerOf<Layer>(stack: Stack, addOn: StackJoiner<Layer>): Layer | undefined {
  const read = readLayer(stack, addOn);
  if (read !== undefined && !read.ok) throw new RangeError(read.errors.join(" "));
  return read?.layer;
}

function chance(stack: Stack, part: string): ChanceReading {
  const works = worksChance(layerOf(stack, risk) ?? { schema: RISK_SCHEMA, goals: [] }, stack, part);
  return works.kind === "exact" ? { value: works.value, importance: works.importance, assumed: works.assumed } : { value: Number.NaN };
}

function bound(stack: Stack): BoundReading {
  const layer = layerOf(stack, spend);
  return layer === undefined ? { bounded: 0, open: [] } : monthTotal(layer);
}

The plan

planPlacement(layer, stack, { joiners, chance, bound }) gives the front of the choices.

import { planPlacement, SAMPLE_BASE, SAMPLE_PLACEMENT } from "@mark1russell7/stack-placement";

const plan = planPlacement(SAMPLE_PLACEMENT, SAMPLE_BASE, { joiners, chance, bound });
plan.front.map((row) => [row.choice["copy-a"], row.choice["copy-b"], row.cost, row.chance.toFixed(6)]);
// => [
//   ["small-x", null, 5, "0.989010"],
//   ["small-x", "small-x", 10, "0.998900"],
//   ["small-x", "small-y", 11, "0.999726"],
//   ["small-y", "small-x", 11, "0.999726"],
// ]

Two copies on the provider provider-x cost 10 and give 0.998900. A copy on each provider costs 11 and gives 0.999726. The shared provider is the difference.

  • A space with 2000 choices or less gets a grid of each choice. A larger space gets a seeded genetic search. The option evaluations sets the count.
  • A choice that breaks a limit is not on the front. plan.breaks counts the choices with each break: join, measure, cost, bound and chance.
  • Each row has the sources of its candidates and its shared fragments. It also has the reading of the bound measure and the most important parts for the chance.
  • The search compares a cost to 1e-9 and a chance to 1e-12 (OBJECTIVE_STEPS). Thus two choices with one true value tie, and the front keeps each.

The result is deterministic when each measure is deterministic: one layer, one stack and one set of options give one plan.

The gate

checkPlacement(layer, stack) gives the faults of a layer for its base stack. An empty list tells that the gate passes.

| Code | The fault | | --- | --- | | part-unknown | The part of the layer is not a part of the base stack. | | slot-twice | Two or more slots have one id. | | slot-part | The id of a slot is a part of the base stack. | | slot-unneeded | No part of the base stack names a slot in a need. It is a warning. | | slot-no-candidate | A slot has no candidate. | | candidate-twice | Two or more candidates of a slot have one key. | | candidate-part | The stack of a candidate has no part with the id of its slot. | | cost-range | A cost is not a finite number of 0 or more. | | shared-twice | Two or more shared fragments have one id. | | shared-unknown | A candidate uses a shared fragment that the layer does not have. | | shared-unused | No candidate uses a shared fragment. It is a warning. | | limit-range | A limit of cost is less than 0, or the limit of chance is not from 0 to 1. |

The gate does not examine the layers of a fragment or of the base stack. The gates of their add-ons examine each placed stack. The gate does not compare the currency of the layer with a different layer. The measures of the caller do it when it is necessary.

The base stack is not whole before a placement. A part of the base names each slot in a need, and the base has no part for a slot. Thus checkStack of the core gives the fault need-part for each slot of the base stack. A placed stack has the part of each slot with a candidate. An empty optional slot has no part, and the chance counts that part as down.

The add-on

placementAddOn() gives the add-on for checkStackLayers and joinStacks of the core. Its join is joinPlacement: the slots and the shared fragments of each fragment, with one part, one currency and one value for each limit.

License

MIT