@mark1russell7/market 0.1.2 → 0.1.4
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 +39 -2
- package/build/index.d.ts +8 -211
- package/build/index.d.ts.map +1 -1
- package/build/index.js +11 -342
- package/build/index.js.map +1 -1
- package/build/offers-CVUAcRHs.d.ts +214 -0
- package/build/offers-CVUAcRHs.d.ts.map +1 -0
- package/build/plan.d.ts +151 -0
- package/build/plan.d.ts.map +1 -0
- package/build/plan.js +440 -0
- package/build/plan.js.map +1 -0
- package/build/records-hK1UCmpm.js +346 -0
- package/build/records-hK1UCmpm.js.map +1 -0
- package/package.json +14 -3
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { Quantity } from "@mark1russell7/quantity";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/** A part number of a maker: the brand, and the number that the maker gives to the part. */
|
|
4
|
+
interface PartNumber {
|
|
5
|
+
readonly brand: string;
|
|
6
|
+
readonly partNumber: string;
|
|
7
|
+
}
|
|
8
|
+
/** The identifiers of a product or of an offer. */
|
|
9
|
+
interface Identifiers {
|
|
10
|
+
readonly gtins: readonly string[];
|
|
11
|
+
readonly partNumbers: readonly PartNumber[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* This function folds a brand or a part number for a comparison. The result has only capital letters A to Z
|
|
15
|
+
* and digits. Thus `MZ-V8V1T0B/AM` and `mzv8v1t0bam` fold to one text.
|
|
16
|
+
*/
|
|
17
|
+
declare function foldCode(text: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* This function gives the match keys of a record, sorted and with no copy. A key is `gtin:` with the GTIN-14,
|
|
20
|
+
* or `part:` with the folded brand and part number. Two records with a key in common name one product.
|
|
21
|
+
* The function ignores a GTIN that is not valid, and a part number whose brand or number folds to no text.
|
|
22
|
+
*/
|
|
23
|
+
declare function matchKeys(identifiers: Identifiers): string[];
|
|
24
|
+
/**
|
|
25
|
+
* The conditions of an offer. A source maps its own condition to one of them, and it keeps its own text in
|
|
26
|
+
* the field `grade` of the offer.
|
|
27
|
+
*/
|
|
28
|
+
declare const CONDITIONS: readonly ["new", "open-box", "refurbished", "used", "for-parts", "unknown"];
|
|
29
|
+
/** The condition of an offer. */
|
|
30
|
+
type Condition = (typeof CONDITIONS)[number];
|
|
31
|
+
/** The states of the stock of an offer at the time of a reading. */
|
|
32
|
+
declare const AVAILABILITIES: readonly ["in-stock", "low-stock", "out-of-stock", "preorder", "unknown"];
|
|
33
|
+
/** The state of the stock of an offer. */
|
|
34
|
+
type Availability = (typeof AVAILABILITIES)[number];
|
|
35
|
+
/** The buying formats of an offer. In an auction, the price of a reading is the current bid. */
|
|
36
|
+
declare const FORMATS: readonly ["fixed-price", "auction"];
|
|
37
|
+
/** The buying format of an offer. */
|
|
38
|
+
type Format = (typeof FORMATS)[number];
|
|
39
|
+
/** One specification of a product as text. */
|
|
40
|
+
interface Spec {
|
|
41
|
+
readonly name: string;
|
|
42
|
+
readonly value: string;
|
|
43
|
+
}
|
|
44
|
+
/** The feedback of a seller: the percent of good feedback, and the count of the feedback. */
|
|
45
|
+
interface Rating {
|
|
46
|
+
readonly percent: number;
|
|
47
|
+
readonly count: number;
|
|
48
|
+
}
|
|
49
|
+
/** A seller of an offer. A source gives some of these fields, or none. */
|
|
50
|
+
interface Seller {
|
|
51
|
+
readonly id?: string | undefined;
|
|
52
|
+
readonly name?: string | undefined;
|
|
53
|
+
readonly rating?: Rating | undefined;
|
|
54
|
+
}
|
|
55
|
+
/** A product of the catalog: one thing that a person can buy, with its identifiers and its specifications. */
|
|
56
|
+
interface Product {
|
|
57
|
+
readonly id: string;
|
|
58
|
+
readonly title: string;
|
|
59
|
+
readonly brand?: string | undefined;
|
|
60
|
+
readonly category?: readonly string[] | undefined;
|
|
61
|
+
readonly gtins: readonly string[];
|
|
62
|
+
readonly partNumbers: readonly PartNumber[];
|
|
63
|
+
readonly specs: readonly Spec[];
|
|
64
|
+
}
|
|
65
|
+
/** An offer of a seller: one product at one seller, with the identifiers that the source gives. */
|
|
66
|
+
interface Offer {
|
|
67
|
+
readonly id: string;
|
|
68
|
+
readonly source: string;
|
|
69
|
+
readonly sourceId: string;
|
|
70
|
+
readonly productId?: string | undefined;
|
|
71
|
+
readonly title: string;
|
|
72
|
+
readonly url?: string | undefined;
|
|
73
|
+
readonly seller: Seller;
|
|
74
|
+
readonly condition: Condition;
|
|
75
|
+
readonly grade?: string | undefined;
|
|
76
|
+
readonly format: Format;
|
|
77
|
+
readonly endsAt?: string | undefined;
|
|
78
|
+
readonly gtins: readonly string[];
|
|
79
|
+
readonly partNumbers: readonly PartNumber[];
|
|
80
|
+
readonly specs: readonly Spec[];
|
|
81
|
+
}
|
|
82
|
+
/** The shipping of a reading. A calculated cost depends on the address of the buyer. */
|
|
83
|
+
type Shipping = {
|
|
84
|
+
readonly kind: "free";
|
|
85
|
+
} | {
|
|
86
|
+
readonly kind: "fixed";
|
|
87
|
+
readonly cost: Quantity;
|
|
88
|
+
} | {
|
|
89
|
+
readonly kind: "calculated";
|
|
90
|
+
} | {
|
|
91
|
+
readonly kind: "unknown";
|
|
92
|
+
};
|
|
93
|
+
/** A price break of a reading: the unit price for an order of `quantity` units or more. */
|
|
94
|
+
interface PriceBreak {
|
|
95
|
+
readonly quantity: number;
|
|
96
|
+
readonly unitPrice: Quantity;
|
|
97
|
+
}
|
|
98
|
+
/** A price reading: the state of one offer at one instant. */
|
|
99
|
+
interface PriceReading {
|
|
100
|
+
readonly offerId: string;
|
|
101
|
+
readonly at: string;
|
|
102
|
+
readonly price: Quantity;
|
|
103
|
+
readonly listPrice?: Quantity | undefined;
|
|
104
|
+
readonly shipping: Shipping;
|
|
105
|
+
readonly availability: Availability;
|
|
106
|
+
readonly available?: number | undefined;
|
|
107
|
+
readonly minimumQuantity?: number | undefined;
|
|
108
|
+
readonly priceBreaks?: readonly PriceBreak[] | undefined;
|
|
109
|
+
}
|
|
110
|
+
/** This schema accepts a text with a character that is not a space, and with no space at an end. */
|
|
111
|
+
declare const textSchema: z.ZodType<string>;
|
|
112
|
+
/** This schema accepts the name of a source: small letters, digits and hyphens, with a letter first. */
|
|
113
|
+
declare const sourceSchema: z.ZodType<string>;
|
|
114
|
+
/** This schema accepts a GTIN in its GTIN-14 form, with a correct check digit. `parseGtin` gives this form. */
|
|
115
|
+
declare const gtinSchema: z.ZodType<string>;
|
|
116
|
+
/** This schema accepts an amount of money of zero or more, for example `{ "value": 129.99, "unit": "USD" }`. */
|
|
117
|
+
declare const moneySchema: z.ZodType<Quantity, Quantity>;
|
|
118
|
+
/** This schema accepts an instant in UTC in the ISO 8601 form, for example `2026-11-12T18:00:00Z`. */
|
|
119
|
+
declare const instantSchema: z.ZodType<string>;
|
|
120
|
+
/** This schema accepts a part number of a maker. */
|
|
121
|
+
declare const partNumberSchema: z.ZodType<PartNumber>;
|
|
122
|
+
/** This schema accepts one specification as text, for example `{ "name": "Capacity", "value": "1 TB" }`. */
|
|
123
|
+
declare const specSchema: z.ZodType<Spec>;
|
|
124
|
+
/** This schema accepts a seller. A rating is the percent of good feedback and the count of the feedback. */
|
|
125
|
+
declare const sellerSchema: z.ZodType<Seller>;
|
|
126
|
+
/** This schema accepts a product: one thing that a person can buy, with its identifiers and its specifications. */
|
|
127
|
+
declare const productSchema: z.ZodType<Product>;
|
|
128
|
+
/** This function gives the id of an offer: the name of its source, a colon, and the id at the source. */
|
|
129
|
+
declare function offerId(source: string, sourceId: string): string;
|
|
130
|
+
/** This function gives the name of the source of an offer id: the text before the first colon. */
|
|
131
|
+
declare function sourceOfOffer(id: string): string;
|
|
132
|
+
/**
|
|
133
|
+
* This schema accepts an offer: one product at one seller. The offer has the identifiers that the source gives.
|
|
134
|
+
* `productId` names the product of the catalog after a match.
|
|
135
|
+
*/
|
|
136
|
+
declare const offerSchema: z.ZodType<Offer>;
|
|
137
|
+
/** This schema accepts the shipping of a reading. A calculated cost depends on the address of the buyer. */
|
|
138
|
+
declare const shippingSchema: z.ZodType<Shipping>;
|
|
139
|
+
/** This schema accepts a price break: the unit price for an order of `quantity` units or more. */
|
|
140
|
+
declare const priceBreakSchema: z.ZodType<PriceBreak>;
|
|
141
|
+
/**
|
|
142
|
+
* This schema accepts a price reading: the state of one offer at one instant. `price` is the unit price for an
|
|
143
|
+
* order of `minimumQuantity` units, or of one unit. The quantities of the breaks increase, and each is more
|
|
144
|
+
* than the minimum.
|
|
145
|
+
*/
|
|
146
|
+
declare const priceReadingSchema: z.ZodType<PriceReading>;
|
|
147
|
+
/** One offer of a source, and its price reading at one instant. */
|
|
148
|
+
interface Observation {
|
|
149
|
+
readonly offer: Offer;
|
|
150
|
+
readonly reading: PriceReading;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* This record names a part that a buyer wants: the names of its maker, and its part numbers. A seller can write
|
|
154
|
+
* the brand of one maker in more than one form, so the want has a list of names.
|
|
155
|
+
*/
|
|
156
|
+
interface PartWant {
|
|
157
|
+
/** The names of the maker, as the sellers write the brand. */
|
|
158
|
+
readonly brands: readonly string[];
|
|
159
|
+
/** The part numbers of the maker. A part number of an offer matches when it starts with one of them, after the fold. */
|
|
160
|
+
readonly partNumbers: readonly string[];
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* This function tells if an offer is an offer of the part. One part number of the offer must have a brand of the
|
|
164
|
+
* want and start with a part number of the want. `foldCode` folds each text before the comparison. A part number
|
|
165
|
+
* of another maker does not match: many makers use short numbers like `A1383`.
|
|
166
|
+
*/
|
|
167
|
+
declare function offersPart(offer: Pick<Offer, "partNumbers">, want: PartWant): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* This function gives the latest observation of each offer, in the order of the offer ids. When two readings of
|
|
170
|
+
* one offer have the same instant, the later one in the list applies.
|
|
171
|
+
*/
|
|
172
|
+
declare function latestObservations(observations: readonly Observation[]): Observation[];
|
|
173
|
+
/** This function gives the latest observation of each offer of the part, in the order of the offer ids. */
|
|
174
|
+
declare function offersOfPart(observations: readonly Observation[], want: PartWant): Observation[];
|
|
175
|
+
/** This record is one offer that a buyer can choose, with the price of an order in the currency of the buyer. */
|
|
176
|
+
interface OfferChoice {
|
|
177
|
+
readonly observation: Observation;
|
|
178
|
+
/** The unit price for the count, times the count. */
|
|
179
|
+
readonly goods: Quantity;
|
|
180
|
+
/** The goods and the shipping, or null when the shipping cost is not known. */
|
|
181
|
+
readonly cost: Quantity | null;
|
|
182
|
+
/** True when the availability is `in-stock` or `low-stock`. */
|
|
183
|
+
readonly inStock: boolean;
|
|
184
|
+
}
|
|
185
|
+
/** These options change the choice of an offer. */
|
|
186
|
+
interface BestOfferOptions {
|
|
187
|
+
/** The currency of the prices, a unit of money of `@mark1russell7/quantity`, for example `USD`. An offer with a price in another currency is skipped. */
|
|
188
|
+
readonly currency: string;
|
|
189
|
+
/** The count of units of the order. The default is 1. */
|
|
190
|
+
readonly count?: number;
|
|
191
|
+
/** The conditions that the buyer accepts. The default is `new` only. */
|
|
192
|
+
readonly conditions?: readonly Condition[];
|
|
193
|
+
}
|
|
194
|
+
/** This record is the choice of an offer: the best offer, each offer in the order of the price, and each skipped offer. */
|
|
195
|
+
interface BestOffer {
|
|
196
|
+
/** The offer with the lowest price that is in stock, or else the offer with the lowest price, or null with no offer. */
|
|
197
|
+
readonly best: OfferChoice | null;
|
|
198
|
+
/** The offers, from the lowest price of the goods. Equal prices go in the order of the cost, then of the offer id. */
|
|
199
|
+
readonly offers: readonly OfferChoice[];
|
|
200
|
+
/** The offers that the choice skipped, each with the reason. */
|
|
201
|
+
readonly skipped: readonly {
|
|
202
|
+
readonly offerId: string;
|
|
203
|
+
readonly why: string;
|
|
204
|
+
}[];
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* This function chooses the offer to buy from the latest observation of each offer. It skips an offer with a
|
|
208
|
+
* condition that the buyer does not accept, a price in another currency, or a minimum above the count.
|
|
209
|
+
*
|
|
210
|
+
* @throws RangeError when the count is not a whole number of 1 or more, or when the currency is not a unit of money.
|
|
211
|
+
*/
|
|
212
|
+
declare function bestOffer(observations: readonly Observation[], options: BestOfferOptions): BestOffer;
|
|
213
|
+
export { priceBreakSchema as A, PartNumber as B, Spec as C, offerId as D, moneySchema as E, sourceOfOffer as F, matchKeys as H, sourceSchema as I, specSchema as L, productSchema as M, sellerSchema as N, offerSchema as O, shippingSchema as P, textSchema as R, Shipping as S, instantSchema as T, foldCode as V, PriceBreak as _, PartWant as a, Rating as b, offersOfPart as c, Availability as d, CONDITIONS as f, Offer as g, Format as h, OfferChoice as i, priceReadingSchema as j, partNumberSchema as k, offersPart as l, FORMATS as m, BestOfferOptions as n, bestOffer as o, Condition as p, Observation as r, latestObservations as s, BestOffer as t, AVAILABILITIES as u, PriceReading as v, gtinSchema as w, Seller as x, Product as y, Identifiers as z };
|
|
214
|
+
//# sourceMappingURL=offers-CVUAcRHs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"offers-CVUAcRHs.d.ts","names":[],"sources":["../src/identifiers.ts","../src/records.ts","../src/offers.ts"],"mappings":";;;UAGiB;WACN;WACA;;;UAIM;WACN;WACA,sBAAsB;;;;;;iBAOjB,SAAS;;;;;;iBAST,UAAU,aAAa;;;;;cCjB1B;;KAED,oBAAoB;;cAGnB;;KAED,uBAAuB;;cAGtB;;KAED,iBAAiB;;UAGZ;WACN;WACA;;;UAIM;WACN;WACA;;;UAIM;WACN;WACA;WACA,SAAS;;;UAIH;WACN;WACA;WACA;WACA;WACA;WACA,sBAAsB;WACtB,gBAAgB;;;UAIV;WACN;WACA;WACA;WACA;WACA;WACA;WACA,QAAQ;WACR,WAAW;WACX;WACA,QAAQ;WACR;WACA;WACA,sBAAsB;WACtB,gBAAgB;;;KAIf;WACG;;WACA;WAAwB,MAAM;;WAC9B;;WACA;;;UAGE;WACN;WACA,WAAW;;;UAIL;WACN;WACA;WACA,OAAO;WACP,YAAY;WACZ,UAAU;WACV,cAAc;WACd;WACA;WACA,uBAAuB;;;cAIrB,YAAY,EAAE;;cAKd,cAAc,EAAE;;cAKhB,YAAY,EAAE;;cAKd,aAAa,EAAE,QAAQ,UAAU;;cAGjC,eAAe,EAAE;;cAGjB,kBAAkB,EAAE,QAAQ;;cAG5B,YAAY,EAAE,QAAQ;;cAGtB,cAAc,EAAE,QAAQ;;cAOxB,eAAe,EAAE,QAAQ;;iBAWtB,QAAQ,gBAAgB;;iBAKxB,cAAc;;;;;cAUjB,aAAa,EAAE,QAAQ;;cAuBvB,gBAAgB,EAAE,QAAQ;;cAQ1B,kBAAkB,EAAE,QAAQ;;;;;;cAO5B,oBAAoB,EAAE,QAAQ;;UC/L1B;WACN,OAAO;WACP,SAAS;;;;;;UAOH;;WAEN;;WAEA;;;;;;;iBAQK,WAAW,OAAO,KAAK,uBAAuB,MAAM;;;;;iBAapD,mBAAmB,uBAAuB,gBAAgB;;iBAU1D,aAAa,uBAAuB,eAAe,MAAM,WAAW;;UAKnE;WACN,aAAa;;WAEb,OAAO;;WAEP,MAAM;;WAEN;;;UAIM;;WAEN;;WAEA;;WAEA,sBAAsB;;;UAIhB;;WAEN,MAAM;;WAEN,iBAAiB;;WAEjB;aAA6B;aAA0B;;;;;;;;;iBASlD,UAAU,uBAAuB,eAAe,SAAS,mBAAmB"}
|
package/build/plan.d.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { a as PartWant, p as Condition, r as Observation } from "./offers-CVUAcRHs.js";
|
|
2
|
+
import { Quantity } from "@mark1russell7/quantity";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { Objective, SweepCounts } from "@mark1russell7/strategy-search";
|
|
5
|
+
/** The format name of a need record. */
|
|
6
|
+
export declare const NEED_FORMAT = "buy-need/1";
|
|
7
|
+
/** The format name of a plan record. */
|
|
8
|
+
export declare const PLAN_FORMAT = "buy-plan/1";
|
|
9
|
+
/** The key of the inputs of a need in the space of a basket. A slot cannot have this name. */
|
|
10
|
+
export declare const NEED_KEY = "need";
|
|
11
|
+
/** The fields that the plan writes in the record of each slot. A fact of a part cannot have one of these names. */
|
|
12
|
+
export declare const SLOT_FIELDS: readonly ["slot", "part", "count", "cost"];
|
|
13
|
+
/** The largest count of evaluations of a plan, when the options do not give a count. */
|
|
14
|
+
export declare const PLAN_EVALUATIONS = 2e3;
|
|
15
|
+
/** A fact of a part, or an input of a need: a number, a text or a boolean. */
|
|
16
|
+
export type Fact = number | string | boolean;
|
|
17
|
+
/** One part that can fill a slot: its key in the slot, the part that the offers must match, and its facts. */
|
|
18
|
+
export interface NeedPart {
|
|
19
|
+
readonly key: string;
|
|
20
|
+
readonly want: PartWant;
|
|
21
|
+
/** The facts of the part that the programs read, for example its watts. */
|
|
22
|
+
readonly facts?: Readonly<Record<string, Fact>> | undefined;
|
|
23
|
+
}
|
|
24
|
+
/** The count of units of a slot. With `min` 0, a basket can leave the slot empty. */
|
|
25
|
+
export interface SlotCount {
|
|
26
|
+
readonly min: number;
|
|
27
|
+
readonly max: number;
|
|
28
|
+
}
|
|
29
|
+
/** One slot of a need: its name, the parts that can fill it, and the count of its units. The default count is 1. */
|
|
30
|
+
export interface NeedSlot {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly parts: readonly NeedPart[];
|
|
33
|
+
readonly count?: SlotCount | undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* One measure of a basket: a Vex program that gives a number. With `goal`, the measure is an objective of the search.
|
|
37
|
+
* A value below `min` or above `max` breaks the basket.
|
|
38
|
+
*/
|
|
39
|
+
export interface NeedMeasure {
|
|
40
|
+
readonly name: string;
|
|
41
|
+
/** The program, as the JSON form of a Vex expression. */
|
|
42
|
+
readonly program: unknown;
|
|
43
|
+
readonly goal?: "min" | "max" | undefined;
|
|
44
|
+
/** The unit of the values, as text for a reader. */
|
|
45
|
+
readonly unit?: string | undefined;
|
|
46
|
+
readonly min?: number | undefined;
|
|
47
|
+
readonly max?: number | undefined;
|
|
48
|
+
}
|
|
49
|
+
/** One rule of a basket: a Vex program that gives `true` when the basket keeps the rule. */
|
|
50
|
+
export interface NeedRule {
|
|
51
|
+
readonly name: string;
|
|
52
|
+
/** The program, as the JSON form of a Vex expression. */
|
|
53
|
+
readonly program: unknown;
|
|
54
|
+
}
|
|
55
|
+
/** This record is a need: the currency and the conditions of the offers, the inputs, the slots, the measures and the rules. */
|
|
56
|
+
export interface BuyNeed {
|
|
57
|
+
readonly format: typeof NEED_FORMAT;
|
|
58
|
+
readonly id: string;
|
|
59
|
+
/** The currency of the prices, a unit of money of `@mark1russell7/quantity`, for example `USD`. */
|
|
60
|
+
readonly currency: string;
|
|
61
|
+
/** The conditions that the buyer accepts. The default is `new` only. */
|
|
62
|
+
readonly conditions?: readonly Condition[] | undefined;
|
|
63
|
+
/** The inputs that the programs read at the key `need`, for example the load in watts. */
|
|
64
|
+
readonly inputs?: Readonly<Record<string, Fact>> | undefined;
|
|
65
|
+
readonly slots: readonly NeedSlot[];
|
|
66
|
+
readonly measures?: readonly NeedMeasure[] | undefined;
|
|
67
|
+
readonly rules?: readonly NeedRule[] | undefined;
|
|
68
|
+
}
|
|
69
|
+
/** This schema accepts the form of a need. `needProblems` examines the names, the counts and the programs. */
|
|
70
|
+
export declare const buyNeedSchema: z.ZodType<BuyNeed>;
|
|
71
|
+
/**
|
|
72
|
+
* This function gives the problems of a need. Two slots, parts, measures or rules with one name are a problem. A bad
|
|
73
|
+
* count is a problem. The slot name `need` and the measure name `price` are problems. A fact with the name of a field
|
|
74
|
+
* of a slot is a problem. A program that is not valid is a problem.
|
|
75
|
+
*/
|
|
76
|
+
export declare function needProblems(need: BuyNeed): string[];
|
|
77
|
+
/** This record is one item of a basket: the slot, the part, the count, the offer to buy and the cost with the shipping. */
|
|
78
|
+
export interface BuyItem {
|
|
79
|
+
readonly slot: string;
|
|
80
|
+
readonly part: string;
|
|
81
|
+
readonly count: number;
|
|
82
|
+
readonly offerId: string;
|
|
83
|
+
readonly cost: Quantity;
|
|
84
|
+
}
|
|
85
|
+
/** This record is one basket of the front: its config id, its price, the value of each measure and its items. */
|
|
86
|
+
export interface BuyChoice {
|
|
87
|
+
readonly config: string;
|
|
88
|
+
/** The sum of the cost of each item. Each item is one order, with its own shipping. */
|
|
89
|
+
readonly price: Quantity;
|
|
90
|
+
readonly values: Readonly<Record<string, number>>;
|
|
91
|
+
readonly items: readonly BuyItem[];
|
|
92
|
+
}
|
|
93
|
+
/** This record counts the baskets that break one constraint, with the reason of the first such basket. */
|
|
94
|
+
export interface BuyBreak {
|
|
95
|
+
/** The constraint: `price:<slot>`, `measure:<name>`, `limit:<name>` or `rule:<name>`. */
|
|
96
|
+
readonly name: string;
|
|
97
|
+
readonly count: number;
|
|
98
|
+
readonly why: string;
|
|
99
|
+
}
|
|
100
|
+
/** This record is a part that no basket can have, because no offer of the part is usable at a count of its slot. */
|
|
101
|
+
export interface UnpricedPart {
|
|
102
|
+
readonly slot: string;
|
|
103
|
+
readonly part: string;
|
|
104
|
+
readonly why: string;
|
|
105
|
+
}
|
|
106
|
+
/** This record is a buy plan: the method of the search, its counts, the front of the baskets and the reasons of the breaks. */
|
|
107
|
+
export interface BuyPlan {
|
|
108
|
+
readonly format: typeof PLAN_FORMAT;
|
|
109
|
+
/** The id of the need. */
|
|
110
|
+
readonly need: string;
|
|
111
|
+
readonly currency: string;
|
|
112
|
+
/** `grid` evaluates each basket. `evolve` is a genetic search. `none` tells that a slot that must have a part has no part with an offer. */
|
|
113
|
+
readonly method: "grid" | "evolve" | "none";
|
|
114
|
+
/** The seed of a genetic search, or null. */
|
|
115
|
+
readonly seed: number | null;
|
|
116
|
+
/** The id of the run of strategy-search, or null for `none`. */
|
|
117
|
+
readonly run: string | null;
|
|
118
|
+
readonly objectives: readonly Objective[];
|
|
119
|
+
readonly counts: SweepCounts;
|
|
120
|
+
/** The baskets on the Pareto front, from the lowest price. Equal prices go in the order of the config id. */
|
|
121
|
+
readonly front: readonly BuyChoice[];
|
|
122
|
+
/** The constraints that the evaluated baskets break, in the order of their names. */
|
|
123
|
+
readonly breaks: readonly BuyBreak[];
|
|
124
|
+
/** The parts with no usable offer, in the order of the slots and of their parts. */
|
|
125
|
+
readonly unpriced: readonly UnpricedPart[];
|
|
126
|
+
}
|
|
127
|
+
/** These options change the search of a plan. */
|
|
128
|
+
export interface PlanOptions {
|
|
129
|
+
/** The largest count of evaluations. A space with no more baskets gets a grid of each basket. The default is `PLAN_EVALUATIONS`. */
|
|
130
|
+
readonly evaluations?: number | undefined;
|
|
131
|
+
/** The seed of a genetic search. The default is the id of the need. */
|
|
132
|
+
readonly seed?: number | string | undefined;
|
|
133
|
+
/** The count of the baskets of a generation of a genetic search. The default is the default of strategy-search. */
|
|
134
|
+
readonly population?: number | undefined;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* This function makes a buy plan from a need and the observations of the offers. Each slot is a stage of a strategy
|
|
138
|
+
* space. Each part with a usable offer is an option of its stage, with a param `count`. The price of a basket is the sum
|
|
139
|
+
* of the cost of each item.
|
|
140
|
+
*
|
|
141
|
+
* Each measure and each rule is a Vex program that evaluates at the key `need` of a record space. The key `need` has
|
|
142
|
+
* the inputs. The key of each slot has the facts of its part, `slot`, `part`, `count` and `cost`. A slot with no part
|
|
143
|
+
* has only `slot`, the count 0 and the cost 0. Thus the axis `others` gives the slots.
|
|
144
|
+
*
|
|
145
|
+
* A space with no more baskets than `evaluations` gets a grid of each basket, and a larger space gets a genetic search.
|
|
146
|
+
*
|
|
147
|
+
* @throws RangeError when the need or its currency is not valid, or when `evaluations` is not a whole number of 1 or more.
|
|
148
|
+
* The function also throws a RangeError when strategy-search refuses the options.
|
|
149
|
+
*/
|
|
150
|
+
export declare function planBuys(need: BuyNeed, observations: readonly Observation[], options?: PlanOptions): BuyPlan;
|
|
151
|
+
//# sourceMappingURL=plan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.d.ts","names":[],"sources":["../src/plan.ts"],"mappings":";;;;;qBAiBa;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;YAMD;;iBAGK;WACN;WACA,MAAM;;WAEN,QAAQ,SAAS,eAAe;;;iBAI1B;WACN;WACA;;;iBAIM;WACN;WACA,gBAAgB;WAChB,QAAQ;;;;;;iBAOF;WACN;;WAEA;WACA;;WAEA;WACA;WACA;;;iBAIM;WACN;;WAEA;;;iBAIM;WACN,eAAe;WACf;;WAEA;;WAEA,sBAAsB;;WAEtB,SAAS,SAAS,eAAe;WACjC,gBAAgB;WAChB,oBAAoB;WACpB,iBAAiB;;;qBASf,eAAe,EAAE,QAAQ;;;;;;wBAuDtB,aAAa,MAAM;;iBAuDlB;WACN;WACA;WACA;WACA;WACA,MAAM;;;iBAIA;WACN;;WAEA,OAAO;WACP,QAAQ,SAAS;WACjB,gBAAgB;;;iBAIV;;WAEN;WACA;WACA;;;iBAIM;WACN;WACA;WACA;;;iBAIM;WACN,eAAe;;WAEf;WACA;;WAEA;;WAEA;;WAEA;WACA,qBAAqB;WACrB,QAAQ;;WAER,gBAAgB;;WAEhB,iBAAiB;;WAEjB,mBAAmB;;;iBAIb;;WAEN;;WAEA;;WAEA;;;;;;;;;;;;;;;;wBA6CK,SAAS,MAAM,SAAS,uBAAuB,eAAe,UAAS,cAAmB"}
|