@mark1russell7/market 0.1.4 → 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 +64 -1
- package/build/index.d.ts +155 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +347 -2
- package/build/index.js.map +1 -1
- package/package.json +5 -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. A buy plan gives the best baskets of the parts that a need names.
|
|
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
|
|
@@ -112,6 +112,66 @@ const plan = planBuys(need, observations);
|
|
|
112
112
|
plan.front.map((choice) => [choice.price.value, choice.values["minutes"]]); // [[120, 20], [200, 50], [280, 80], [420, 100]]
|
|
113
113
|
```
|
|
114
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
|
+
|
|
115
175
|
## Example
|
|
116
176
|
|
|
117
177
|
```ts
|
|
@@ -141,6 +201,9 @@ isKept(terms, reading, "2026-11-16T00:00:00Z"); // false
|
|
|
141
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.
|
|
142
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.
|
|
143
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`.
|
|
144
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.
|
|
145
208
|
- A buy plan does not compare the count of an item with the count of the available units of its offer.
|
|
146
209
|
- The package has no history of prices yet. Roadmap item R5 adds it, after the owner chooses its source.
|
package/build/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
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
|
*/
|
|
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";
|
|
8
9
|
import { Quantity } from "@mark1russell7/quantity";
|
|
@@ -203,6 +204,159 @@ export declare function gtinCheckDigit(body: string): number;
|
|
|
203
204
|
* It refuses a length other than 8, 12, 13 or 14 digits, a wrong check digit, and a GTIN of zeros only.
|
|
204
205
|
*/
|
|
205
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;
|
|
206
360
|
/**
|
|
207
361
|
* This function gives the unit price for an order of `count` units. The price of the largest break at or
|
|
208
362
|
* below the count applies, or the price of the reading when no break applies.
|
|
@@ -217,5 +371,5 @@ export declare function unitPriceFor(reading: PriceReading, count: number): Quan
|
|
|
217
371
|
* @throws RangeError when the count is not a whole number, or when it is less than the minimum of the reading.
|
|
218
372
|
*/
|
|
219
373
|
export declare function costOf(reading: PriceReading, count: number): Quantity | null;
|
|
220
|
-
export { AVAILABILITIES, type Availability, type BestOffer, type BestOfferOptions, type Board, type BoardDrop, type BoardRead, CONDITIONS, type Condition, type Dropped, FORMATS, type Format, type Identifiers, type KeepOptions, type Kept, type Observation, type Offer, type OfferChoice, type PartNumber, type PartWant, type PriceBreak, type PriceReading, 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 WatchEntry, bestOffer, foldCode, gtinSchema, instantSchema, latestObservations, matchKeys, moneySchema, offerId, offerSchema, offersOfPart, offersPart, partNumberSchema, priceBreakSchema, priceReadingSchema, productSchema, sellerSchema, shippingSchema, sourceOfOffer, sourceSchema, specSchema, textSchema };
|
|
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 };
|
|
221
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/terms.ts","../src/board.ts","../src/gtin.ts","../src/price.ts"],"mappings":"
|
|
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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BAA0B;;;;;;;wBCrarG,aAAa,SAAS,cAAc,gBAAgB;;;;;;;wBAgBpD,OAAO,SAAS,cAAc,gBAAgB"}
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { C as costOf, D as gtinCheckDigit, E as matchKeys, O as parseGtin, S as offersPart, T as foldCode, _ as specSchema, a as instantSchema, b as latestObservations, c as offerSchema, d as priceReadingSchema, f as productSchema, g as sourceSchema, h as sourceOfOffer, i as gtinSchema, l as partNumberSchema, m as shippingSchema, n as CONDITIONS, o as moneySchema, p as sellerSchema, r as FORMATS, s as offerId, t as AVAILABILITIES, u as priceBreakSchema, v as textSchema, w as unitPriceFor, x as offersOfPart, y as bestOffer } from "./records-hK1UCmpm.js";
|
|
2
|
-
import { valueIn } from "@mark1russell7/quantity";
|
|
2
|
+
import { UnitError, canonicalUnit, convertExact, convertible, parseUnit, quantity, rationals, valueIn } from "@mark1russell7/quantity";
|
|
3
3
|
import { quantitySchema } from "@mark1russell7/quantity/schema";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
// src/terms.ts
|
|
@@ -284,6 +284,351 @@ function planReads(entries, last, now, options) {
|
|
|
284
284
|
next: Number.isFinite(next) ? new Date(next).toISOString() : null
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
|
-
|
|
287
|
+
// src/metered.ts
|
|
288
|
+
/**
|
|
289
|
+
* The kinds of a metered amount: a time (the hours of a machine), data times time (stored data), data (a transfer)
|
|
290
|
+
* and a count (requests).
|
|
291
|
+
*/
|
|
292
|
+
const METERED_KINDS = [
|
|
293
|
+
"time",
|
|
294
|
+
"data-time",
|
|
295
|
+
"data",
|
|
296
|
+
"count"
|
|
297
|
+
];
|
|
298
|
+
/**
|
|
299
|
+
* The scopes of a free amount. With `account`, all the usage of the account in all regions shares one free amount.
|
|
300
|
+
* With `region`, each region has its own free amount. With `resource`, each resource has its own free amount.
|
|
301
|
+
*/
|
|
302
|
+
const FREE_SCOPES = [
|
|
303
|
+
"account",
|
|
304
|
+
"region",
|
|
305
|
+
"resource"
|
|
306
|
+
];
|
|
307
|
+
/** This function gives the kind of a metered amount from the exponents of its data and its time, or undefined. */
|
|
308
|
+
function kindOfExponents(data, time) {
|
|
309
|
+
if (data === 0 && time === 0) return "count";
|
|
310
|
+
if (data === 0 && time === 1) return "time";
|
|
311
|
+
if (data === 1 && time === 0) return "data";
|
|
312
|
+
if (data === 1 && time === 1) return "data-time";
|
|
313
|
+
}
|
|
314
|
+
/** This function reads the unit of a metered price. It gives the parts of the unit, or the problem as a text. */
|
|
315
|
+
function readPriceUnit(unit) {
|
|
316
|
+
const refused = `The unit ${unit} is not a price for each unit of a metered amount, for example USD/h.`;
|
|
317
|
+
let parsed;
|
|
318
|
+
try {
|
|
319
|
+
parsed = parseUnit(unit);
|
|
320
|
+
} catch (error) {
|
|
321
|
+
if (error instanceof UnitError) return refused;
|
|
322
|
+
throw error;
|
|
323
|
+
}
|
|
324
|
+
const above = parsed.components.filter((component) => component.exponent > 0);
|
|
325
|
+
const [money] = above;
|
|
326
|
+
const atom = money?.atom;
|
|
327
|
+
const isMoney = atom !== void 0 && Object.keys(atom.vector).length === 1 && atom.vector.money === 1;
|
|
328
|
+
const below = parsed.components.some((component) => component.exponent < 0);
|
|
329
|
+
if (above.length !== 1 || money?.exponent !== 1 || money.annotation !== void 0 || !isMoney || !below) return refused;
|
|
330
|
+
const { money: units = 0, data = 0, time = 0, ...others } = parsed.vector;
|
|
331
|
+
const kind = Object.values(others).every((exponent) => exponent === 0) && units === 1 ? kindOfExponents(-data, -time) : void 0;
|
|
332
|
+
return kind === void 0 ? refused : {
|
|
333
|
+
money: atom.symbol,
|
|
334
|
+
kind
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
/** This function gives the unit of a price for each unit of an amount, for example `USD/(GiB·mo)` for `GiB·mo`. */
|
|
338
|
+
function priceUnitFor(money, amountUnit) {
|
|
339
|
+
try {
|
|
340
|
+
return canonicalUnit(`${money}/${amountUnit}`);
|
|
341
|
+
} catch (error) {
|
|
342
|
+
if (error instanceof UnitError) return void 0;
|
|
343
|
+
throw error;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/** This function tells if an amount in one unit converts to another unit. A unit that the quantity package does not know does not convert. */
|
|
347
|
+
function converts(from, to) {
|
|
348
|
+
try {
|
|
349
|
+
return convertible(from, to);
|
|
350
|
+
} catch (error) {
|
|
351
|
+
if (error instanceof UnitError) return false;
|
|
352
|
+
throw error;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
/** This function gives the start of each tier in one unit, or undefined when a start does not convert to it. */
|
|
356
|
+
function startsOf(tiers, unit) {
|
|
357
|
+
try {
|
|
358
|
+
return tiers.map((tier) => convertExact(rationals.fromNumber(tier.from.value), tier.from.unit, unit));
|
|
359
|
+
} catch (error) {
|
|
360
|
+
if (error instanceof UnitError || error instanceof RangeError) return void 0;
|
|
361
|
+
throw error;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/** This function tells if a unit of an amount measures the metered amount of a unit of price. */
|
|
365
|
+
function measures(amountUnit, priceUnit, money) {
|
|
366
|
+
const unit = priceUnitFor(money, amountUnit);
|
|
367
|
+
return unit !== void 0 && converts(unit, priceUnit);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* This function gives the kind of the metered amount of the unit of a metered price, for example `time` for `USD/h`
|
|
371
|
+
* and `data-time` for `USD/(GiB·mo)`.
|
|
372
|
+
*
|
|
373
|
+
* @throws RangeError when the unit is not a price for each unit of a metered amount.
|
|
374
|
+
*/
|
|
375
|
+
function meteredKindOf(unit) {
|
|
376
|
+
const parts = readPriceUnit(unit);
|
|
377
|
+
if (typeof parts === "string") throw new RangeError(parts);
|
|
378
|
+
return parts.kind;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* This schema accepts the location of a metered offer. The name of the provider has small letters, digits and
|
|
382
|
+
* hyphens, as the name of a source. The region and the zone are the ids of the provider.
|
|
383
|
+
*/
|
|
384
|
+
const locationSchema = z.strictObject({
|
|
385
|
+
provider: sourceSchema,
|
|
386
|
+
region: textSchema,
|
|
387
|
+
zone: textSchema.optional()
|
|
388
|
+
});
|
|
389
|
+
/**
|
|
390
|
+
* This schema accepts the term of a metered price. A `spot` term can have the notice before the provider ends the
|
|
391
|
+
* use. A `committed` term has its length.
|
|
392
|
+
*/
|
|
393
|
+
const priceTermSchema = z.discriminatedUnion("kind", [
|
|
394
|
+
z.strictObject({ kind: z.literal("on-demand") }),
|
|
395
|
+
z.strictObject({
|
|
396
|
+
kind: z.literal("spot"),
|
|
397
|
+
notice: quantitySchema("time", { nonnegative: true }).optional()
|
|
398
|
+
}),
|
|
399
|
+
z.strictObject({
|
|
400
|
+
kind: z.literal("committed"),
|
|
401
|
+
length: quantitySchema("time", { positive: true })
|
|
402
|
+
})
|
|
403
|
+
]);
|
|
404
|
+
/**
|
|
405
|
+
* This schema accepts a metered offer: one resource of a provider in one location, on one term. The id is the
|
|
406
|
+
* source and the source id, with a colon between them.
|
|
407
|
+
*/
|
|
408
|
+
const meteredOfferSchema = z.strictObject({
|
|
409
|
+
id: textSchema,
|
|
410
|
+
source: sourceSchema,
|
|
411
|
+
sourceId: textSchema,
|
|
412
|
+
productId: textSchema.optional(),
|
|
413
|
+
title: textSchema,
|
|
414
|
+
url: z.url({ protocol: /^https$/ }).optional(),
|
|
415
|
+
location: locationSchema,
|
|
416
|
+
term: priceTermSchema,
|
|
417
|
+
specs: z.array(specSchema)
|
|
418
|
+
}).refine((offer) => offer.id === offerId(offer.source, offer.sourceId), {
|
|
419
|
+
message: "The id of an offer is its source and its source id, with a colon between them.",
|
|
420
|
+
path: ["id"]
|
|
421
|
+
});
|
|
422
|
+
/**
|
|
423
|
+
* This schema accepts a metered price of zero or more: an amount of money for each unit of a metered amount, for
|
|
424
|
+
* example `{ "value": 0.0116, "unit": "USD/h" }`.
|
|
425
|
+
*/
|
|
426
|
+
const meteredPriceSchema = quantitySchema(void 0, { nonnegative: true }).superRefine((price, context) => {
|
|
427
|
+
const parts = readPriceUnit(price.unit);
|
|
428
|
+
if (typeof parts === "string") context.addIssue({
|
|
429
|
+
code: "custom",
|
|
430
|
+
message: parts
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
/** 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. */
|
|
434
|
+
const tierSchema = z.strictObject({
|
|
435
|
+
from: quantitySchema(void 0, { nonnegative: true }),
|
|
436
|
+
unitPrice: meteredPriceSchema
|
|
437
|
+
}).superRefine((tier, context) => {
|
|
438
|
+
const parts = readPriceUnit(tier.unitPrice.unit);
|
|
439
|
+
if (typeof parts === "string" || measures(tier.from.unit, tier.unitPrice.unit, parts.money)) return;
|
|
440
|
+
context.addIssue({
|
|
441
|
+
code: "custom",
|
|
442
|
+
message: `The start ${tier.from.unit} does not measure the metered amount of the price ${tier.unitPrice.unit}.`,
|
|
443
|
+
path: ["from"]
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
/** This schema accepts a free amount of more than zero for each period, and its scope. */
|
|
447
|
+
const freeAmountSchema = z.strictObject({
|
|
448
|
+
amount: quantitySchema(void 0, { positive: true }),
|
|
449
|
+
scope: z.enum(FREE_SCOPES)
|
|
450
|
+
});
|
|
451
|
+
/**
|
|
452
|
+
* This schema accepts a meter. The first tier starts at zero, and the starts increase. The prices of the tiers and
|
|
453
|
+
* the free amount measure one metered amount.
|
|
454
|
+
*/
|
|
455
|
+
const meterSchema = z.strictObject({
|
|
456
|
+
name: textSchema,
|
|
457
|
+
tiers: z.array(tierSchema).min(1),
|
|
458
|
+
free: freeAmountSchema.optional()
|
|
459
|
+
}).superRefine((meter, context) => {
|
|
460
|
+
const [first] = meter.tiers;
|
|
461
|
+
if (first === void 0) return;
|
|
462
|
+
const parts = readPriceUnit(first.unitPrice.unit);
|
|
463
|
+
if (typeof parts === "string") return;
|
|
464
|
+
let units = true;
|
|
465
|
+
for (const [index, tier] of meter.tiers.entries()) {
|
|
466
|
+
if (converts(tier.unitPrice.unit, first.unitPrice.unit) && measures(tier.from.unit, first.unitPrice.unit, parts.money)) continue;
|
|
467
|
+
units = false;
|
|
468
|
+
context.addIssue({
|
|
469
|
+
code: "custom",
|
|
470
|
+
message: `The tier ${index} does not measure the metered amount of the price ${first.unitPrice.unit}.`,
|
|
471
|
+
path: ["tiers", index]
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
if (meter.free !== void 0 && !measures(meter.free.amount.unit, first.unitPrice.unit, parts.money)) context.addIssue({
|
|
475
|
+
code: "custom",
|
|
476
|
+
message: `The free amount ${meter.free.amount.unit} does not measure the metered amount of the price ${first.unitPrice.unit}.`,
|
|
477
|
+
path: ["free", "amount"]
|
|
478
|
+
});
|
|
479
|
+
if (!units) return;
|
|
480
|
+
const starts = startsOf(meter.tiers, first.from.unit);
|
|
481
|
+
if (starts === void 0) return;
|
|
482
|
+
if (rationals.sign(starts[0] ?? rationals.ZERO) !== 0) context.addIssue({
|
|
483
|
+
code: "custom",
|
|
484
|
+
message: "The first tier does not start at zero.",
|
|
485
|
+
path: [
|
|
486
|
+
"tiers",
|
|
487
|
+
0,
|
|
488
|
+
"from"
|
|
489
|
+
]
|
|
490
|
+
});
|
|
491
|
+
for (let index = 1; index < starts.length; index += 1) {
|
|
492
|
+
if (rationals.cmp(starts[index] ?? rationals.ZERO, starts[index - 1] ?? rationals.ZERO) > 0) continue;
|
|
493
|
+
context.addIssue({
|
|
494
|
+
code: "custom",
|
|
495
|
+
message: `The tier ${index} does not start after the tier ${index - 1}.`,
|
|
496
|
+
path: [
|
|
497
|
+
"tiers",
|
|
498
|
+
index,
|
|
499
|
+
"from"
|
|
500
|
+
]
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
/**
|
|
505
|
+
* This schema accepts a metered reading: the metered prices of one offer at one instant. The tiers and the free
|
|
506
|
+
* amounts count the usage of one `period`. Each meter has its own name.
|
|
507
|
+
*/
|
|
508
|
+
const meteredReadingSchema = z.strictObject({
|
|
509
|
+
offerId: textSchema,
|
|
510
|
+
at: instantSchema,
|
|
511
|
+
period: quantitySchema("time", { positive: true }),
|
|
512
|
+
meters: z.array(meterSchema).min(1),
|
|
513
|
+
upfront: moneySchema.optional()
|
|
514
|
+
}).refine((reading) => new Set(reading.meters.map((meter) => meter.name)).size === reading.meters.length, {
|
|
515
|
+
message: "The reading has two meters with one name.",
|
|
516
|
+
path: ["meters"]
|
|
517
|
+
});
|
|
518
|
+
/** This schema accepts a metered observation: an offer, and a reading of that offer. Only a committed term has upfront money. */
|
|
519
|
+
const meteredObservationSchema = z.strictObject({
|
|
520
|
+
offer: meteredOfferSchema,
|
|
521
|
+
reading: meteredReadingSchema
|
|
522
|
+
}).superRefine((each, context) => {
|
|
523
|
+
if (each.reading.offerId !== each.offer.id) context.addIssue({
|
|
524
|
+
code: "custom",
|
|
525
|
+
message: "The reading is not a reading of the offer.",
|
|
526
|
+
path: ["reading", "offerId"]
|
|
527
|
+
});
|
|
528
|
+
if (each.reading.upfront !== void 0 && each.offer.term.kind !== "committed") context.addIssue({
|
|
529
|
+
code: "custom",
|
|
530
|
+
message: `The term ${each.offer.term.kind} has no upfront money.`,
|
|
531
|
+
path: ["reading", "upfront"]
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
/** This function gives the value of an amount in a unit, as an exact rational. */
|
|
535
|
+
function exactIn(amount, unit) {
|
|
536
|
+
return convertExact(rationals.fromNumber(amount.value), amount.unit, unit);
|
|
537
|
+
}
|
|
538
|
+
/** This function gives the larger of two rationals. */
|
|
539
|
+
function larger(a, b) {
|
|
540
|
+
return rationals.cmp(a, b) >= 0 ? a : b;
|
|
541
|
+
}
|
|
542
|
+
/** This function gives the smaller of two rationals. */
|
|
543
|
+
function smaller(a, b) {
|
|
544
|
+
return rationals.cmp(a, b) <= 0 ? a : b;
|
|
545
|
+
}
|
|
546
|
+
/** This function examines an amount of usage of a meter, and gives its value in its own unit. */
|
|
547
|
+
function usageValue(meter, amount, priceUnit, money, what) {
|
|
548
|
+
if (!Number.isFinite(amount.value) || amount.value < 0) throw new RangeError(`The ${what} of the meter ${meter.name} is ${amount.value}, not an amount of zero or more.`);
|
|
549
|
+
if (!measures(amount.unit, priceUnit, money)) throw new RangeError(`The ${what} of the meter ${meter.name} is in ${amount.unit}, which does not measure the price ${priceUnit}.`);
|
|
550
|
+
return rationals.fromNumber(amount.value);
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* This function gives the exact cost of the usage of one meter, in the unit of money of its first tier. The free
|
|
554
|
+
* amount comes off the usage first. The tiers then count the rest of the usage from zero.
|
|
555
|
+
*/
|
|
556
|
+
function costOfMeter(meter, used, freeUsed) {
|
|
557
|
+
const [first] = meter.tiers;
|
|
558
|
+
if (first === void 0) throw new RangeError(`The meter ${meter.name} has no tier.`);
|
|
559
|
+
const parts = readPriceUnit(first.unitPrice.unit);
|
|
560
|
+
if (typeof parts === "string") throw new RangeError(parts);
|
|
561
|
+
const { money } = parts;
|
|
562
|
+
if (used === void 0) return {
|
|
563
|
+
money,
|
|
564
|
+
cost: rationals.ZERO
|
|
565
|
+
};
|
|
566
|
+
const amount = usageValue(meter, used, first.unitPrice.unit, money, "usage");
|
|
567
|
+
const unit = used.unit;
|
|
568
|
+
const perUnit = priceUnitFor(money, unit);
|
|
569
|
+
if (perUnit === void 0) throw new RangeError(`The usage of the meter ${meter.name} is in ${unit}, which has no price unit.`);
|
|
570
|
+
let free = rationals.ZERO;
|
|
571
|
+
if (meter.free !== void 0) free = exactIn(meter.free.amount, unit);
|
|
572
|
+
if (freeUsed !== void 0) {
|
|
573
|
+
usageValue(meter, freeUsed, first.unitPrice.unit, money, "used free amount");
|
|
574
|
+
free = larger(rationals.ZERO, rationals.sub(free, exactIn(freeUsed, unit)));
|
|
575
|
+
}
|
|
576
|
+
const billed = larger(rationals.ZERO, rationals.sub(amount, free));
|
|
577
|
+
let cost = rationals.ZERO;
|
|
578
|
+
for (const [index, tier] of meter.tiers.entries()) {
|
|
579
|
+
const start = exactIn(tier.from, unit);
|
|
580
|
+
const next = meter.tiers[index + 1];
|
|
581
|
+
const end = next === void 0 ? billed : smaller(billed, exactIn(next.from, unit));
|
|
582
|
+
if (rationals.cmp(end, start) <= 0) continue;
|
|
583
|
+
cost = rationals.add(cost, rationals.mul(rationals.sub(end, start), exactIn(tier.unitPrice, perUnit)));
|
|
584
|
+
}
|
|
585
|
+
return {
|
|
586
|
+
money,
|
|
587
|
+
cost
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* This function gives the cost of a metered offer for one period, from the usage of each meter in that period. A
|
|
592
|
+
* meter with no usage costs zero. The free amount of a meter comes off its usage first, less `freeUsed`. The tiers
|
|
593
|
+
* then count the rest of the usage from zero. A committed term adds its upfront money times the period over the length.
|
|
594
|
+
*
|
|
595
|
+
* The arithmetic is exact, and the function does not round the cost to the cent. Each value is the nearest number to
|
|
596
|
+
* the exact cost. The function converts the units with the exact factors of `@mark1russell7/quantity`.
|
|
597
|
+
*
|
|
598
|
+
* @throws RangeError when the usage names a meter that the reading does not have. It also throws when an amount
|
|
599
|
+
* of usage is negative, or does not measure the metered amount of its meter.
|
|
600
|
+
*/
|
|
601
|
+
function meteredCost(observation, usage, options = {}) {
|
|
602
|
+
const { offer, reading } = observation;
|
|
603
|
+
const { freeUsed = {} } = options;
|
|
604
|
+
const names = new Set(reading.meters.map((meter) => meter.name));
|
|
605
|
+
for (const name of [...Object.keys(usage), ...Object.keys(freeUsed)]) if (!names.has(name)) throw new RangeError(`The reading of ${reading.offerId} has no meter ${name}.`);
|
|
606
|
+
const at = (record, name) => Object.hasOwn(record, name) ? record[name] : void 0;
|
|
607
|
+
const costs = reading.meters.map((meter) => ({
|
|
608
|
+
name: meter.name,
|
|
609
|
+
...costOfMeter(meter, at(usage, meter.name), at(freeUsed, meter.name))
|
|
610
|
+
}));
|
|
611
|
+
const unit = costs[0]?.money;
|
|
612
|
+
if (unit === void 0) throw new RangeError(`The reading of ${reading.offerId} has no meter.`);
|
|
613
|
+
let total = rationals.ZERO;
|
|
614
|
+
for (const each of costs) total = rationals.add(total, convertExact(each.cost, each.money, unit));
|
|
615
|
+
const meters = costs.map((each) => ({
|
|
616
|
+
name: each.name,
|
|
617
|
+
cost: quantity(rationals.toNumber(each.cost), each.money)
|
|
618
|
+
}));
|
|
619
|
+
let upfront = rationals.ZERO;
|
|
620
|
+
if (offer.term.kind === "committed" && reading.upfront !== void 0) {
|
|
621
|
+
const { length } = offer.term;
|
|
622
|
+
const share = rationals.div(exactIn(reading.period, length.unit), rationals.fromNumber(length.value));
|
|
623
|
+
upfront = rationals.mul(exactIn(reading.upfront, unit), share);
|
|
624
|
+
}
|
|
625
|
+
total = rationals.add(total, upfront);
|
|
626
|
+
return {
|
|
627
|
+
meters,
|
|
628
|
+
upfront: quantity(rationals.toNumber(upfront), unit),
|
|
629
|
+
total: quantity(rationals.toNumber(total), unit)
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
export { AVAILABILITIES, BOARD_FORMAT, CONDITIONS, FORMATS, FREE_SCOPES, METERED_KINDS, bestOffer, boardObservations, boardReadSchema, boardSchema, costOf, foldCode, freeAmountSchema, gtinCheckDigit, gtinSchema, instantSchema, isKept, keepObservations, keepUntil, lastReads, latestObservations, locationSchema, matchKeys, meterSchema, meteredCost, meteredKindOf, meteredObservationSchema, meteredOfferSchema, meteredPriceSchema, meteredReadingSchema, moneySchema, observationSchema, offerId, offerSchema, offersOfPart, offersPart, parseGtin, partNumberSchema, permitsHistory, permitsTrend, planReads, priceBreakSchema, priceReadingSchema, priceTermSchema, productSchema, readInterval, retentionSchema, sellerSchema, settleBoard, shippingSchema, sourceOfOffer, sourceSchema, sourceTermsSchema, specSchema, textSchema, tierSchema, unitPriceFor, watchEntrySchema, watchProblems };
|
|
288
633
|
|
|
289
634
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/terms.ts","../src/board.ts"],"sourcesContent":["import { valueIn, type Quantity } from \"@mark1russell7/quantity\";\nimport { quantitySchema } from \"@mark1russell7/quantity/schema\";\nimport { z } from \"zod\";\nimport { sourceSchema, textSchema } from \"./records.ts\";\n\n/** The storage rule of a source, from its terms. */\nexport type Retention =\n | { readonly kind: \"keep\" }\n | { readonly kind: \"max-age\"; readonly age: Quantity }\n | { readonly kind: \"no-store\" };\n\n/** The rules of the terms of one source. */\nexport interface SourceTerms {\n readonly source: string;\n readonly retention: Retention;\n readonly deleteWhenEnded: boolean;\n readonly priceModel: boolean;\n readonly clause: string;\n}\n\n/**\n * This schema accepts the storage rule of a source, from its terms. With `keep`, the terms set no limit on the\n * time. With `max-age`, a store keeps a reading for `age` at most. With `no-store`, a reading serves one request.\n */\nexport const retentionSchema: z.ZodType<Retention> = z.discriminatedUnion(\"kind\", [\n z.strictObject({ kind: z.literal(\"keep\") }),\n z.strictObject({ kind: z.literal(\"max-age\"), age: quantitySchema(\"time\", { positive: true }) }),\n z.strictObject({ kind: z.literal(\"no-store\") }),\n]);\n\n/**\n * This schema accepts the rules of the terms of one source. `deleteWhenEnded` deletes the readings of an offer\n * when the offer ends. `priceModel` permits a trend or a forecast of prices. `clause` names the text of the terms.\n */\nexport const sourceTermsSchema: z.ZodType<SourceTerms> = z.strictObject({\n source: sourceSchema,\n retention: retentionSchema,\n deleteWhenEnded: z.boolean(),\n priceModel: z.boolean(),\n clause: textSchema,\n});\n\n/**\n * This function gives the last instant at which a store keeps a reading, or null when the terms set no\n * limit. For a source with `no-store`, the instant is the instant of the reading.\n */\nexport function keepUntil(terms: SourceTerms, reading: { readonly at: string }): string | null {\n const { retention } = terms;\n if (retention.kind === \"keep\") return null;\n const at = Date.parse(reading.at);\n if (Number.isNaN(at)) throw new RangeError(`The instant ${JSON.stringify(reading.at)} is not an instant.`);\n if (retention.kind === \"no-store\") return new Date(at).toISOString();\n return new Date(at + Math.floor(valueIn(retention.age, \"ms\"))).toISOString();\n}\n\n/**\n * This function tells if a store keeps a reading at the instant `now`. A store keeps no reading of a source with\n * `no-store`, and no reading of an ended offer when the terms delete them.\n */\nexport function isKept(terms: SourceTerms, reading: { readonly at: string }, now: string, ended = false): boolean {\n if (ended && terms.deleteWhenEnded) return false;\n if (terms.retention.kind === \"no-store\") return false;\n const until = keepUntil(terms, reading);\n if (until === null) return true;\n const instant = Date.parse(now);\n if (Number.isNaN(instant)) throw new RangeError(`The instant ${JSON.stringify(now)} is not an instant.`);\n return instant <= Date.parse(until);\n}\n\n/** This function tells if the terms permit a stored history of the readings of a source. */\nexport function permitsHistory(terms: SourceTerms): boolean {\n return terms.retention.kind === \"keep\" && !terms.deleteWhenEnded;\n}\n\n/** This function tells if the terms permit a trend of the prices of a source: a history and a model of prices. */\nexport function permitsTrend(terms: SourceTerms): boolean {\n return permitsHistory(terms) && terms.priceModel;\n}\n","import { valueIn, type Quantity } from \"@mark1russell7/quantity\";\nimport { quantitySchema } from \"@mark1russell7/quantity/schema\";\nimport { z } from \"zod\";\nimport { latestObservations, type Observation } from \"./offers.ts\";\nimport { instantSchema, offerSchema, priceReadingSchema, sourceSchema, textSchema } from \"./records.ts\";\nimport { isKept, keepUntil, type SourceTerms } from \"./terms.ts\";\n\n/*\n * This module calculates a board of current prices. A watch reads its sources on a schedule. The board keeps the\n * last read of each entry of the watch, within the terms of each source. Each function of this module is a\n * calculation with no effect. A host does the reads and writes the board.\n */\n\n/** The format name of a board record. */\nexport const BOARD_FORMAT = \"price-board/1\";\n\n/** This schema accepts an observation: an offer, and a reading of that offer. */\nexport const observationSchema: z.ZodType<Observation> = z\n .strictObject({ offer: offerSchema, reading: priceReadingSchema })\n .refine((each) => each.reading.offerId === each.offer.id, { message: \"The reading is not a reading of the offer.\" });\n\n/** This record is the last read of one entry of a watch: the name of the entry, the instant, and the observations. */\nexport interface BoardRead {\n readonly name: string;\n readonly at: string;\n readonly observations: readonly Observation[];\n}\n\n/** This record is a board: the instant of its last settle, and the last read of each entry, in the order of the names. */\nexport interface Board {\n readonly format: typeof BOARD_FORMAT;\n readonly at: string;\n readonly reads: readonly BoardRead[];\n}\n\n/** This schema accepts the read of an entry. The read has one observation of each offer at most. */\nexport const boardReadSchema: z.ZodType<BoardRead> = z\n .strictObject({ name: textSchema, at: instantSchema, observations: z.array(observationSchema) })\n .refine((read) => new Set(read.observations.map((each) => each.offer.id)).size === read.observations.length, {\n message: \"The read has two observations of one offer.\",\n });\n\n/** This schema accepts a board. The board has one read of each entry at most. */\nexport const boardSchema: z.ZodType<Board> = z\n .strictObject({ format: z.literal(BOARD_FORMAT), at: instantSchema, reads: z.array(boardReadSchema) })\n .refine((board) => new Set(board.reads.map((each) => each.name)).size === board.reads.length, {\n message: \"The board has two reads of one entry.\",\n });\n\n/** This record is an offer that the store does not keep, with the reason. */\nexport interface Dropped {\n readonly offerId: string;\n readonly why: string;\n}\n\n/** These options give the rules of a store: the terms of each source, the instant, and the offers that ended. */\nexport interface KeepOptions {\n /** The terms of the sources. A store keeps no reading of a source without terms. */\n readonly terms: readonly SourceTerms[];\n /** The instant of the decision. */\n readonly now: string;\n /** The ids of the offers that ended, as their sources tell. An offer with `endsAt` at or before `now` also ended. */\n readonly ended?: readonly string[] | undefined;\n}\n\n/** This record is the decision of a store: the observations that it keeps, and each offer that it drops. */\nexport interface Kept {\n /** The latest observation of each kept offer, in the order of the offer ids. */\n readonly kept: readonly Observation[];\n /** Each dropped offer, in the order of the offer ids. */\n readonly dropped: readonly Dropped[];\n}\n\n/** This function gives the terms of each source by its name. Two terms of one source are a problem of the input. */\nfunction termsBySource(terms: readonly SourceTerms[]): ReadonlyMap<string, SourceTerms> {\n const map = new Map<string, SourceTerms>();\n for (const each of terms) {\n if (map.has(each.source)) throw new RangeError(`The terms of the source ${each.source} are in the list two times.`);\n map.set(each.source, each);\n }\n return map;\n}\n\n/** This function gives the text of an amount of time, for example `6 h`. */\nconst timeText = (age: Quantity): string => `${age.value} ${age.unit}`;\n\n/**\n * This function decides which observations a store keeps. It takes the latest observation of each offer. It keeps\n * an observation while the terms of its source permit it, and while its offer has not ended. A current price is\n * a price that a buyer can pay, so the store drops an ended offer for each source.\n *\n * `settleBoard` applies this function to each read of a board.\n *\n * @throws RangeError when `now` is not an instant, or when the terms have two entries for one source.\n */\nexport function keepObservations(observations: readonly Observation[], options: KeepOptions): Kept {\n const terms = termsBySource(options.terms);\n const now = Date.parse(options.now);\n if (Number.isNaN(now)) throw new RangeError(`The instant ${JSON.stringify(options.now)} is not an instant.`);\n const ended = new Set(options.ended ?? []);\n const kept: Observation[] = [];\n const dropped: Dropped[] = [];\n for (const observation of latestObservations(observations)) {\n const { offer, reading } = observation;\n const rules = terms.get(offer.source);\n const endsAt = offer.endsAt === undefined ? Number.NaN : Date.parse(offer.endsAt);\n const over = ended.has(offer.id) || endsAt <= now;\n if (rules === undefined) dropped.push({ offerId: offer.id, why: `The terms of the source ${offer.source} are not known, so a store keeps no reading of it.` });\n else if (rules.retention.kind === \"no-store\") dropped.push({ offerId: offer.id, why: `The terms of ${offer.source} permit no store: a reading serves one request.` });\n else if (over) {\n const rule = rules.deleteWhenEnded ? `, and the terms of ${offer.source} delete its readings` : \"\";\n dropped.push({ offerId: offer.id, why: `The offer ended${rule}.` });\n } else if (!isKept(rules, reading, options.now)) {\n const age = rules.retention.kind === \"max-age\" ? timeText(rules.retention.age) : \"\";\n dropped.push({ offerId: offer.id, why: `The reading of ${reading.at} passed the limit of ${age} of the terms of ${offer.source} at ${keepUntil(rules, reading)}.` });\n } else kept.push(observation);\n }\n return { kept, dropped };\n}\n\n/** These options give the rules of a settle: the rules of a store, and the names of the entries of the watch. */\nexport interface SettleOptions extends KeepOptions {\n /** The names of the entries of the watch. The board drops the read of each other name. With no list, it keeps each read. */\n readonly names?: readonly string[] | undefined;\n}\n\n/** This record is an offer that the board drops, with the name of the entry of its read. */\nexport interface BoardDrop extends Dropped {\n readonly entry: string;\n}\n\n/** This record is the result of a settle: the new board, and each offer that it dropped. */\nexport interface Settled {\n readonly board: Board;\n readonly dropped: readonly BoardDrop[];\n}\n\nconst byText = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0);\n\n/**\n * This function settles a board at `now`. A new read replaces the last read of its entry, so an offer that the new\n * read does not give leaves the read. Then `keepObservations` applies the terms to each read. The board drops the\n * read of an entry that the watch does not have. Write the new board in place of the old board.\n *\n * @param read - A new read of an entry, or none to settle the board alone\n * @throws RangeError when `now` is not an instant, or when the terms have two entries for one source.\n */\nexport function settleBoard(board: Board, options: SettleOptions, read?: BoardRead): Settled {\n const names = options.names === undefined ? undefined : new Set(options.names);\n const reads = new Map(board.reads.map((each) => [each.name, each]));\n if (read !== undefined) reads.set(read.name, read);\n const settled: BoardRead[] = [];\n const dropped: BoardDrop[] = [];\n for (const name of [...reads.keys()].sort(byText)) {\n const each = reads.get(name);\n if (each === undefined) continue;\n if (names !== undefined && !names.has(name)) {\n for (const gone of latestObservations(each.observations)) dropped.push({ entry: name, offerId: gone.offer.id, why: `The watch has no entry ${name}.` });\n continue;\n }\n const decision = keepObservations(each.observations, options);\n settled.push({ name, at: each.at, observations: decision.kept });\n for (const drop of decision.dropped) dropped.push({ entry: name, ...drop });\n }\n return { board: { format: BOARD_FORMAT, at: options.now, reads: settled }, dropped };\n}\n\n/**\n * This function gives the current observations of a board at `now`. Each is the latest observation of an offer over\n * the reads, while the terms of its source permit it. Give them to `offersOfPart` and `bestOffer`.\n */\nexport function boardObservations(board: Board, options: KeepOptions): Observation[] {\n return [...keepObservations(board.reads.flatMap((each) => each.observations), options).kept];\n}\n\n/** This function gives the instant of the last read of each entry of a board, by name, for `planReads`. */\nexport function lastReads(board: Board): Record<string, string> {\n return Object.fromEntries(board.reads.map((each) => [each.name, each.at]));\n}\n\n/** This record is one entry of a watch: a read of one source that repeats. */\nexport interface WatchEntry {\n /** The name of the entry. Each entry of a watch has its own name. */\n readonly name: string;\n /** The source of the read. */\n readonly source: string;\n /** The time from one read of the entry to the next, a time of `@mark1russell7/quantity`. */\n readonly every: Quantity;\n}\n\n/** This schema accepts an entry of a watch. */\nexport const watchEntrySchema: z.ZodType<WatchEntry> = z.strictObject({\n name: textSchema,\n source: sourceSchema,\n every: quantitySchema(\"time\", { positive: true }),\n});\n\n/** These options give the rules of a schedule: the terms of each source, and the slack of the loop. */\nexport interface ScheduleOptions {\n /** The terms of the sources. */\n readonly terms: readonly SourceTerms[];\n /**\n * The longest time from the instant of a due read to the instant that its reading is on the board. It is the\n * time between two passes of the loop, plus the longest pass.\n */\n readonly slack: Quantity;\n}\n\n/** This record is the interval of an entry, in milliseconds, or the reason that the entry has no interval. */\nexport type ReadInterval = { readonly ok: true; readonly ms: number } | { readonly ok: false; readonly why: string };\n\n/**\n * This function gives the time from one read of an entry to the next, in milliseconds. A reading of a source with\n * the limit `L` stays on the board until `L` after the read. The next reading arrives `slack` after the next read\n * is due, at most. Thus the interval is the shorter of `every` and `L - slack`. Then the board has a current\n * reading of the entry at each instant after its first read.\n */\nexport function readInterval(entry: WatchEntry, options: ScheduleOptions): ReadInterval {\n const terms = termsBySource(options.terms).get(entry.source);\n const every = valueIn(entry.every, \"ms\");\n if (!(every > 0)) return { ok: false, why: `The time every of the entry ${entry.name} is not more than 0.` };\n if (terms === undefined) return { ok: false, why: `The terms of the source ${entry.source} of the entry ${entry.name} are not known.` };\n const { retention } = terms;\n if (retention.kind === \"no-store\") return { ok: false, why: `The terms of ${entry.source} permit no store, so a watch cannot keep the prices of the entry ${entry.name}. Read the source for each request.` };\n if (retention.kind === \"keep\") return { ok: true, ms: every };\n const room = valueIn(retention.age, \"ms\") - valueIn(options.slack, \"ms\");\n if (!(room > 0)) return { ok: false, why: `The slack ${timeText(options.slack)} is not less than the limit ${timeText(retention.age)} of the terms of ${entry.source}, so the board has gaps in the prices of the entry ${entry.name}.` };\n return { ok: true, ms: Math.min(every, room) };\n}\n\n/** This function gives the problems of a watch: an entry with no interval, and two entries with one name. */\nexport function watchProblems(entries: readonly WatchEntry[], options: ScheduleOptions): string[] {\n const problems: string[] = [];\n const names = new Set<string>();\n for (const entry of entries) {\n if (names.has(entry.name)) problems.push(`Two entries have the name ${entry.name}.`);\n names.add(entry.name);\n const interval = readInterval(entry, options);\n if (!interval.ok) problems.push(interval.why);\n }\n return problems;\n}\n\n/** This record is the plan of one pass of a watch: the due entries, and the instant of the next due read. */\nexport interface ReadPlan {\n /** The names of the due entries, in the order of the entries. An entry with no read is due. */\n readonly due: readonly string[];\n /**\n * The names of the due entries, the entry that is due for the longest time first. An entry with no read comes\n * first. Entries that became due at the same instant keep the order of the entries. Read the entries in this order.\n * Then each due entry comes before the next read of a later due entry.\n */\n readonly queue: readonly string[];\n /** The first instant after `now` that an entry is due, or null when no entry has an interval. */\n readonly next: string | null;\n}\n\n/**\n * This function plans one pass of a watch. An entry is due when it has no last read, or when its interval has\n * passed since its last read. An entry with no interval is not due at any time. `watchProblems` gives its reason.\n *\n * @param last - The instant of the last read of each entry, by name\n * @throws RangeError when `now` or a last read is not an instant.\n */\nexport function planReads(entries: readonly WatchEntry[], last: Readonly<Record<string, string>>, now: string, options: ScheduleOptions): ReadPlan {\n const at = Date.parse(now);\n if (Number.isNaN(at)) throw new RangeError(`The instant ${JSON.stringify(now)} is not an instant.`);\n const due: string[] = [];\n const since: { readonly name: string; readonly at: number }[] = [];\n let next = Number.POSITIVE_INFINITY;\n for (const entry of entries) {\n const interval = readInterval(entry, options);\n if (!interval.ok) continue;\n const before = Object.hasOwn(last, entry.name) ? last[entry.name] : undefined;\n const read = before === undefined ? Number.NaN : Date.parse(before);\n if (before !== undefined && Number.isNaN(read)) throw new RangeError(`The last read ${JSON.stringify(before)} of the entry ${entry.name} is not an instant.`);\n const isDue = Number.isNaN(read) || read + interval.ms <= at;\n if (isDue) {\n due.push(entry.name);\n since.push({ name: entry.name, at: Number.isNaN(read) ? Number.NEGATIVE_INFINITY : read + interval.ms });\n }\n // A planned read happens at `now`, so the next read of a due entry is one interval after `now`.\n next = Math.min(next, (isDue ? at : read) + interval.ms);\n }\n // The sort of an array is stable, so equal instants keep the order of the entries.\n const queue = since.sort((a, b) => a.at - b.at).map((each) => each.name);\n return { due, queue, next: Number.isFinite(next) ? new Date(next).toISOString() : null };\n}\n"],"mappings":";;;;;;;;;AAwBA,MAAa,kBAAwC,EAAE,mBAAmB,QAAQ;CAChF,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,MAAM,EAAE,CAAC;CAC1C,EAAE,aAAa;EAAE,MAAM,EAAE,QAAQ,SAAS;EAAG,KAAK,eAAe,QAAQ,EAAE,UAAU,KAAK,CAAC;CAAE,CAAC;CAC9F,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,UAAU,EAAE,CAAC;AAChD,CAAC;;;;;AAMD,MAAa,oBAA4C,EAAE,aAAa;CACtE,QAAQ;CACR,WAAW;CACX,iBAAiB,EAAE,QAAQ;CAC3B,YAAY,EAAE,QAAQ;CACtB,QAAQ;AACV,CAAC;;;;;AAMD,SAAgB,UAAU,OAAoB,SAAiD;CAC7F,MAAM,EAAE,cAAc;CACtB,IAAI,UAAU,SAAS,QAAQ,OAAO;CACtC,MAAM,KAAK,KAAK,MAAM,QAAQ,EAAE;CAChC,IAAI,OAAO,MAAM,EAAE,GAAG,MAAM,IAAI,WAAW,eAAe,KAAK,UAAU,QAAQ,EAAE,EAAE,oBAAoB;CACzG,IAAI,UAAU,SAAS,YAAY,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,YAAY;CACnE,OAAO,IAAI,KAAK,KAAK,KAAK,MAAM,QAAQ,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY;AAC7E;;;;;AAMA,SAAgB,OAAO,OAAoB,SAAkC,KAAa,QAAQ,OAAgB;CAChH,IAAI,SAAS,MAAM,iBAAiB,OAAO;CAC3C,IAAI,MAAM,UAAU,SAAS,YAAY,OAAO;CAChD,MAAM,QAAQ,UAAU,OAAO,OAAO;CACtC,IAAI,UAAU,MAAM,OAAO;CAC3B,MAAM,UA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O,SAAS;GAAG,CAAC;EACzG;EAEA,OAAO,KAAK,IAAI,OAAO,QAAQ,KAAK,QAAQ,SAAS,EAAE;CACzD;CAGA,OAAO;EAAE;EAAK,OADA,MAAM,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,KAAK,IACjD;EAAG,MAAM,OAAO,SAAS,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC,YAAY,IAAI;CAAK;AACzF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/terms.ts","../src/board.ts","../src/metered.ts"],"sourcesContent":["import { valueIn, type Quantity } from \"@mark1russell7/quantity\";\nimport { quantitySchema } from \"@mark1russell7/quantity/schema\";\nimport { z } from \"zod\";\nimport { sourceSchema, textSchema } from \"./records.ts\";\n\n/** The storage rule of a source, from its terms. */\nexport type Retention =\n | { readonly kind: \"keep\" }\n | { readonly kind: \"max-age\"; readonly age: Quantity }\n | { readonly kind: \"no-store\" };\n\n/** The rules of the terms of one source. */\nexport interface SourceTerms {\n readonly source: string;\n readonly retention: Retention;\n readonly deleteWhenEnded: boolean;\n readonly priceModel: boolean;\n readonly clause: string;\n}\n\n/**\n * This schema accepts the storage rule of a source, from its terms. With `keep`, the terms set no limit on the\n * time. With `max-age`, a store keeps a reading for `age` at most. With `no-store`, a reading serves one request.\n */\nexport const retentionSchema: z.ZodType<Retention> = z.discriminatedUnion(\"kind\", [\n z.strictObject({ kind: z.literal(\"keep\") }),\n z.strictObject({ kind: z.literal(\"max-age\"), age: quantitySchema(\"time\", { positive: true }) }),\n z.strictObject({ kind: z.literal(\"no-store\") }),\n]);\n\n/**\n * This schema accepts the rules of the terms of one source. `deleteWhenEnded` deletes the readings of an offer\n * when the offer ends. `priceModel` permits a trend or a forecast of prices. `clause` names the text of the terms.\n */\nexport const sourceTermsSchema: z.ZodType<SourceTerms> = z.strictObject({\n source: sourceSchema,\n retention: retentionSchema,\n deleteWhenEnded: z.boolean(),\n priceModel: z.boolean(),\n clause: textSchema,\n});\n\n/**\n * This function gives the last instant at which a store keeps a reading, or null when the terms set no\n * limit. For a source with `no-store`, the instant is the instant of the reading.\n */\nexport function keepUntil(terms: SourceTerms, reading: { readonly at: string }): string | null {\n const { retention } = terms;\n if (retention.kind === \"keep\") return null;\n const at = Date.parse(reading.at);\n if (Number.isNaN(at)) throw new RangeError(`The instant ${JSON.stringify(reading.at)} is not an instant.`);\n if (retention.kind === \"no-store\") return new Date(at).toISOString();\n return new Date(at + Math.floor(valueIn(retention.age, \"ms\"))).toISOString();\n}\n\n/**\n * This function tells if a store keeps a reading at the instant `now`. A store keeps no reading of a source with\n * `no-store`, and no reading of an ended offer when the terms delete them.\n */\nexport function isKept(terms: SourceTerms, reading: { readonly at: string }, now: string, ended = false): boolean {\n if (ended && terms.deleteWhenEnded) return false;\n if (terms.retention.kind === \"no-store\") return false;\n const until = keepUntil(terms, reading);\n if (until === null) return true;\n const instant = Date.parse(now);\n if (Number.isNaN(instant)) throw new RangeError(`The instant ${JSON.stringify(now)} is not an instant.`);\n return instant <= Date.parse(until);\n}\n\n/** This function tells if the terms permit a stored history of the readings of a source. */\nexport function permitsHistory(terms: SourceTerms): boolean {\n return terms.retention.kind === \"keep\" && !terms.deleteWhenEnded;\n}\n\n/** This function tells if the terms permit a trend of the prices of a source: a history and a model of prices. */\nexport function permitsTrend(terms: SourceTerms): boolean {\n return permitsHistory(terms) && terms.priceModel;\n}\n","import { valueIn, type Quantity } from \"@mark1russell7/quantity\";\nimport { quantitySchema } from \"@mark1russell7/quantity/schema\";\nimport { z } from \"zod\";\nimport { latestObservations, type Observation } from \"./offers.ts\";\nimport { instantSchema, offerSchema, priceReadingSchema, sourceSchema, textSchema } from \"./records.ts\";\nimport { isKept, keepUntil, type SourceTerms } from \"./terms.ts\";\n\n/*\n * This module calculates a board of current prices. A watch reads its sources on a schedule. The board keeps the\n * last read of each entry of the watch, within the terms of each source. Each function of this module is a\n * calculation with no effect. A host does the reads and writes the board.\n */\n\n/** The format name of a board record. */\nexport const BOARD_FORMAT = \"price-board/1\";\n\n/** This schema accepts an observation: an offer, and a reading of that offer. */\nexport const observationSchema: z.ZodType<Observation> = z\n .strictObject({ offer: offerSchema, reading: priceReadingSchema })\n .refine((each) => each.reading.offerId === each.offer.id, { message: \"The reading is not a reading of the offer.\" });\n\n/** This record is the last read of one entry of a watch: the name of the entry, the instant, and the observations. */\nexport interface BoardRead {\n readonly name: string;\n readonly at: string;\n readonly observations: readonly Observation[];\n}\n\n/** This record is a board: the instant of its last settle, and the last read of each entry, in the order of the names. */\nexport interface Board {\n readonly format: typeof BOARD_FORMAT;\n readonly at: string;\n readonly reads: readonly BoardRead[];\n}\n\n/** This schema accepts the read of an entry. The read has one observation of each offer at most. */\nexport const boardReadSchema: z.ZodType<BoardRead> = z\n .strictObject({ name: textSchema, at: instantSchema, observations: z.array(observationSchema) })\n .refine((read) => new Set(read.observations.map((each) => each.offer.id)).size === read.observations.length, {\n message: \"The read has two observations of one offer.\",\n });\n\n/** This schema accepts a board. The board has one read of each entry at most. */\nexport const boardSchema: z.ZodType<Board> = z\n .strictObject({ format: z.literal(BOARD_FORMAT), at: instantSchema, reads: z.array(boardReadSchema) })\n .refine((board) => new Set(board.reads.map((each) => each.name)).size === board.reads.length, {\n message: \"The board has two reads of one entry.\",\n });\n\n/** This record is an offer that the store does not keep, with the reason. */\nexport interface Dropped {\n readonly offerId: string;\n readonly why: string;\n}\n\n/** These options give the rules of a store: the terms of each source, the instant, and the offers that ended. */\nexport interface KeepOptions {\n /** The terms of the sources. A store keeps no reading of a source without terms. */\n readonly terms: readonly SourceTerms[];\n /** The instant of the decision. */\n readonly now: string;\n /** The ids of the offers that ended, as their sources tell. An offer with `endsAt` at or before `now` also ended. */\n readonly ended?: readonly string[] | undefined;\n}\n\n/** This record is the decision of a store: the observations that it keeps, and each offer that it drops. */\nexport interface Kept {\n /** The latest observation of each kept offer, in the order of the offer ids. */\n readonly kept: readonly Observation[];\n /** Each dropped offer, in the order of the offer ids. */\n readonly dropped: readonly Dropped[];\n}\n\n/** This function gives the terms of each source by its name. Two terms of one source are a problem of the input. */\nfunction termsBySource(terms: readonly SourceTerms[]): ReadonlyMap<string, SourceTerms> {\n const map = new Map<string, SourceTerms>();\n for (const each of terms) {\n if (map.has(each.source)) throw new RangeError(`The terms of the source ${each.source} are in the list two times.`);\n map.set(each.source, each);\n }\n return map;\n}\n\n/** This function gives the text of an amount of time, for example `6 h`. */\nconst timeText = (age: Quantity): string => `${age.value} ${age.unit}`;\n\n/**\n * This function decides which observations a store keeps. It takes the latest observation of each offer. It keeps\n * an observation while the terms of its source permit it, and while its offer has not ended. A current price is\n * a price that a buyer can pay, so the store drops an ended offer for each source.\n *\n * `settleBoard` applies this function to each read of a board.\n *\n * @throws RangeError when `now` is not an instant, or when the terms have two entries for one source.\n */\nexport function keepObservations(observations: readonly Observation[], options: KeepOptions): Kept {\n const terms = termsBySource(options.terms);\n const now = Date.parse(options.now);\n if (Number.isNaN(now)) throw new RangeError(`The instant ${JSON.stringify(options.now)} is not an instant.`);\n const ended = new Set(options.ended ?? []);\n const kept: Observation[] = [];\n const dropped: Dropped[] = [];\n for (const observation of latestObservations(observations)) {\n const { offer, reading } = observation;\n const rules = terms.get(offer.source);\n const endsAt = offer.endsAt === undefined ? Number.NaN : Date.parse(offer.endsAt);\n const over = ended.has(offer.id) || endsAt <= now;\n if (rules === undefined) dropped.push({ offerId: offer.id, why: `The terms of the source ${offer.source} are not known, so a store keeps no reading of it.` });\n else if (rules.retention.kind === \"no-store\") dropped.push({ offerId: offer.id, why: `The terms of ${offer.source} permit no store: a reading serves one request.` });\n else if (over) {\n const rule = rules.deleteWhenEnded ? `, and the terms of ${offer.source} delete its readings` : \"\";\n dropped.push({ offerId: offer.id, why: `The offer ended${rule}.` });\n } else if (!isKept(rules, reading, options.now)) {\n const age = rules.retention.kind === \"max-age\" ? timeText(rules.retention.age) : \"\";\n dropped.push({ offerId: offer.id, why: `The reading of ${reading.at} passed the limit of ${age} of the terms of ${offer.source} at ${keepUntil(rules, reading)}.` });\n } else kept.push(observation);\n }\n return { kept, dropped };\n}\n\n/** These options give the rules of a settle: the rules of a store, and the names of the entries of the watch. */\nexport interface SettleOptions extends KeepOptions {\n /** The names of the entries of the watch. The board drops the read of each other name. With no list, it keeps each read. */\n readonly names?: readonly string[] | undefined;\n}\n\n/** This record is an offer that the board drops, with the name of the entry of its read. */\nexport interface BoardDrop extends Dropped {\n readonly entry: string;\n}\n\n/** This record is the result of a settle: the new board, and each offer that it dropped. */\nexport interface Settled {\n readonly board: Board;\n readonly dropped: readonly BoardDrop[];\n}\n\nconst byText = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0);\n\n/**\n * This function settles a board at `now`. A new read replaces the last read of its entry, so an offer that the new\n * read does not give leaves the read. Then `keepObservations` applies the terms to each read. The board drops the\n * read of an entry that the watch does not have. Write the new board in place of the old board.\n *\n * @param read - A new read of an entry, or none to settle the board alone\n * @throws RangeError when `now` is not an instant, or when the terms have two entries for one source.\n */\nexport function settleBoard(board: Board, options: SettleOptions, read?: BoardRead): Settled {\n const names = options.names === undefined ? undefined : new Set(options.names);\n const reads = new Map(board.reads.map((each) => [each.name, each]));\n if (read !== undefined) reads.set(read.name, read);\n const settled: BoardRead[] = [];\n const dropped: BoardDrop[] = [];\n for (const name of [...reads.keys()].sort(byText)) {\n const each = reads.get(name);\n if (each === undefined) continue;\n if (names !== undefined && !names.has(name)) {\n for (const gone of latestObservations(each.observations)) dropped.push({ entry: name, offerId: gone.offer.id, why: `The watch has no entry ${name}.` });\n continue;\n }\n const decision = keepObservations(each.observations, options);\n settled.push({ name, at: each.at, observations: decision.kept });\n for (const drop of decision.dropped) dropped.push({ entry: name, ...drop });\n }\n return { board: { format: BOARD_FORMAT, at: options.now, reads: settled }, dropped };\n}\n\n/**\n * This function gives the current observations of a board at `now`. Each is the latest observation of an offer over\n * the reads, while the terms of its source permit it. Give them to `offersOfPart` and `bestOffer`.\n */\nexport function boardObservations(board: Board, options: KeepOptions): Observation[] {\n return [...keepObservations(board.reads.flatMap((each) => each.observations), options).kept];\n}\n\n/** This function gives the instant of the last read of each entry of a board, by name, for `planReads`. */\nexport function lastReads(board: Board): Record<string, string> {\n return Object.fromEntries(board.reads.map((each) => [each.name, each.at]));\n}\n\n/** This record is one entry of a watch: a read of one source that repeats. */\nexport interface WatchEntry {\n /** The name of the entry. Each entry of a watch has its own name. */\n readonly name: string;\n /** The source of the read. */\n readonly source: string;\n /** The time from one read of the entry to the next, a time of `@mark1russell7/quantity`. */\n readonly every: Quantity;\n}\n\n/** This schema accepts an entry of a watch. */\nexport const watchEntrySchema: z.ZodType<WatchEntry> = z.strictObject({\n name: textSchema,\n source: sourceSchema,\n every: quantitySchema(\"time\", { positive: true }),\n});\n\n/** These options give the rules of a schedule: the terms of each source, and the slack of the loop. */\nexport interface ScheduleOptions {\n /** The terms of the sources. */\n readonly terms: readonly SourceTerms[];\n /**\n * The longest time from the instant of a due read to the instant that its reading is on the board. It is the\n * time between two passes of the loop, plus the longest pass.\n */\n readonly slack: Quantity;\n}\n\n/** This record is the interval of an entry, in milliseconds, or the reason that the entry has no interval. */\nexport type ReadInterval = { readonly ok: true; readonly ms: number } | { readonly ok: false; readonly why: string };\n\n/**\n * This function gives the time from one read of an entry to the next, in milliseconds. A reading of a source with\n * the limit `L` stays on the board until `L` after the read. The next reading arrives `slack` after the next read\n * is due, at most. Thus the interval is the shorter of `every` and `L - slack`. Then the board has a current\n * reading of the entry at each instant after its first read.\n */\nexport function readInterval(entry: WatchEntry, options: ScheduleOptions): ReadInterval {\n const terms = termsBySource(options.terms).get(entry.source);\n const every = valueIn(entry.every, \"ms\");\n if (!(every > 0)) return { ok: false, why: `The time every of the entry ${entry.name} is not more than 0.` };\n if (terms === undefined) return { ok: false, why: `The terms of the source ${entry.source} of the entry ${entry.name} are not known.` };\n const { retention } = terms;\n if (retention.kind === \"no-store\") return { ok: false, why: `The terms of ${entry.source} permit no store, so a watch cannot keep the prices of the entry ${entry.name}. Read the source for each request.` };\n if (retention.kind === \"keep\") return { ok: true, ms: every };\n const room = valueIn(retention.age, \"ms\") - valueIn(options.slack, \"ms\");\n if (!(room > 0)) return { ok: false, why: `The slack ${timeText(options.slack)} is not less than the limit ${timeText(retention.age)} of the terms of ${entry.source}, so the board has gaps in the prices of the entry ${entry.name}.` };\n return { ok: true, ms: Math.min(every, room) };\n}\n\n/** This function gives the problems of a watch: an entry with no interval, and two entries with one name. */\nexport function watchProblems(entries: readonly WatchEntry[], options: ScheduleOptions): string[] {\n const problems: string[] = [];\n const names = new Set<string>();\n for (const entry of entries) {\n if (names.has(entry.name)) problems.push(`Two entries have the name ${entry.name}.`);\n names.add(entry.name);\n const interval = readInterval(entry, options);\n if (!interval.ok) problems.push(interval.why);\n }\n return problems;\n}\n\n/** This record is the plan of one pass of a watch: the due entries, and the instant of the next due read. */\nexport interface ReadPlan {\n /** The names of the due entries, in the order of the entries. An entry with no read is due. */\n readonly due: readonly string[];\n /**\n * The names of the due entries, the entry that is due for the longest time first. An entry with no read comes\n * first. Entries that became due at the same instant keep the order of the entries. Read the entries in this order.\n * Then each due entry comes before the next read of a later due entry.\n */\n readonly queue: readonly string[];\n /** The first instant after `now` that an entry is due, or null when no entry has an interval. */\n readonly next: string | null;\n}\n\n/**\n * This function plans one pass of a watch. An entry is due when it has no last read, or when its interval has\n * passed since its last read. An entry with no interval is not due at any time. `watchProblems` gives its reason.\n *\n * @param last - The instant of the last read of each entry, by name\n * @throws RangeError when `now` or a last read is not an instant.\n */\nexport function planReads(entries: readonly WatchEntry[], last: Readonly<Record<string, string>>, now: string, options: ScheduleOptions): ReadPlan {\n const at = Date.parse(now);\n if (Number.isNaN(at)) throw new RangeError(`The instant ${JSON.stringify(now)} is not an instant.`);\n const due: string[] = [];\n const since: { readonly name: string; readonly at: number }[] = [];\n let next = Number.POSITIVE_INFINITY;\n for (const entry of entries) {\n const interval = readInterval(entry, options);\n if (!interval.ok) continue;\n const before = Object.hasOwn(last, entry.name) ? last[entry.name] : undefined;\n const read = before === undefined ? Number.NaN : Date.parse(before);\n if (before !== undefined && Number.isNaN(read)) throw new RangeError(`The last read ${JSON.stringify(before)} of the entry ${entry.name} is not an instant.`);\n const isDue = Number.isNaN(read) || read + interval.ms <= at;\n if (isDue) {\n due.push(entry.name);\n since.push({ name: entry.name, at: Number.isNaN(read) ? Number.NEGATIVE_INFINITY : read + interval.ms });\n }\n // A planned read happens at `now`, so the next read of a due entry is one interval after `now`.\n next = Math.min(next, (isDue ? at : read) + interval.ms);\n }\n // The sort of an array is stable, so equal instants keep the order of the entries.\n const queue = since.sort((a, b) => a.at - b.at).map((each) => each.name);\n return { due, queue, next: Number.isFinite(next) ? new Date(next).toISOString() : null };\n}\n","import {\n canonicalUnit,\n convertExact,\n convertible,\n parseUnit,\n quantity,\n rationals,\n UnitError,\n type Quantity,\n type Rational,\n} from \"@mark1russell7/quantity\";\nimport { quantitySchema } from \"@mark1russell7/quantity/schema\";\nimport { z } from \"zod\";\nimport { instantSchema, moneySchema, offerId, sourceSchema, specSchema, textSchema, type Spec } from \"./records.ts\";\n\n/*\n * This module has the metered prices of a market. A provider meters an amount, for example the hours of a machine,\n * the stored data of each month, the data that goes out, or the requests. A metered price is a price for each unit\n * of that amount, in tiers, with a free amount for each billing period and a term.\n */\n\n/**\n * The kinds of a metered amount: a time (the hours of a machine), data times time (stored data), data (a transfer)\n * and a count (requests).\n */\nexport const METERED_KINDS = [\"time\", \"data-time\", \"data\", \"count\"] as const;\n/** The kind of a metered amount. */\nexport type MeteredKind = (typeof METERED_KINDS)[number];\n\n/**\n * The scopes of a free amount. With `account`, all the usage of the account in all regions shares one free amount.\n * With `region`, each region has its own free amount. With `resource`, each resource has its own free amount.\n */\nexport const FREE_SCOPES = [\"account\", \"region\", \"resource\"] as const;\n/** The scope of a free amount: the usage that shares it. */\nexport type FreeScope = (typeof FREE_SCOPES)[number];\n\n/** The location of a metered offer: the provider, and its region and zone, as the provider names them. */\nexport interface Location {\n readonly provider: string;\n readonly region: string;\n readonly zone?: string | undefined;\n}\n\n/**\n * The term of a metered price. A `spot` price is also a preemptible price: the provider can end the use at any time,\n * after the `notice`. A `committed` price binds the buyer for its `length`.\n */\nexport type PriceTerm =\n | { readonly kind: \"on-demand\" }\n | { readonly kind: \"spot\"; readonly notice?: Quantity | undefined }\n | { readonly kind: \"committed\"; readonly length: Quantity };\n\n/** A metered offer: one resource of a provider in one location, on one term, with the identifiers that the source gives. */\nexport interface MeteredOffer {\n readonly id: string;\n readonly source: string;\n readonly sourceId: string;\n readonly productId?: string | undefined;\n readonly title: string;\n readonly url?: string | undefined;\n readonly location: Location;\n readonly term: PriceTerm;\n readonly specs: readonly Spec[];\n}\n\n/** 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. */\nexport interface Tier {\n readonly from: Quantity;\n readonly unitPrice: Quantity;\n}\n\n/** A free amount of a meter for each period, and the scope that shares it. */\nexport interface FreeAmount {\n readonly amount: Quantity;\n readonly scope: FreeScope;\n}\n\n/** A meter of a metered reading: the tiers of the price of one metered amount, and its free amount. */\nexport interface Meter {\n readonly name: string;\n readonly tiers: readonly Tier[];\n readonly free?: FreeAmount | undefined;\n}\n\n/** A metered reading: the metered prices of one offer at one instant. */\nexport interface MeteredReading {\n readonly offerId: string;\n readonly at: string;\n readonly period: Quantity;\n readonly meters: readonly Meter[];\n readonly upfront?: Quantity | undefined;\n}\n\n/** One metered offer of a source, and its metered reading at one instant. */\nexport interface MeteredObservation {\n readonly offer: MeteredOffer;\n readonly reading: MeteredReading;\n}\n\n/** The usage of each meter in one period, by the name of the meter. */\nexport type MeteredUsage = Readonly<Record<string, Quantity>>;\n\n/** These options change the cost of a metered offer. */\nexport interface MeteredCostOptions {\n /**\n * The part of the free amount of each meter that other usage in its scope used in the same period. The keys are\n * the names of the meters. The default is none.\n */\n readonly freeUsed?: MeteredUsage | undefined;\n}\n\n/** The cost of the usage of one meter in one period. */\nexport interface MeterCost {\n readonly name: string;\n readonly cost: Quantity;\n}\n\n/** The cost of a metered offer for one period. */\nexport interface MeteredCost {\n /** The cost of each meter, in the order of the meters of the reading. */\n readonly meters: readonly MeterCost[];\n /** The part of the upfront money of a committed term for one period, or zero. */\n readonly upfront: Quantity;\n /** The sum of the cost of each meter and the part of the upfront money. */\n readonly total: Quantity;\n}\n\n/** The parts of the unit of a metered price: its unit of money, and the kind of its metered amount. */\ninterface PriceParts {\n readonly money: string;\n readonly kind: MeteredKind;\n}\n\n/** This function gives the kind of a metered amount from the exponents of its data and its time, or undefined. */\nfunction kindOfExponents(data: number, time: number): MeteredKind | undefined {\n if (data === 0 && time === 0) return \"count\";\n if (data === 0 && time === 1) return \"time\";\n if (data === 1 && time === 0) return \"data\";\n if (data === 1 && time === 1) return \"data-time\";\n return undefined;\n}\n\n/** This function reads the unit of a metered price. It gives the parts of the unit, or the problem as a text. */\nfunction readPriceUnit(unit: string): PriceParts | string {\n const refused = `The unit ${unit} is not a price for each unit of a metered amount, for example USD/h.`;\n let parsed: ReturnType<typeof parseUnit>;\n try {\n parsed = parseUnit(unit);\n } catch (error) {\n if (error instanceof UnitError) return refused;\n throw error;\n }\n const above = parsed.components.filter((component) => component.exponent > 0);\n const [money] = above;\n const atom = money?.atom;\n const isMoney = atom !== undefined && Object.keys(atom.vector).length === 1 && atom.vector.money === 1;\n const below = parsed.components.some((component) => component.exponent < 0);\n if (above.length !== 1 || money?.exponent !== 1 || money.annotation !== undefined || !isMoney || !below) return refused;\n const { money: units = 0, data = 0, time = 0, ...others } = parsed.vector;\n const kind = Object.values(others).every((exponent) => exponent === 0) && units === 1 ? kindOfExponents(-data, -time) : undefined;\n return kind === undefined ? refused : { money: atom.symbol, kind };\n}\n\n/** This function gives the unit of a price for each unit of an amount, for example `USD/(GiB·mo)` for `GiB·mo`. */\nfunction priceUnitFor(money: string, amountUnit: string): string | undefined {\n try {\n return canonicalUnit(`${money}/${amountUnit}`);\n } catch (error) {\n if (error instanceof UnitError) return undefined;\n throw error;\n }\n}\n\n/** This function tells if an amount in one unit converts to another unit. A unit that the quantity package does not know does not convert. */\nfunction converts(from: string, to: string): boolean {\n try {\n return convertible(from, to);\n } catch (error) {\n if (error instanceof UnitError) return false;\n throw error;\n }\n}\n\n/** This function gives the start of each tier in one unit, or undefined when a start does not convert to it. */\nfunction startsOf(tiers: readonly Tier[], unit: string): Rational[] | undefined {\n try {\n return tiers.map((tier) => convertExact(rationals.fromNumber(tier.from.value), tier.from.unit, unit));\n } catch (error) {\n if (error instanceof UnitError || error instanceof RangeError) return undefined;\n throw error;\n }\n}\n\n/** This function tells if a unit of an amount measures the metered amount of a unit of price. */\nfunction measures(amountUnit: string, priceUnit: string, money: string): boolean {\n const unit = priceUnitFor(money, amountUnit);\n return unit !== undefined && converts(unit, priceUnit);\n}\n\n/**\n * This function gives the kind of the metered amount of the unit of a metered price, for example `time` for `USD/h`\n * and `data-time` for `USD/(GiB·mo)`.\n *\n * @throws RangeError when the unit is not a price for each unit of a metered amount.\n */\nexport function meteredKindOf(unit: string): MeteredKind {\n const parts = readPriceUnit(unit);\n if (typeof parts === \"string\") throw new RangeError(parts);\n return parts.kind;\n}\n\n/**\n * This schema accepts the location of a metered offer. The name of the provider has small letters, digits and\n * hyphens, as the name of a source. The region and the zone are the ids of the provider.\n */\nexport const locationSchema: z.ZodType<Location> = z.strictObject({\n provider: sourceSchema,\n region: textSchema,\n zone: textSchema.optional(),\n});\n\n/**\n * This schema accepts the term of a metered price. A `spot` term can have the notice before the provider ends the\n * use. A `committed` term has its length.\n */\nexport const priceTermSchema: z.ZodType<PriceTerm> = z.discriminatedUnion(\"kind\", [\n z.strictObject({ kind: z.literal(\"on-demand\") }),\n z.strictObject({ kind: z.literal(\"spot\"), notice: quantitySchema(\"time\", { nonnegative: true }).optional() }),\n z.strictObject({ kind: z.literal(\"committed\"), length: quantitySchema(\"time\", { positive: true }) }),\n]);\n\n/**\n * This schema accepts a metered offer: one resource of a provider in one location, on one term. The id is the\n * source and the source id, with a colon between them.\n */\nexport const meteredOfferSchema: z.ZodType<MeteredOffer> = z\n .strictObject({\n id: textSchema,\n source: sourceSchema,\n sourceId: textSchema,\n productId: textSchema.optional(),\n title: textSchema,\n url: z.url({ protocol: /^https$/ }).optional(),\n location: locationSchema,\n term: priceTermSchema,\n specs: z.array(specSchema),\n })\n .refine((offer) => offer.id === offerId(offer.source, offer.sourceId), {\n message: \"The id of an offer is its source and its source id, with a colon between them.\",\n path: [\"id\"],\n });\n\n/**\n * This schema accepts a metered price of zero or more: an amount of money for each unit of a metered amount, for\n * example `{ \"value\": 0.0116, \"unit\": \"USD/h\" }`.\n */\nexport const meteredPriceSchema: z.ZodType<Quantity, Quantity> = quantitySchema(undefined, { nonnegative: true }).superRefine(\n (price, context) => {\n const parts = readPriceUnit(price.unit);\n if (typeof parts === \"string\") context.addIssue({ code: \"custom\", message: parts });\n },\n);\n\n/** 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. */\nexport const tierSchema: z.ZodType<Tier> = z\n .strictObject({ from: quantitySchema(undefined, { nonnegative: true }), unitPrice: meteredPriceSchema })\n .superRefine((tier, context) => {\n const parts = readPriceUnit(tier.unitPrice.unit);\n if (typeof parts === \"string\" || measures(tier.from.unit, tier.unitPrice.unit, parts.money)) return;\n context.addIssue({\n code: \"custom\",\n message: `The start ${tier.from.unit} does not measure the metered amount of the price ${tier.unitPrice.unit}.`,\n path: [\"from\"],\n });\n });\n\n/** This schema accepts a free amount of more than zero for each period, and its scope. */\nexport const freeAmountSchema: z.ZodType<FreeAmount> = z.strictObject({\n amount: quantitySchema(undefined, { positive: true }),\n scope: z.enum(FREE_SCOPES),\n});\n\n/**\n * This schema accepts a meter. The first tier starts at zero, and the starts increase. The prices of the tiers and\n * the free amount measure one metered amount.\n */\nexport const meterSchema: z.ZodType<Meter> = z\n .strictObject({ name: textSchema, tiers: z.array(tierSchema).min(1), free: freeAmountSchema.optional() })\n .superRefine((meter, context) => {\n const [first] = meter.tiers;\n if (first === undefined) return;\n const parts = readPriceUnit(first.unitPrice.unit);\n if (typeof parts === \"string\") return;\n let units = true;\n for (const [index, tier] of meter.tiers.entries()) {\n if (converts(tier.unitPrice.unit, first.unitPrice.unit) && measures(tier.from.unit, first.unitPrice.unit, parts.money)) continue;\n units = false;\n context.addIssue({\n code: \"custom\",\n message: `The tier ${index} does not measure the metered amount of the price ${first.unitPrice.unit}.`,\n path: [\"tiers\", index],\n });\n }\n if (meter.free !== undefined && !measures(meter.free.amount.unit, first.unitPrice.unit, parts.money)) {\n context.addIssue({\n code: \"custom\",\n message: `The free amount ${meter.free.amount.unit} does not measure the metered amount of the price ${first.unitPrice.unit}.`,\n path: [\"free\", \"amount\"],\n });\n }\n if (!units) return;\n const starts = startsOf(meter.tiers, first.from.unit);\n if (starts === undefined) return;\n if (rationals.sign(starts[0] ?? rationals.ZERO) !== 0) {\n context.addIssue({ code: \"custom\", message: \"The first tier does not start at zero.\", path: [\"tiers\", 0, \"from\"] });\n }\n for (let index = 1; index < starts.length; index += 1) {\n if (rationals.cmp(starts[index] ?? rationals.ZERO, starts[index - 1] ?? rationals.ZERO) > 0) continue;\n context.addIssue({\n code: \"custom\",\n message: `The tier ${index} does not start after the tier ${index - 1}.`,\n path: [\"tiers\", index, \"from\"],\n });\n }\n });\n\n/**\n * This schema accepts a metered reading: the metered prices of one offer at one instant. The tiers and the free\n * amounts count the usage of one `period`. Each meter has its own name.\n */\nexport const meteredReadingSchema: z.ZodType<MeteredReading> = z\n .strictObject({\n offerId: textSchema,\n at: instantSchema,\n period: quantitySchema(\"time\", { positive: true }),\n meters: z.array(meterSchema).min(1),\n upfront: moneySchema.optional(),\n })\n .refine((reading) => new Set(reading.meters.map((meter) => meter.name)).size === reading.meters.length, {\n message: \"The reading has two meters with one name.\",\n path: [\"meters\"],\n });\n\n/** This schema accepts a metered observation: an offer, and a reading of that offer. Only a committed term has upfront money. */\nexport const meteredObservationSchema: z.ZodType<MeteredObservation> = z\n .strictObject({ offer: meteredOfferSchema, reading: meteredReadingSchema })\n .superRefine((each, context) => {\n if (each.reading.offerId !== each.offer.id) {\n context.addIssue({ code: \"custom\", message: \"The reading is not a reading of the offer.\", path: [\"reading\", \"offerId\"] });\n }\n if (each.reading.upfront !== undefined && each.offer.term.kind !== \"committed\") {\n context.addIssue({\n code: \"custom\",\n message: `The term ${each.offer.term.kind} has no upfront money.`,\n path: [\"reading\", \"upfront\"],\n });\n }\n });\n\n/** This function gives the value of an amount in a unit, as an exact rational. */\nfunction exactIn(amount: Quantity, unit: string): Rational {\n return convertExact(rationals.fromNumber(amount.value), amount.unit, unit);\n}\n\n/** This function gives the larger of two rationals. */\nfunction larger(a: Rational, b: Rational): Rational {\n return rationals.cmp(a, b) >= 0 ? a : b;\n}\n\n/** This function gives the smaller of two rationals. */\nfunction smaller(a: Rational, b: Rational): Rational {\n return rationals.cmp(a, b) <= 0 ? a : b;\n}\n\n/** This function examines an amount of usage of a meter, and gives its value in its own unit. */\nfunction usageValue(meter: Meter, amount: Quantity, priceUnit: string, money: string, what: string): Rational {\n if (!Number.isFinite(amount.value) || amount.value < 0) {\n throw new RangeError(`The ${what} of the meter ${meter.name} is ${amount.value}, not an amount of zero or more.`);\n }\n if (!measures(amount.unit, priceUnit, money)) {\n throw new RangeError(`The ${what} of the meter ${meter.name} is in ${amount.unit}, which does not measure the price ${priceUnit}.`);\n }\n return rationals.fromNumber(amount.value);\n}\n\n/**\n * This function gives the exact cost of the usage of one meter, in the unit of money of its first tier. The free\n * amount comes off the usage first. The tiers then count the rest of the usage from zero.\n */\nfunction costOfMeter(meter: Meter, used: Quantity | undefined, freeUsed: Quantity | undefined): { money: string; cost: Rational } {\n const [first] = meter.tiers;\n if (first === undefined) throw new RangeError(`The meter ${meter.name} has no tier.`);\n const parts = readPriceUnit(first.unitPrice.unit);\n if (typeof parts === \"string\") throw new RangeError(parts);\n const { money } = parts;\n if (used === undefined) return { money, cost: rationals.ZERO };\n const amount = usageValue(meter, used, first.unitPrice.unit, money, \"usage\");\n const unit = used.unit;\n const perUnit = priceUnitFor(money, unit);\n if (perUnit === undefined) throw new RangeError(`The usage of the meter ${meter.name} is in ${unit}, which has no price unit.`);\n let free: Rational = rationals.ZERO;\n if (meter.free !== undefined) free = exactIn(meter.free.amount, unit);\n if (freeUsed !== undefined) {\n usageValue(meter, freeUsed, first.unitPrice.unit, money, \"used free amount\");\n free = larger(rationals.ZERO, rationals.sub(free, exactIn(freeUsed, unit)));\n }\n const billed = larger(rationals.ZERO, rationals.sub(amount, free));\n let cost: Rational = rationals.ZERO;\n for (const [index, tier] of meter.tiers.entries()) {\n const start = exactIn(tier.from, unit);\n const next = meter.tiers[index + 1];\n const end = next === undefined ? billed : smaller(billed, exactIn(next.from, unit));\n if (rationals.cmp(end, start) <= 0) continue;\n cost = rationals.add(cost, rationals.mul(rationals.sub(end, start), exactIn(tier.unitPrice, perUnit)));\n }\n return { money, cost };\n}\n\n/**\n * This function gives the cost of a metered offer for one period, from the usage of each meter in that period. A\n * meter with no usage costs zero. The free amount of a meter comes off its usage first, less `freeUsed`. The tiers\n * then count the rest of the usage from zero. A committed term adds its upfront money times the period over the length.\n *\n * The arithmetic is exact, and the function does not round the cost to the cent. Each value is the nearest number to\n * the exact cost. The function converts the units with the exact factors of `@mark1russell7/quantity`.\n *\n * @throws RangeError when the usage names a meter that the reading does not have. It also throws when an amount\n * of usage is negative, or does not measure the metered amount of its meter.\n */\nexport function meteredCost(observation: MeteredObservation, usage: MeteredUsage, options: MeteredCostOptions = {}): MeteredCost {\n const { offer, reading } = observation;\n const { freeUsed = {} } = options;\n const names = new Set(reading.meters.map((meter) => meter.name));\n for (const name of [...Object.keys(usage), ...Object.keys(freeUsed)]) {\n if (!names.has(name)) throw new RangeError(`The reading of ${reading.offerId} has no meter ${name}.`);\n }\n const at = (record: MeteredUsage, name: string): Quantity | undefined => (Object.hasOwn(record, name) ? record[name] : undefined);\n const costs = reading.meters.map((meter) => ({ name: meter.name, ...costOfMeter(meter, at(usage, meter.name), at(freeUsed, meter.name)) }));\n const unit = costs[0]?.money;\n if (unit === undefined) throw new RangeError(`The reading of ${reading.offerId} has no meter.`);\n let total: Rational = rationals.ZERO;\n for (const each of costs) total = rationals.add(total, convertExact(each.cost, each.money, unit));\n const meters = costs.map((each): MeterCost => ({ name: each.name, cost: quantity(rationals.toNumber(each.cost), each.money) }));\n let upfront: Rational = rationals.ZERO;\n if (offer.term.kind === \"committed\" && reading.upfront !== undefined) {\n const { length } = offer.term;\n const share = rationals.div(exactIn(reading.period, length.unit), rationals.fromNumber(length.value));\n upfront = rationals.mul(exactIn(reading.upfront, unit), share);\n }\n total = rationals.add(total, upfront);\n return { meters, upfront: quantity(rationals.toNumber(upfront), unit), total: quantity(rationals.toNumber(total), unit) };\n}\n"],"mappings":";;;;;;;;;AAwBA,MAAa,kBAAwC,EAAE,mBAAmB,QAAQ;CAChF,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,MAAM,EAAE,CAAC;CAC1C,EAAE,aAAa;EAAE,MAAM,EAAE,QAAQ,SAAS;EAAG,KAAK,eAAe,QAAQ,EAAE,UAAU,KAAK,CAAC;CAAE,CAAC;CAC9F,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,UAAU,EAAE,CAAC;AAChD,CAAC;;;;;AAMD,MAAa,oBAA4C,EAAE,aAAa;CACtE,QAAQ;CACR,WAAW;CACX,iBAAiB,EAAE,QAAQ;CAC3B,YAAY,EAAE,QAAQ;CACtB,QAAQ;AACV,CAAC;;;;;AAMD,SAAgB,UAAU,OAAoB,SAAiD;CAC7F,MAAM,EAAE,cAAc;CACtB,IAAI,UAAU,SAAS,QAAQ,OAAO;CACtC,MAAM,KAAK,KAAK,MAAM,QAAQ,EAAE;CAChC,IAAI,OAAO,MAAM,EAAE,GAAG,MAAM,IAAI,WAAW,eAAe,KAAK,UAAU,QAAQ,EAAE,EAAE,oBAAoB;CACzG,IAAI,UAAU,SAAS,YAAY,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,YAAY;CACnE,OAAO,IAAI,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U,SAAS,OAAO,GAAG,IAAI;EAAG,OAAO,SAAS,UAAU,SAAS,KAAK,GAAG,IAAI;CAAE;AAC1H"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/market",
|
|
4
|
-
"version": "0.1.
|
|
5
|
-
"description": "The records of a market: a product, an offer of a seller and a price reading, with their checks, the GTIN check, match keys, the cost of an order, the storage rules of a source, the best offer of a part, a board of current prices within the terms of each source,
|
|
4
|
+
"version": "0.1.5",
|
|
5
|
+
"description": "The records of a market: a product, an offer of a seller and a price reading, with their checks, the GTIN check, match keys, the cost of an order, the storage rules of a source, the best offer of a part, a board of current prices within the terms of each source, a buy plan: the Pareto front of the baskets of a need, and metered prices of cloud resources with tiers, free amounts, terms and their cost.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
"catalog",
|
|
23
23
|
"parts",
|
|
24
24
|
"buy-plan",
|
|
25
|
-
"pareto"
|
|
25
|
+
"pareto",
|
|
26
|
+
"metered-prices",
|
|
27
|
+
"cloud-pricing"
|
|
26
28
|
],
|
|
27
29
|
"type": "module",
|
|
28
30
|
"main": "./build/index.js",
|