@mark1russell7/market 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -1
- package/build/index.d.ts +156 -211
- package/build/index.d.ts.map +1 -1
- package/build/index.js +348 -342
- package/build/index.js.map +1 -1
- package/build/offers-CVUAcRHs.d.ts +214 -0
- package/build/offers-CVUAcRHs.d.ts.map +1 -0
- package/build/plan.d.ts +151 -0
- package/build/plan.d.ts.map +1 -0
- package/build/plan.js +440 -0
- package/build/plan.js.map +1 -0
- package/build/records-hK1UCmpm.js +346 -0
- package/build/records-hK1UCmpm.js.map +1 -0
- package/package.json +16 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mark1russell7/market
|
|
2
2
|
|
|
3
|
-
The records of a market: a product, an offer of a seller and a price reading, with their checks. The package also has the GTIN check, the match keys of a record, the cost of an order and the storage rules of a source. The offers of a part and the best offer join the observations of the sources to the parts that a buyer wants. The board keeps the current prices within the terms of each source, and plans the reads of a watch.
|
|
3
|
+
The records of a market: a product, an offer of a seller and a price reading, with their checks. The package also has the GTIN check, the match keys of a record, the cost of an order and the storage rules of a source. The offers of a part and the best offer join the observations of the sources to the parts that a buyer wants. The board keeps the current prices within the terms of each source, and plans the reads of a watch. A buy plan gives the best baskets of the parts that a need names. A metered price gives the cost of a cloud resource from its usage, with tiers, free amounts and terms.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
pnpm add @mark1russell7/market
|
|
@@ -77,6 +77,101 @@ board = settleBoard(board, { terms, now, names }, { name: "ups", at: now, observ
|
|
|
77
77
|
const chosen = bestOffer(offersOfPart(boardObservations(board, { terms, now }), want), { currency: "USD" });
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
+
## A buy plan
|
|
81
|
+
|
|
82
|
+
The entry `@mark1russell7/market/plan` chooses the parts of a purchase. A need names the slots of a basket and the parts that can fill each slot. Each part has facts, for example its watts. Vex programs over a basket give its measures and its rules. The plan searches the baskets with `@mark1russell7/strategy-search`. It gives the Pareto front of the price against the measures.
|
|
83
|
+
|
|
84
|
+
- `planBuys(need, observations, { evaluations, seed, population })` gives the plan. Each item of a basket is the offer in stock with the lowest cost for its part and its count.
|
|
85
|
+
- **The search.** A space with no more baskets than `evaluations` gets a grid of each basket. A larger space gets a genetic search. The seed of the search is `seed`, or else the id of the need.
|
|
86
|
+
- `needProblems(need)` gives the problems of a need. Examples are two slots with one name, a bad count, and a program that is not valid. `buyNeedSchema` examines the form of a need file.
|
|
87
|
+
- **The records of a basket.** A program evaluates at the key `need`, which has the inputs of the need. The key of each slot has the facts of its part, `slot`, `part`, `count` and `cost`. An empty slot has the count 0. The axis `others` gives the slots.
|
|
88
|
+
- **The breaks.** A basket breaks `price:<slot>` with no usable offer at its count. It breaks `measure:<name>` when a measure gives no number, and `limit:<name>` outside the limits of a measure. It breaks `rule:<name>` when a rule does not give `true`. The plan counts the baskets of each break, with the reason of the first basket.
|
|
89
|
+
- **The parts with no offer.** `unpriced` names each part with no usable offer at a count of its slot. A slot with a minimum of 1 or more and no such part gives the method `none` and an empty front.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { app, axes, each, lit, ref } from "@mark1russell7/vex";
|
|
93
|
+
import { NEED_FORMAT, planBuys, type BuyNeed } from "@mark1russell7/market/plan";
|
|
94
|
+
|
|
95
|
+
const part = (key: string, wattHours: number, outputWatts: number) => ({ key, want: { brands: ["Acme"], partNumbers: [key] }, facts: { wattHours, outputWatts } });
|
|
96
|
+
const need: BuyNeed = {
|
|
97
|
+
format: NEED_FORMAT,
|
|
98
|
+
id: "closet-ups",
|
|
99
|
+
currency: "USD",
|
|
100
|
+
inputs: { loadWatts: 300 },
|
|
101
|
+
slots: [
|
|
102
|
+
{ name: "ups", parts: [part("UPS-600", 100, 360), part("UPS-1000", 200, 600)] },
|
|
103
|
+
{ name: "battery", parts: [part("PACK-1", 150, 0)], count: { min: 0, max: 2 } },
|
|
104
|
+
],
|
|
105
|
+
// The minutes of the batteries at the load.
|
|
106
|
+
measures: [{ name: "minutes", goal: "max", unit: "min", program: app("multiply", app("divide", app("sum", each(axes.others, app("multiply", ref("wattHours"), ref("count")))), ref("loadWatts")), lit(60)) }],
|
|
107
|
+
// The largest output of a part is the load or more.
|
|
108
|
+
rules: [{ name: "output", program: app("gte", app("max", each(axes.others, ref("outputWatts"))), ref("loadWatts")) }],
|
|
109
|
+
};
|
|
110
|
+
// The offers: a UPS-600 for $120, a UPS-1000 for $260 and a PACK-1 for $80, each with free shipping.
|
|
111
|
+
const plan = planBuys(need, observations);
|
|
112
|
+
plan.front.map((choice) => [choice.price.value, choice.values["minutes"]]); // [[120, 20], [200, 50], [280, 80], [420, 100]]
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Metered prices
|
|
116
|
+
|
|
117
|
+
A cloud resource has a metered price: a price for each unit of an amount that the provider meters. A metered amount is a `time` (the hours of a machine), a `data-time` (stored data in GiB-months), a `data` (a transfer) or a `count` (requests).
|
|
118
|
+
|
|
119
|
+
| Record | Schema | What it has |
|
|
120
|
+
| --- | --- | --- |
|
|
121
|
+
| Metered offer | `meteredOfferSchema` | One resource of a provider in one location, on one term: the source, the id at the source, the location, the term and the specifications. |
|
|
122
|
+
| Metered reading | `meteredReadingSchema` | The metered prices of one offer at one instant: the billing period, the meters, and the upfront money of a committed term. |
|
|
123
|
+
| Metered observation | `meteredObservationSchema` | A metered offer and a reading of that offer. |
|
|
124
|
+
|
|
125
|
+
- **Prices.** A metered price is a quantity with a compound unit of `@mark1russell7/quantity`, for example `USD/h`, `USD/GiB`, `USD/(GiB·mo)` or `USD/{request}`. `meteredKindOf(unit)` gives the kind of its metered amount.
|
|
126
|
+
- **Meters.** A reading has one meter or more, each with its own name. A meter has its tiers, and a free amount as an option.
|
|
127
|
+
- **Tiers.** A tier has its start and its price for each unit. The first tier starts at zero, and the starts increase. A start can have another unit of the same amount, for example `TiB` with prices in `USD/GiB`.
|
|
128
|
+
- **Free amounts.** A free amount is for each billing period. Its scope tells which usage shares it: the `account`, each `region` or each `resource`.
|
|
129
|
+
- **Terms.** The term of an offer is `on-demand`, `spot` or `committed`. The provider can end a `spot` use at any time, after the `notice`. A preemptible use is a `spot` use. A `committed` term has its `length`, and its readings can have `upfront` money.
|
|
130
|
+
- **Location.** The location of an offer has the provider, its region and its zone. The region and the zone are the ids of the provider. A source gives each location and each term its own offer id, so the readings of one offer make one series.
|
|
131
|
+
- **Terms of a source.** A metered reading has `offerId` and `at`, as a price reading has. Thus `keepUntil`, `isKept`, `permitsHistory` and `permitsTrend` apply to it.
|
|
132
|
+
|
|
133
|
+
`meteredCost(observation, usage, { freeUsed })` gives the cost of an offer for one period. `usage` has the amount of each meter in that period, by the name of the meter.
|
|
134
|
+
|
|
135
|
+
1. The free amount comes off the usage first. `freeUsed` is the part of the free amount that other usage in its scope used.
|
|
136
|
+
2. The tiers count the rest of the usage from zero. Each tier applies its price to its part of the usage.
|
|
137
|
+
3. A committed term adds its upfront money, times the period, divided by the length.
|
|
138
|
+
|
|
139
|
+
The arithmetic is exact, and the function does not round the cost to the cent. A meter with no usage costs zero. The result has the cost of each meter, the part of the upfront money, and the total.
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import { meteredCost, type MeteredObservation } from "@mark1russell7/market";
|
|
143
|
+
|
|
144
|
+
const id = "example-cloud:egress/region-1";
|
|
145
|
+
const observation: MeteredObservation = {
|
|
146
|
+
offer: {
|
|
147
|
+
id,
|
|
148
|
+
source: "example-cloud",
|
|
149
|
+
sourceId: "egress/region-1",
|
|
150
|
+
title: "Data out to the internet",
|
|
151
|
+
location: { provider: "example-cloud", region: "region-1" },
|
|
152
|
+
term: { kind: "on-demand" },
|
|
153
|
+
specs: [],
|
|
154
|
+
},
|
|
155
|
+
reading: {
|
|
156
|
+
offerId: id,
|
|
157
|
+
at: "2026-11-12T18:00:00Z",
|
|
158
|
+
period: { value: 1, unit: "mo" },
|
|
159
|
+
meters: [
|
|
160
|
+
{
|
|
161
|
+
name: "egress",
|
|
162
|
+
tiers: [
|
|
163
|
+
{ from: { value: 0, unit: "GiB" }, unitPrice: { value: 0.09, unit: "USD/GiB" } },
|
|
164
|
+
{ from: { value: 10, unit: "TiB" }, unitPrice: { value: 0.085, unit: "USD/GiB" } },
|
|
165
|
+
],
|
|
166
|
+
free: { amount: { value: 100, unit: "GiB" }, scope: "account" },
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
// The free 100 GiB come off first. Then 10,240 GiB cost $0.09 each, and 1 GiB costs $0.085.
|
|
172
|
+
meteredCost(observation, { egress: { value: 10_341, unit: "GiB" } }).total; // { value: 921.685, unit: "USD" }
|
|
173
|
+
```
|
|
174
|
+
|
|
80
175
|
## Example
|
|
81
176
|
|
|
82
177
|
```ts
|
|
@@ -106,5 +201,10 @@ isKept(terms, reading, "2026-11-16T00:00:00Z"); // false
|
|
|
106
201
|
- The match keys do not know the aliases of a brand. `Western Digital` and `WD` give two keys. A want of a part names each form of the brand.
|
|
107
202
|
- A part number of a want matches each longer part number that starts with it. A want gives the full part number of the maker.
|
|
108
203
|
- The money of the quantity package has one currency: the US dollar.
|
|
204
|
+
- A month of the quantity package is 730.485 hours, the mean month of the calendar. Many providers bill a month as 730 hours. Give the usage in the unit of the price.
|
|
205
|
+
- The quantity package has no prefix for a count. Thus a price for each million requests is a price for each request: `0.0000004 USD/{request}`.
|
|
206
|
+
- `meteredCost` gives the cost of one offer. When offers share a free amount, the caller divides the free amount with `freeUsed`.
|
|
207
|
+
- The price of a basket adds the cost of each item. Each item is one order with its own shipping, so the plan does not know a shared shipping cost.
|
|
208
|
+
- A buy plan does not compare the count of an item with the count of the available units of its offer.
|
|
109
209
|
- The package has no history of prices yet. Roadmap item R5 adds it, after the owner chooses its source.
|
|
110
210
|
- The board does not know if an offer ended when a new read does not give it. It drops the offer from that read. Another read can still give it.
|
package/build/index.d.ts
CHANGED
|
@@ -3,219 +3,11 @@
|
|
|
3
3
|
* also has the GTIN check, the match keys of a record, the cost of an order and the storage rules of a source.
|
|
4
4
|
* The offers of a part and the best offer join the observations of the sources to the parts that a buyer wants.
|
|
5
5
|
* The board keeps the current prices within the terms of each source, and plans the reads of a watch.
|
|
6
|
+
* A metered offer has a price for each unit of a metered amount, in tiers, with a free amount and a term.
|
|
6
7
|
*/
|
|
8
|
+
import { A as priceBreakSchema, B as PartNumber, C as Spec, D as offerId, E as moneySchema, F as sourceOfOffer, H as matchKeys, I as sourceSchema, L as specSchema, M as productSchema, N as sellerSchema, O as offerSchema, P as shippingSchema, R as textSchema, S as Shipping, T as instantSchema, V as foldCode, _ as PriceBreak, a as PartWant, b as Rating, c as offersOfPart, d as Availability, f as CONDITIONS, g as Offer, h as Format, i as OfferChoice, j as priceReadingSchema, k as partNumberSchema, l as offersPart, m as FORMATS, n as BestOfferOptions, o as bestOffer, p as Condition, r as Observation, s as latestObservations, t as BestOffer, u as AVAILABILITIES, v as PriceReading, w as gtinSchema, x as Seller, y as Product, z as Identifiers } from "./offers-CVUAcRHs.js";
|
|
7
9
|
import { Quantity } from "@mark1russell7/quantity";
|
|
8
10
|
import { z } from "zod";
|
|
9
|
-
/** A part number of a maker: the brand, and the number that the maker gives to the part. */
|
|
10
|
-
interface PartNumber {
|
|
11
|
-
readonly brand: string;
|
|
12
|
-
readonly partNumber: string;
|
|
13
|
-
}
|
|
14
|
-
/** The identifiers of a product or of an offer. */
|
|
15
|
-
interface Identifiers {
|
|
16
|
-
readonly gtins: readonly string[];
|
|
17
|
-
readonly partNumbers: readonly PartNumber[];
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* This function folds a brand or a part number for a comparison. The result has only capital letters A to Z
|
|
21
|
-
* and digits. Thus `MZ-V8V1T0B/AM` and `mzv8v1t0bam` fold to one text.
|
|
22
|
-
*/
|
|
23
|
-
export declare function foldCode(text: string): string;
|
|
24
|
-
/**
|
|
25
|
-
* This function gives the match keys of a record, sorted and with no copy. A key is `gtin:` with the GTIN-14,
|
|
26
|
-
* or `part:` with the folded brand and part number. Two records with a key in common name one product.
|
|
27
|
-
* The function ignores a GTIN that is not valid, and a part number whose brand or number folds to no text.
|
|
28
|
-
*/
|
|
29
|
-
export declare function matchKeys(identifiers: Identifiers): string[];
|
|
30
|
-
/**
|
|
31
|
-
* The conditions of an offer. A source maps its own condition to one of them, and it keeps its own text in
|
|
32
|
-
* the field `grade` of the offer.
|
|
33
|
-
*/
|
|
34
|
-
export declare const CONDITIONS: readonly ["new", "open-box", "refurbished", "used", "for-parts", "unknown"];
|
|
35
|
-
/** The condition of an offer. */
|
|
36
|
-
type Condition = (typeof CONDITIONS)[number];
|
|
37
|
-
/** The states of the stock of an offer at the time of a reading. */
|
|
38
|
-
export declare const AVAILABILITIES: readonly ["in-stock", "low-stock", "out-of-stock", "preorder", "unknown"];
|
|
39
|
-
/** The state of the stock of an offer. */
|
|
40
|
-
type Availability = (typeof AVAILABILITIES)[number];
|
|
41
|
-
/** The buying formats of an offer. In an auction, the price of a reading is the current bid. */
|
|
42
|
-
export declare const FORMATS: readonly ["fixed-price", "auction"];
|
|
43
|
-
/** The buying format of an offer. */
|
|
44
|
-
type Format = (typeof FORMATS)[number];
|
|
45
|
-
/** One specification of a product as text. */
|
|
46
|
-
interface Spec {
|
|
47
|
-
readonly name: string;
|
|
48
|
-
readonly value: string;
|
|
49
|
-
}
|
|
50
|
-
/** The feedback of a seller: the percent of good feedback, and the count of the feedback. */
|
|
51
|
-
interface Rating {
|
|
52
|
-
readonly percent: number;
|
|
53
|
-
readonly count: number;
|
|
54
|
-
}
|
|
55
|
-
/** A seller of an offer. A source gives some of these fields, or none. */
|
|
56
|
-
interface Seller {
|
|
57
|
-
readonly id?: string | undefined;
|
|
58
|
-
readonly name?: string | undefined;
|
|
59
|
-
readonly rating?: Rating | undefined;
|
|
60
|
-
}
|
|
61
|
-
/** A product of the catalog: one thing that a person can buy, with its identifiers and its specifications. */
|
|
62
|
-
interface Product {
|
|
63
|
-
readonly id: string;
|
|
64
|
-
readonly title: string;
|
|
65
|
-
readonly brand?: string | undefined;
|
|
66
|
-
readonly category?: readonly string[] | undefined;
|
|
67
|
-
readonly gtins: readonly string[];
|
|
68
|
-
readonly partNumbers: readonly PartNumber[];
|
|
69
|
-
readonly specs: readonly Spec[];
|
|
70
|
-
}
|
|
71
|
-
/** An offer of a seller: one product at one seller, with the identifiers that the source gives. */
|
|
72
|
-
interface Offer {
|
|
73
|
-
readonly id: string;
|
|
74
|
-
readonly source: string;
|
|
75
|
-
readonly sourceId: string;
|
|
76
|
-
readonly productId?: string | undefined;
|
|
77
|
-
readonly title: string;
|
|
78
|
-
readonly url?: string | undefined;
|
|
79
|
-
readonly seller: Seller;
|
|
80
|
-
readonly condition: Condition;
|
|
81
|
-
readonly grade?: string | undefined;
|
|
82
|
-
readonly format: Format;
|
|
83
|
-
readonly endsAt?: string | undefined;
|
|
84
|
-
readonly gtins: readonly string[];
|
|
85
|
-
readonly partNumbers: readonly PartNumber[];
|
|
86
|
-
readonly specs: readonly Spec[];
|
|
87
|
-
}
|
|
88
|
-
/** The shipping of a reading. A calculated cost depends on the address of the buyer. */
|
|
89
|
-
type Shipping = {
|
|
90
|
-
readonly kind: "free";
|
|
91
|
-
} | {
|
|
92
|
-
readonly kind: "fixed";
|
|
93
|
-
readonly cost: Quantity;
|
|
94
|
-
} | {
|
|
95
|
-
readonly kind: "calculated";
|
|
96
|
-
} | {
|
|
97
|
-
readonly kind: "unknown";
|
|
98
|
-
};
|
|
99
|
-
/** A price break of a reading: the unit price for an order of `quantity` units or more. */
|
|
100
|
-
interface PriceBreak {
|
|
101
|
-
readonly quantity: number;
|
|
102
|
-
readonly unitPrice: Quantity;
|
|
103
|
-
}
|
|
104
|
-
/** A price reading: the state of one offer at one instant. */
|
|
105
|
-
interface PriceReading {
|
|
106
|
-
readonly offerId: string;
|
|
107
|
-
readonly at: string;
|
|
108
|
-
readonly price: Quantity;
|
|
109
|
-
readonly listPrice?: Quantity | undefined;
|
|
110
|
-
readonly shipping: Shipping;
|
|
111
|
-
readonly availability: Availability;
|
|
112
|
-
readonly available?: number | undefined;
|
|
113
|
-
readonly minimumQuantity?: number | undefined;
|
|
114
|
-
readonly priceBreaks?: readonly PriceBreak[] | undefined;
|
|
115
|
-
}
|
|
116
|
-
/** This schema accepts a text with a character that is not a space, and with no space at an end. */
|
|
117
|
-
export declare const textSchema: z.ZodType<string>;
|
|
118
|
-
/** This schema accepts the name of a source: small letters, digits and hyphens, with a letter first. */
|
|
119
|
-
export declare const sourceSchema: z.ZodType<string>;
|
|
120
|
-
/** This schema accepts a GTIN in its GTIN-14 form, with a correct check digit. `parseGtin` gives this form. */
|
|
121
|
-
export declare const gtinSchema: z.ZodType<string>;
|
|
122
|
-
/** This schema accepts an amount of money of zero or more, for example `{ "value": 129.99, "unit": "USD" }`. */
|
|
123
|
-
export declare const moneySchema: z.ZodType<Quantity, Quantity>;
|
|
124
|
-
/** This schema accepts an instant in UTC in the ISO 8601 form, for example `2026-11-12T18:00:00Z`. */
|
|
125
|
-
export declare const instantSchema: z.ZodType<string>;
|
|
126
|
-
/** This schema accepts a part number of a maker. */
|
|
127
|
-
export declare const partNumberSchema: z.ZodType<PartNumber>;
|
|
128
|
-
/** This schema accepts one specification as text, for example `{ "name": "Capacity", "value": "1 TB" }`. */
|
|
129
|
-
export declare const specSchema: z.ZodType<Spec>;
|
|
130
|
-
/** This schema accepts a seller. A rating is the percent of good feedback and the count of the feedback. */
|
|
131
|
-
export declare const sellerSchema: z.ZodType<Seller>;
|
|
132
|
-
/** This schema accepts a product: one thing that a person can buy, with its identifiers and its specifications. */
|
|
133
|
-
export declare const productSchema: z.ZodType<Product>;
|
|
134
|
-
/** This function gives the id of an offer: the name of its source, a colon, and the id at the source. */
|
|
135
|
-
export declare function offerId(source: string, sourceId: string): string;
|
|
136
|
-
/** This function gives the name of the source of an offer id: the text before the first colon. */
|
|
137
|
-
export declare function sourceOfOffer(id: string): string;
|
|
138
|
-
/**
|
|
139
|
-
* This schema accepts an offer: one product at one seller. The offer has the identifiers that the source gives.
|
|
140
|
-
* `productId` names the product of the catalog after a match.
|
|
141
|
-
*/
|
|
142
|
-
export declare const offerSchema: z.ZodType<Offer>;
|
|
143
|
-
/** This schema accepts the shipping of a reading. A calculated cost depends on the address of the buyer. */
|
|
144
|
-
export declare const shippingSchema: z.ZodType<Shipping>;
|
|
145
|
-
/** This schema accepts a price break: the unit price for an order of `quantity` units or more. */
|
|
146
|
-
export declare const priceBreakSchema: z.ZodType<PriceBreak>;
|
|
147
|
-
/**
|
|
148
|
-
* This schema accepts a price reading: the state of one offer at one instant. `price` is the unit price for an
|
|
149
|
-
* order of `minimumQuantity` units, or of one unit. The quantities of the breaks increase, and each is more
|
|
150
|
-
* than the minimum.
|
|
151
|
-
*/
|
|
152
|
-
export declare const priceReadingSchema: z.ZodType<PriceReading>;
|
|
153
|
-
/** One offer of a source, and its price reading at one instant. */
|
|
154
|
-
interface Observation {
|
|
155
|
-
readonly offer: Offer;
|
|
156
|
-
readonly reading: PriceReading;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* This record names a part that a buyer wants: the names of its maker, and its part numbers. A seller can write
|
|
160
|
-
* the brand of one maker in more than one form, so the want has a list of names.
|
|
161
|
-
*/
|
|
162
|
-
interface PartWant {
|
|
163
|
-
/** The names of the maker, as the sellers write the brand. */
|
|
164
|
-
readonly brands: readonly string[];
|
|
165
|
-
/** The part numbers of the maker. A part number of an offer matches when it starts with one of them, after the fold. */
|
|
166
|
-
readonly partNumbers: readonly string[];
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* This function tells if an offer is an offer of the part. One part number of the offer must have a brand of the
|
|
170
|
-
* want and start with a part number of the want. `foldCode` folds each text before the comparison. A part number
|
|
171
|
-
* of another maker does not match: many makers use short numbers like `A1383`.
|
|
172
|
-
*/
|
|
173
|
-
export declare function offersPart(offer: Pick<Offer, "partNumbers">, want: PartWant): boolean;
|
|
174
|
-
/**
|
|
175
|
-
* This function gives the latest observation of each offer, in the order of the offer ids. When two readings of
|
|
176
|
-
* one offer have the same instant, the later one in the list applies.
|
|
177
|
-
*/
|
|
178
|
-
export declare function latestObservations(observations: readonly Observation[]): Observation[];
|
|
179
|
-
/** This function gives the latest observation of each offer of the part, in the order of the offer ids. */
|
|
180
|
-
export declare function offersOfPart(observations: readonly Observation[], want: PartWant): Observation[];
|
|
181
|
-
/** This record is one offer that a buyer can choose, with the price of an order in the currency of the buyer. */
|
|
182
|
-
interface OfferChoice {
|
|
183
|
-
readonly observation: Observation;
|
|
184
|
-
/** The unit price for the count, times the count. */
|
|
185
|
-
readonly goods: Quantity;
|
|
186
|
-
/** The goods and the shipping, or null when the shipping cost is not known. */
|
|
187
|
-
readonly cost: Quantity | null;
|
|
188
|
-
/** True when the availability is `in-stock` or `low-stock`. */
|
|
189
|
-
readonly inStock: boolean;
|
|
190
|
-
}
|
|
191
|
-
/** These options change the choice of an offer. */
|
|
192
|
-
interface BestOfferOptions {
|
|
193
|
-
/** The currency of the prices, a unit of money of `@mark1russell7/quantity`, for example `USD`. An offer with a price in another currency is skipped. */
|
|
194
|
-
readonly currency: string;
|
|
195
|
-
/** The count of units of the order. The default is 1. */
|
|
196
|
-
readonly count?: number;
|
|
197
|
-
/** The conditions that the buyer accepts. The default is `new` only. */
|
|
198
|
-
readonly conditions?: readonly Condition[];
|
|
199
|
-
}
|
|
200
|
-
/** This record is the choice of an offer: the best offer, each offer in the order of the price, and each skipped offer. */
|
|
201
|
-
interface BestOffer {
|
|
202
|
-
/** The offer with the lowest price that is in stock, or else the offer with the lowest price, or null with no offer. */
|
|
203
|
-
readonly best: OfferChoice | null;
|
|
204
|
-
/** The offers, from the lowest price of the goods. Equal prices go in the order of the cost, then of the offer id. */
|
|
205
|
-
readonly offers: readonly OfferChoice[];
|
|
206
|
-
/** The offers that the choice skipped, each with the reason. */
|
|
207
|
-
readonly skipped: readonly {
|
|
208
|
-
readonly offerId: string;
|
|
209
|
-
readonly why: string;
|
|
210
|
-
}[];
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* This function chooses the offer to buy from the latest observation of each offer. It skips an offer with a
|
|
214
|
-
* condition that the buyer does not accept, a price in another currency, or a minimum above the count.
|
|
215
|
-
*
|
|
216
|
-
* @throws RangeError when the count is not a whole number of 1 or more, or when the currency is not a unit of money.
|
|
217
|
-
*/
|
|
218
|
-
export declare function bestOffer(observations: readonly Observation[], options: BestOfferOptions): BestOffer;
|
|
219
11
|
/** The storage rule of a source, from its terms. */
|
|
220
12
|
type Retention = {
|
|
221
13
|
readonly kind: "keep";
|
|
@@ -412,6 +204,159 @@ export declare function gtinCheckDigit(body: string): number;
|
|
|
412
204
|
* It refuses a length other than 8, 12, 13 or 14 digits, a wrong check digit, and a GTIN of zeros only.
|
|
413
205
|
*/
|
|
414
206
|
export declare function parseGtin(text: string): string | null;
|
|
207
|
+
/**
|
|
208
|
+
* The kinds of a metered amount: a time (the hours of a machine), data times time (stored data), data (a transfer)
|
|
209
|
+
* and a count (requests).
|
|
210
|
+
*/
|
|
211
|
+
export declare const METERED_KINDS: readonly ["time", "data-time", "data", "count"];
|
|
212
|
+
/** The kind of a metered amount. */
|
|
213
|
+
type MeteredKind = (typeof METERED_KINDS)[number];
|
|
214
|
+
/**
|
|
215
|
+
* The scopes of a free amount. With `account`, all the usage of the account in all regions shares one free amount.
|
|
216
|
+
* With `region`, each region has its own free amount. With `resource`, each resource has its own free amount.
|
|
217
|
+
*/
|
|
218
|
+
export declare const FREE_SCOPES: readonly ["account", "region", "resource"];
|
|
219
|
+
/** The scope of a free amount: the usage that shares it. */
|
|
220
|
+
type FreeScope = (typeof FREE_SCOPES)[number];
|
|
221
|
+
/** The location of a metered offer: the provider, and its region and zone, as the provider names them. */
|
|
222
|
+
interface Location {
|
|
223
|
+
readonly provider: string;
|
|
224
|
+
readonly region: string;
|
|
225
|
+
readonly zone?: string | undefined;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* The term of a metered price. A `spot` price is also a preemptible price: the provider can end the use at any time,
|
|
229
|
+
* after the `notice`. A `committed` price binds the buyer for its `length`.
|
|
230
|
+
*/
|
|
231
|
+
type PriceTerm = {
|
|
232
|
+
readonly kind: "on-demand";
|
|
233
|
+
} | {
|
|
234
|
+
readonly kind: "spot";
|
|
235
|
+
readonly notice?: Quantity | undefined;
|
|
236
|
+
} | {
|
|
237
|
+
readonly kind: "committed";
|
|
238
|
+
readonly length: Quantity;
|
|
239
|
+
};
|
|
240
|
+
/** A metered offer: one resource of a provider in one location, on one term, with the identifiers that the source gives. */
|
|
241
|
+
interface MeteredOffer {
|
|
242
|
+
readonly id: string;
|
|
243
|
+
readonly source: string;
|
|
244
|
+
readonly sourceId: string;
|
|
245
|
+
readonly productId?: string | undefined;
|
|
246
|
+
readonly title: string;
|
|
247
|
+
readonly url?: string | undefined;
|
|
248
|
+
readonly location: Location;
|
|
249
|
+
readonly term: PriceTerm;
|
|
250
|
+
readonly specs: readonly Spec[];
|
|
251
|
+
}
|
|
252
|
+
/** A tier of a meter: the price for each unit of the usage from `from` to the start of the next tier, in one period. */
|
|
253
|
+
interface Tier {
|
|
254
|
+
readonly from: Quantity;
|
|
255
|
+
readonly unitPrice: Quantity;
|
|
256
|
+
}
|
|
257
|
+
/** A free amount of a meter for each period, and the scope that shares it. */
|
|
258
|
+
interface FreeAmount {
|
|
259
|
+
readonly amount: Quantity;
|
|
260
|
+
readonly scope: FreeScope;
|
|
261
|
+
}
|
|
262
|
+
/** A meter of a metered reading: the tiers of the price of one metered amount, and its free amount. */
|
|
263
|
+
interface Meter {
|
|
264
|
+
readonly name: string;
|
|
265
|
+
readonly tiers: readonly Tier[];
|
|
266
|
+
readonly free?: FreeAmount | undefined;
|
|
267
|
+
}
|
|
268
|
+
/** A metered reading: the metered prices of one offer at one instant. */
|
|
269
|
+
interface MeteredReading {
|
|
270
|
+
readonly offerId: string;
|
|
271
|
+
readonly at: string;
|
|
272
|
+
readonly period: Quantity;
|
|
273
|
+
readonly meters: readonly Meter[];
|
|
274
|
+
readonly upfront?: Quantity | undefined;
|
|
275
|
+
}
|
|
276
|
+
/** One metered offer of a source, and its metered reading at one instant. */
|
|
277
|
+
interface MeteredObservation {
|
|
278
|
+
readonly offer: MeteredOffer;
|
|
279
|
+
readonly reading: MeteredReading;
|
|
280
|
+
}
|
|
281
|
+
/** The usage of each meter in one period, by the name of the meter. */
|
|
282
|
+
type MeteredUsage = Readonly<Record<string, Quantity>>;
|
|
283
|
+
/** These options change the cost of a metered offer. */
|
|
284
|
+
interface MeteredCostOptions {
|
|
285
|
+
/**
|
|
286
|
+
* The part of the free amount of each meter that other usage in its scope used in the same period. The keys are
|
|
287
|
+
* the names of the meters. The default is none.
|
|
288
|
+
*/
|
|
289
|
+
readonly freeUsed?: MeteredUsage | undefined;
|
|
290
|
+
}
|
|
291
|
+
/** The cost of the usage of one meter in one period. */
|
|
292
|
+
interface MeterCost {
|
|
293
|
+
readonly name: string;
|
|
294
|
+
readonly cost: Quantity;
|
|
295
|
+
}
|
|
296
|
+
/** The cost of a metered offer for one period. */
|
|
297
|
+
interface MeteredCost {
|
|
298
|
+
/** The cost of each meter, in the order of the meters of the reading. */
|
|
299
|
+
readonly meters: readonly MeterCost[];
|
|
300
|
+
/** The part of the upfront money of a committed term for one period, or zero. */
|
|
301
|
+
readonly upfront: Quantity;
|
|
302
|
+
/** The sum of the cost of each meter and the part of the upfront money. */
|
|
303
|
+
readonly total: Quantity;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* This function gives the kind of the metered amount of the unit of a metered price, for example `time` for `USD/h`
|
|
307
|
+
* and `data-time` for `USD/(GiB·mo)`.
|
|
308
|
+
*
|
|
309
|
+
* @throws RangeError when the unit is not a price for each unit of a metered amount.
|
|
310
|
+
*/
|
|
311
|
+
export declare function meteredKindOf(unit: string): MeteredKind;
|
|
312
|
+
/**
|
|
313
|
+
* This schema accepts the location of a metered offer. The name of the provider has small letters, digits and
|
|
314
|
+
* hyphens, as the name of a source. The region and the zone are the ids of the provider.
|
|
315
|
+
*/
|
|
316
|
+
export declare const locationSchema: z.ZodType<Location>;
|
|
317
|
+
/**
|
|
318
|
+
* This schema accepts the term of a metered price. A `spot` term can have the notice before the provider ends the
|
|
319
|
+
* use. A `committed` term has its length.
|
|
320
|
+
*/
|
|
321
|
+
export declare const priceTermSchema: z.ZodType<PriceTerm>;
|
|
322
|
+
/**
|
|
323
|
+
* This schema accepts a metered offer: one resource of a provider in one location, on one term. The id is the
|
|
324
|
+
* source and the source id, with a colon between them.
|
|
325
|
+
*/
|
|
326
|
+
export declare const meteredOfferSchema: z.ZodType<MeteredOffer>;
|
|
327
|
+
/**
|
|
328
|
+
* This schema accepts a metered price of zero or more: an amount of money for each unit of a metered amount, for
|
|
329
|
+
* example `{ "value": 0.0116, "unit": "USD/h" }`.
|
|
330
|
+
*/
|
|
331
|
+
export declare const meteredPriceSchema: z.ZodType<Quantity, Quantity>;
|
|
332
|
+
/** This schema accepts a tier: the start of its usage, and its price for each unit. The start measures the metered amount of the price. */
|
|
333
|
+
export declare const tierSchema: z.ZodType<Tier>;
|
|
334
|
+
/** This schema accepts a free amount of more than zero for each period, and its scope. */
|
|
335
|
+
export declare const freeAmountSchema: z.ZodType<FreeAmount>;
|
|
336
|
+
/**
|
|
337
|
+
* This schema accepts a meter. The first tier starts at zero, and the starts increase. The prices of the tiers and
|
|
338
|
+
* the free amount measure one metered amount.
|
|
339
|
+
*/
|
|
340
|
+
export declare const meterSchema: z.ZodType<Meter>;
|
|
341
|
+
/**
|
|
342
|
+
* This schema accepts a metered reading: the metered prices of one offer at one instant. The tiers and the free
|
|
343
|
+
* amounts count the usage of one `period`. Each meter has its own name.
|
|
344
|
+
*/
|
|
345
|
+
export declare const meteredReadingSchema: z.ZodType<MeteredReading>;
|
|
346
|
+
/** This schema accepts a metered observation: an offer, and a reading of that offer. Only a committed term has upfront money. */
|
|
347
|
+
export declare const meteredObservationSchema: z.ZodType<MeteredObservation>;
|
|
348
|
+
/**
|
|
349
|
+
* This function gives the cost of a metered offer for one period, from the usage of each meter in that period. A
|
|
350
|
+
* meter with no usage costs zero. The free amount of a meter comes off its usage first, less `freeUsed`. The tiers
|
|
351
|
+
* then count the rest of the usage from zero. A committed term adds its upfront money times the period over the length.
|
|
352
|
+
*
|
|
353
|
+
* The arithmetic is exact, and the function does not round the cost to the cent. Each value is the nearest number to
|
|
354
|
+
* the exact cost. The function converts the units with the exact factors of `@mark1russell7/quantity`.
|
|
355
|
+
*
|
|
356
|
+
* @throws RangeError when the usage names a meter that the reading does not have. It also throws when an amount
|
|
357
|
+
* of usage is negative, or does not measure the metered amount of its meter.
|
|
358
|
+
*/
|
|
359
|
+
export declare function meteredCost(observation: MeteredObservation, usage: MeteredUsage, options?: MeteredCostOptions): MeteredCost;
|
|
415
360
|
/**
|
|
416
361
|
* This function gives the unit price for an order of `count` units. The price of the largest break at or
|
|
417
362
|
* below the count applies, or the price of the reading when no break applies.
|
|
@@ -426,5 +371,5 @@ export declare function unitPriceFor(reading: PriceReading, count: number): Quan
|
|
|
426
371
|
* @throws RangeError when the count is not a whole number, or when it is less than the minimum of the reading.
|
|
427
372
|
*/
|
|
428
373
|
export declare function costOf(reading: PriceReading, count: number): Quantity | null;
|
|
429
|
-
export type
|
|
374
|
+
export { AVAILABILITIES, type Availability, type BestOffer, type BestOfferOptions, type Board, type BoardDrop, type BoardRead, CONDITIONS, type Condition, type Dropped, FORMATS, type Format, type FreeAmount, type FreeScope, type Identifiers, type KeepOptions, type Kept, type Location, type Meter, type MeterCost, type MeteredCost, type MeteredCostOptions, type MeteredKind, type MeteredObservation, type MeteredOffer, type MeteredReading, type MeteredUsage, type Observation, type Offer, type OfferChoice, type PartNumber, type PartWant, type PriceBreak, type PriceReading, type PriceTerm, type Product, type Rating, type ReadInterval, type ReadPlan, type Retention, type ScheduleOptions, type Seller, type SettleOptions, type Settled, type Shipping, type SourceTerms, type Spec, type Tier, type WatchEntry, bestOffer, foldCode, gtinSchema, instantSchema, latestObservations, matchKeys, moneySchema, offerId, offerSchema, offersOfPart, offersPart, partNumberSchema, priceBreakSchema, priceReadingSchema, productSchema, sellerSchema, shippingSchema, sourceOfOffer, sourceSchema, specSchema, textSchema };
|
|
430
375
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/terms.ts","../src/board.ts","../src/gtin.ts","../src/metered.ts","../src/price.ts"],"mappings":";;;;;;;;;;;KAMY;WACG;;WACA;WAA0B,KAAK;;WAC/B;;;UAGE;WACN;WACA,WAAW;WACX;WACA;WACA;;;;;;qBAOE,iBAAiB,EAAE,QAAQ;;;;;qBAU3B,mBAAmB,EAAE,QAAQ;;;;;wBAY1B,UAAU,OAAO,aAAa;WAAoB;;;;;;wBAalD,OAAO,OAAO,aAAa;WAAoB;GAAc,aAAa;;wBAW1E,eAAe,OAAO;;wBAKtB,aAAa,OAAO;;qBC7DvB;;qBAGA,mBAAmB,EAAE,QAAQ;;UAKzB;WACN;WACA;WACA,uBAAuB;;;UAIjB;WACN,eAAe;WACf;WACA,gBAAgB;;;qBAId,iBAAiB,EAAE,QAAQ;;qBAO3B,aAAa,EAAE,QAAQ;;UAOnB;WACN;WACA;;;UAIM;;WAEN,gBAAgB;;WAEhB;;WAEA;;;UAIM;;WAEN,eAAe;;WAEf,kBAAkB;;;;;;;;;;;wBAyBb,iBAAiB,uBAAuB,eAAe,SAAS,cAAc;;UA0B7E,sBAAsB;;WAE5B;;;UAIM,kBAAkB;WACxB;;;UAIM;WACN,OAAO;WACP,kBAAkB;;;;;;;;;;wBAab,YAAY,OAAO,OAAO,SAAS,eAAe,OAAO,YAAY;;;;;wBAwBrE,kBAAkB,OAAO,OAAO,SAAS,cAAc;;wBAKvD,UAAU,OAAO,QAAQ;;UAKxB;;WAEN;;WAEA;;WAEA,OAAO;;;qBAIL,kBAAkB,EAAE,QAAQ;;UAOxB;;WAEN,gBAAgB;;;;;WAKhB,OAAO;;;KAIN;WAA0B;WAAmB;;WAA0B;WAAoB;;;;;;;;wBAQvF,aAAa,OAAO,YAAY,SAAS,kBAAkB;;wBAc3D,cAAc,kBAAkB,cAAc,SAAS;;UAatD;;WAEN;;;;;;WAMA;;WAEA;;;;;;;;;wBAUK,UAAU,kBAAkB,cAAc,MAAM,SAAS,yBAAyB,aAAa,SAAS,kBAAkB;;;;;;wBC5P1H,eAAe;;;;;wBAcf,UAAU;;;;;qBCDb;;KAED,sBAAsB;;;;;qBAMrB;;KAED,oBAAoB;;UAGf;WACN;WACA;WACA;;;;;;KAOC;WACG;;WACA;WAAuB,SAAS;;WAChC;WAA4B,QAAQ;;;UAGlC;WACN;WACA;WACA;WACA;WACA;WACA;WACA,UAAU;WACV,MAAM;WACN,gBAAgB;;;UAIV;WACN,MAAM;WACN,WAAW;;;UAIL;WACN,QAAQ;WACR,OAAO;;;UAID;WACN;WACA,gBAAgB;WAChB,OAAO;;;UAID;WACN;WACA;WACA,QAAQ;WACR,iBAAiB;WACjB,UAAU;;;UAIJ;WACN,OAAO;WACP,SAAS;;;KAIR,eAAe,SAAS,eAAe;;UAGlC;;;;;WAKN,WAAW;;;UAIL;WACN;WACA,MAAM;;;UAIA;;WAEN,iBAAiB;;WAEjB,SAAS;;WAET,OAAO;;;;;;;;wBAiFF,cAAc,eAAe;;;;;qBAUhC,gBAAgB,EAAE,QAAQ;;;;;qBAU1B,iBAAiB,EAAE,QAAQ;;;;;qBAU3B,oBAAoB,EAAE,QAAQ;;;;;qBAqB9B,oBAAoB,EAAE,QAAQ,UAAU;;qBAQxC,YAAY,EAAE,QAAQ;;qBAatB,kBAAkB,EAAE,QAAQ;;;;;qBAS5B,aAAa,EAAE,QAAQ;;;;;qBA4CvB,sBAAsB,EAAE,QAAQ;;qBAchC,0BAA0B,EAAE,QAAQ;;;;;;;;;;;;wBAqFjC,YAAY,aAAa,oBAAoB,OAAO,cAAc,UAAS,qBAA0B;;;;;;;wBCrarG,aAAa,SAAS,cAAc,gBAAgB;;;;;;;wBAgBpD,OAAO,SAAS,cAAc,gBAAgB"}
|