@roomwise/calc-engine 0.4.0 → 0.6.0

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/dist/index.d.ts CHANGED
@@ -5,15 +5,22 @@ export declare const LocalizedTextSchema: z.ZodObject<{
5
5
  uk: z.ZodString;
6
6
  }, z.core.$strip>;
7
7
  export type LocalizedText = z.infer<typeof LocalizedTextSchema>;
8
+ export declare const ScopeSchema: z.ZodEnum<{
9
+ FULL: "FULL";
10
+ PARTIAL: "PARTIAL";
11
+ }>;
12
+ export type Scope = z.infer<typeof ScopeSchema>;
8
13
  export declare const FinishLevelSchema: z.ZodEnum<{
9
14
  ROUGH: "ROUGH";
10
15
  PRE_FINISH: "PRE_FINISH";
16
+ LIVED_IN: "LIVED_IN";
11
17
  }>;
12
18
  export type FinishLevel = z.infer<typeof FinishLevelSchema>;
13
19
  export declare const RuleLevelSchema: z.ZodEnum<{
14
20
  OBJECT: "OBJECT";
15
21
  CATEGORY: "CATEGORY";
16
22
  MATERIAL_TYPE: "MATERIAL_TYPE";
23
+ SURFACE: "SURFACE";
17
24
  }>;
18
25
  export type RuleLevel = z.infer<typeof RuleLevelSchema>;
19
26
  export declare const RateSourceSchema: z.ZodEnum<{
@@ -22,10 +29,10 @@ export declare const RateSourceSchema: z.ZodEnum<{
22
29
  }>;
23
30
  export type RateSource = z.infer<typeof RateSourceSchema>;
24
31
  export declare const SurfaceKindSchema: z.ZodEnum<{
25
- NONE: "NONE";
26
32
  FLOOR: "FLOOR";
27
33
  WALLS: "WALLS";
28
34
  CEILING: "CEILING";
35
+ NONE: "NONE";
29
36
  }>;
30
37
  export type SurfaceKind = z.infer<typeof SurfaceKindSchema>;
31
38
  export declare const ProductUnitSchema: z.ZodEnum<{
@@ -56,6 +63,8 @@ export declare const RoomTypeCodeSchema: z.ZodEnum<{
56
63
  KITCHEN: "KITCHEN";
57
64
  KITCHEN_LIVING: "KITCHEN_LIVING";
58
65
  BATHROOM: "BATHROOM";
66
+ HALLWAY: "HALLWAY";
67
+ STORAGE: "STORAGE";
59
68
  }>;
60
69
  export type RoomTypeCode = z.infer<typeof RoomTypeCodeSchema>;
61
70
  export declare const CurrencySchema: z.ZodEnum<{
@@ -71,6 +80,12 @@ export declare const SectionSchema: z.ZodEnum<{
71
80
  MATERIALS: "MATERIALS";
72
81
  }>;
73
82
  export type Section = z.infer<typeof SectionSchema>;
83
+ export declare const LineComponentKindSchema: z.ZodEnum<{
84
+ MATERIAL: "MATERIAL";
85
+ LABOR: "LABOR";
86
+ PREP: "PREP";
87
+ }>;
88
+ export type LineComponentKind = z.infer<typeof LineComponentKindSchema>;
74
89
  export declare const LineStatusSchema: z.ZodEnum<{
75
90
  OK: "OK";
76
91
  INCLUDED: "INCLUDED";
@@ -102,6 +117,8 @@ export declare const RoomConfigurationSchema: z.ZodObject<{
102
117
  KITCHEN: "KITCHEN";
103
118
  KITCHEN_LIVING: "KITCHEN_LIVING";
104
119
  BATHROOM: "BATHROOM";
120
+ HALLWAY: "HALLWAY";
121
+ STORAGE: "STORAGE";
105
122
  }>;
106
123
  lengthM: z.ZodNumber;
107
124
  widthM: z.ZodNumber;
@@ -120,11 +137,16 @@ export declare const OptionSelectionSchema: z.ZodObject<{
120
137
  }, z.core.$strip>;
121
138
  export type OptionSelection = z.infer<typeof OptionSelectionSchema>;
122
139
  export declare const ConfigurationSchema: z.ZodObject<{
140
+ scope: z.ZodDefault<z.ZodEnum<{
141
+ FULL: "FULL";
142
+ PARTIAL: "PARTIAL";
143
+ }>>;
123
144
  finishLevel: z.ZodEnum<{
124
145
  ROUGH: "ROUGH";
125
146
  PRE_FINISH: "PRE_FINISH";
147
+ LIVED_IN: "LIVED_IN";
126
148
  }>;
127
- totalAreaSqm: z.ZodNumber;
149
+ totalAreaSqm: z.ZodNullable<z.ZodNumber>;
128
150
  balconyAreaSqm: z.ZodNumber;
129
151
  balconyTiles: z.ZodBoolean;
130
152
  rooms: z.ZodArray<z.ZodObject<{
@@ -136,6 +158,8 @@ export declare const ConfigurationSchema: z.ZodObject<{
136
158
  KITCHEN: "KITCHEN";
137
159
  KITCHEN_LIVING: "KITCHEN_LIVING";
138
160
  BATHROOM: "BATHROOM";
161
+ HALLWAY: "HALLWAY";
162
+ STORAGE: "STORAGE";
139
163
  }>;
140
164
  lengthM: z.ZodNumber;
141
165
  widthM: z.ZodNumber;
@@ -164,6 +188,17 @@ export declare const EstimateMessageSchema: z.ZodObject<{
164
188
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
165
189
  }, z.core.$strip>;
166
190
  export type EstimateMessage = z.infer<typeof EstimateMessageSchema>;
191
+ export declare const LineComponentSchema: z.ZodObject<{
192
+ kind: z.ZodEnum<{
193
+ MATERIAL: "MATERIAL";
194
+ LABOR: "LABOR";
195
+ PREP: "PREP";
196
+ }>;
197
+ ruleId: z.ZodString;
198
+ amountCents: z.ZodNumber;
199
+ sharedWithCategoryId: z.ZodOptional<z.ZodString>;
200
+ }, z.core.$strip>;
201
+ export type LineComponent = z.infer<typeof LineComponentSchema>;
167
202
  export declare const EstimateLineSchema: z.ZodObject<{
168
203
  id: z.ZodString;
169
204
  section: z.ZodEnum<{
@@ -191,6 +226,16 @@ export declare const EstimateLineSchema: z.ZodObject<{
191
226
  unitPriceCents: z.ZodNullable<z.ZodInt>;
192
227
  amountCents: z.ZodInt;
193
228
  amountUahKopecks: z.ZodNullable<z.ZodInt>;
229
+ components: z.ZodOptional<z.ZodArray<z.ZodObject<{
230
+ kind: z.ZodEnum<{
231
+ MATERIAL: "MATERIAL";
232
+ LABOR: "LABOR";
233
+ PREP: "PREP";
234
+ }>;
235
+ ruleId: z.ZodString;
236
+ amountCents: z.ZodNumber;
237
+ sharedWithCategoryId: z.ZodOptional<z.ZodString>;
238
+ }, z.core.$strip>>>;
194
239
  warnings: z.ZodArray<z.ZodObject<{
195
240
  code: z.ZodString;
196
241
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
@@ -268,6 +313,16 @@ export declare const EstimateSchema: z.ZodObject<{
268
313
  unitPriceCents: z.ZodNullable<z.ZodInt>;
269
314
  amountCents: z.ZodInt;
270
315
  amountUahKopecks: z.ZodNullable<z.ZodInt>;
316
+ components: z.ZodOptional<z.ZodArray<z.ZodObject<{
317
+ kind: z.ZodEnum<{
318
+ MATERIAL: "MATERIAL";
319
+ LABOR: "LABOR";
320
+ PREP: "PREP";
321
+ }>;
322
+ ruleId: z.ZodString;
323
+ amountCents: z.ZodNumber;
324
+ sharedWithCategoryId: z.ZodOptional<z.ZodString>;
325
+ }, z.core.$strip>>>;
271
326
  warnings: z.ZodArray<z.ZodObject<{
272
327
  code: z.ZodString;
273
328
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
@@ -309,6 +364,8 @@ export declare const RuleSampleSchema: z.ZodObject<{
309
364
  KITCHEN: "KITCHEN";
310
365
  KITCHEN_LIVING: "KITCHEN_LIVING";
311
366
  BATHROOM: "BATHROOM";
367
+ HALLWAY: "HALLWAY";
368
+ STORAGE: "STORAGE";
312
369
  }>;
313
370
  lengthM: z.ZodNumber;
314
371
  widthM: z.ZodNumber;
@@ -324,22 +381,35 @@ export declare const RuleSampleSchema: z.ZodObject<{
324
381
  }>;
325
382
  wastePercent: z.ZodNumber;
326
383
  }, z.core.$strip>>;
384
+ surfaceArea: z.ZodOptional<z.ZodNumber>;
385
+ puttyRequired: z.ZodOptional<z.ZodBoolean>;
327
386
  object: z.ZodObject<{
328
- totalAreaSqm: z.ZodNumber;
387
+ scope: z.ZodEnum<{
388
+ FULL: "FULL";
389
+ PARTIAL: "PARTIAL";
390
+ }>;
391
+ totalAreaSqm: z.ZodNullable<z.ZodNumber>;
329
392
  balconyAreaSqm: z.ZodNumber;
330
393
  balconyTiles: z.ZodBoolean;
331
394
  finishLevel: z.ZodEnum<{
332
395
  ROUGH: "ROUGH";
333
396
  PRE_FINISH: "PRE_FINISH";
397
+ LIVED_IN: "LIVED_IN";
334
398
  }>;
335
399
  roomsCount: z.ZodInt;
336
400
  bathroomsCount: z.ZodInt;
401
+ roomsFloorArea: z.ZodNumber;
402
+ roomsWallArea: z.ZodNumber;
403
+ roomsPuttyWallArea: z.ZodOptional<z.ZodNumber>;
404
+ roomsPerimeter: z.ZodNumber;
405
+ wetRoomsCount: z.ZodInt;
337
406
  }, z.core.$strip>;
338
407
  }, z.core.$strip>;
339
408
  export type RuleSample = z.infer<typeof RuleSampleSchema>;
340
409
  export declare const RulePreviewSchema: z.ZodObject<{
341
410
  quantity: z.ZodNullable<z.ZodNumber>;
342
411
  amountCents: z.ZodNullable<z.ZodInt>;
412
+ laborCents: z.ZodNullable<z.ZodInt>;
343
413
  variables: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodNumber, z.ZodBoolean, z.ZodString]>>;
344
414
  coefficients: z.ZodRecord<z.ZodString, z.ZodNumber>;
345
415
  error: z.ZodNullable<z.ZodObject<{
@@ -376,24 +446,16 @@ export declare const PricingLimitsSchema: z.ZodObject<{
376
446
  min: z.ZodNumber;
377
447
  max: z.ZodNumber;
378
448
  }, z.core.$strip>;
449
+ missingAreaHintSqm: z.ZodNumber;
379
450
  }, z.core.$strip>;
380
451
  export type PricingLimits = z.infer<typeof PricingLimitsSchema>;
381
- export declare const BaseRateSchema: z.ZodObject<{
382
- finishLevel: z.ZodEnum<{
383
- ROUGH: "ROUGH";
384
- PRE_FINISH: "PRE_FINISH";
385
- }>;
386
- areaFromSqm: z.ZodNumber;
387
- areaToSqm: z.ZodNumber;
388
- rateCentsPerSqm: z.ZodInt;
389
- }, z.core.$strip>;
390
- export type BaseRate = z.infer<typeof BaseRateSchema>;
391
452
  export declare const PricingRuleSchema: z.ZodObject<{
392
453
  id: z.ZodString;
393
454
  level: z.ZodEnum<{
394
455
  OBJECT: "OBJECT";
395
456
  CATEGORY: "CATEGORY";
396
457
  MATERIAL_TYPE: "MATERIAL_TYPE";
458
+ SURFACE: "SURFACE";
397
459
  }>;
398
460
  categoryId: z.ZodNullable<z.ZodString>;
399
461
  materialTypeId: z.ZodNullable<z.ZodString>;
@@ -402,7 +464,14 @@ export declare const PricingRuleSchema: z.ZodObject<{
402
464
  uk: z.ZodString;
403
465
  }, z.core.$strip>;
404
466
  quantityFormula: z.ZodNullable<z.ZodString>;
467
+ surface: z.ZodNullable<z.ZodEnum<{
468
+ FLOOR: "FLOOR";
469
+ WALLS: "WALLS";
470
+ CEILING: "CEILING";
471
+ }>>;
472
+ baseComponent: z.ZodBoolean;
405
473
  costFormula: z.ZodString;
474
+ laborFormula: z.ZodNullable<z.ZodString>;
406
475
  sortOrder: z.ZodInt;
407
476
  }, z.core.$strip>;
408
477
  export type PricingRule = z.infer<typeof PricingRuleSchema>;
@@ -415,11 +484,12 @@ export declare const PricingCategorySchema: z.ZodObject<{
415
484
  id: z.ZodString;
416
485
  wastePercent: z.ZodNumber;
417
486
  surface: z.ZodEnum<{
418
- NONE: "NONE";
419
487
  FLOOR: "FLOOR";
420
488
  WALLS: "WALLS";
421
489
  CEILING: "CEILING";
490
+ NONE: "NONE";
422
491
  }>;
492
+ requiresPutty: z.ZodDefault<z.ZodBoolean>;
423
493
  }, z.core.$strip>;
424
494
  export type PricingCategory = z.infer<typeof PricingCategorySchema>;
425
495
  export declare const PricingMaterialTypeSchema: z.ZodObject<{
@@ -454,6 +524,10 @@ export declare const PricingPackageItemSchema: z.ZodObject<{
454
524
  }>>;
455
525
  }, z.core.$strip>;
456
526
  export type PricingPackageItem = z.infer<typeof PricingPackageItemSchema>;
527
+ export declare function findOptionPriceSourceViolation(priceCents: number | null, priceCoefficientKeys: readonly string[]): {
528
+ path: 'priceCents' | 'priceCoefficientKeys';
529
+ message: string;
530
+ } | null;
457
531
  export declare const PricingOptionSchema: z.ZodObject<{
458
532
  id: z.ZodString;
459
533
  code: z.ZodNullable<z.ZodEnum<{
@@ -463,7 +537,7 @@ export declare const PricingOptionSchema: z.ZodObject<{
463
537
  ENGINEERING: "ENGINEERING";
464
538
  ADDITIONAL: "ADDITIONAL";
465
539
  }>;
466
- priceCents: z.ZodInt;
540
+ priceCents: z.ZodNullable<z.ZodInt>;
467
541
  unit: z.ZodEnum<{
468
542
  PIECE: "PIECE";
469
543
  ROOM_SQM: "ROOM_SQM";
@@ -471,6 +545,11 @@ export declare const PricingOptionSchema: z.ZodObject<{
471
545
  PROJECT: "PROJECT";
472
546
  }>;
473
547
  roomTypeCodes: z.ZodArray<z.ZodString>;
548
+ priceCoefficientKeys: z.ZodArray<z.ZodString>;
549
+ scopes: z.ZodArray<z.ZodEnum<{
550
+ FULL: "FULL";
551
+ PARTIAL: "PARTIAL";
552
+ }>>;
474
553
  minQuantity: z.ZodNullable<z.ZodInt>;
475
554
  maxQuantity: z.ZodNullable<z.ZodInt>;
476
555
  available: z.ZodBoolean;
@@ -503,16 +582,8 @@ export declare const PricingDataSchema: z.ZodObject<{
503
582
  min: z.ZodNumber;
504
583
  max: z.ZodNumber;
505
584
  }, z.core.$strip>;
585
+ missingAreaHintSqm: z.ZodNumber;
506
586
  }, z.core.$strip>;
507
- baseRates: z.ZodArray<z.ZodObject<{
508
- finishLevel: z.ZodEnum<{
509
- ROUGH: "ROUGH";
510
- PRE_FINISH: "PRE_FINISH";
511
- }>;
512
- areaFromSqm: z.ZodNumber;
513
- areaToSqm: z.ZodNumber;
514
- rateCentsPerSqm: z.ZodInt;
515
- }, z.core.$strip>>;
516
587
  coefficients: z.ZodRecord<z.ZodString, z.ZodNumber>;
517
588
  rules: z.ZodArray<z.ZodObject<{
518
589
  id: z.ZodString;
@@ -520,6 +591,7 @@ export declare const PricingDataSchema: z.ZodObject<{
520
591
  OBJECT: "OBJECT";
521
592
  CATEGORY: "CATEGORY";
522
593
  MATERIAL_TYPE: "MATERIAL_TYPE";
594
+ SURFACE: "SURFACE";
523
595
  }>;
524
596
  categoryId: z.ZodNullable<z.ZodString>;
525
597
  materialTypeId: z.ZodNullable<z.ZodString>;
@@ -528,7 +600,14 @@ export declare const PricingDataSchema: z.ZodObject<{
528
600
  uk: z.ZodString;
529
601
  }, z.core.$strip>;
530
602
  quantityFormula: z.ZodNullable<z.ZodString>;
603
+ surface: z.ZodNullable<z.ZodEnum<{
604
+ FLOOR: "FLOOR";
605
+ WALLS: "WALLS";
606
+ CEILING: "CEILING";
607
+ }>>;
608
+ baseComponent: z.ZodBoolean;
531
609
  costFormula: z.ZodString;
610
+ laborFormula: z.ZodNullable<z.ZodString>;
532
611
  sortOrder: z.ZodInt;
533
612
  }, z.core.$strip>>;
534
613
  roomTypes: z.ZodArray<z.ZodObject<{
@@ -539,11 +618,12 @@ export declare const PricingDataSchema: z.ZodObject<{
539
618
  id: z.ZodString;
540
619
  wastePercent: z.ZodNumber;
541
620
  surface: z.ZodEnum<{
542
- NONE: "NONE";
543
621
  FLOOR: "FLOOR";
544
622
  WALLS: "WALLS";
545
623
  CEILING: "CEILING";
624
+ NONE: "NONE";
546
625
  }>;
626
+ requiresPutty: z.ZodDefault<z.ZodBoolean>;
547
627
  }, z.core.$strip>>;
548
628
  materialTypes: z.ZodArray<z.ZodObject<{
549
629
  id: z.ZodString;
@@ -583,7 +663,7 @@ export declare const PricingDataSchema: z.ZodObject<{
583
663
  ENGINEERING: "ENGINEERING";
584
664
  ADDITIONAL: "ADDITIONAL";
585
665
  }>;
586
- priceCents: z.ZodInt;
666
+ priceCents: z.ZodNullable<z.ZodInt>;
587
667
  unit: z.ZodEnum<{
588
668
  PIECE: "PIECE";
589
669
  ROOM_SQM: "ROOM_SQM";
@@ -591,6 +671,11 @@ export declare const PricingDataSchema: z.ZodObject<{
591
671
  PROJECT: "PROJECT";
592
672
  }>;
593
673
  roomTypeCodes: z.ZodArray<z.ZodString>;
674
+ priceCoefficientKeys: z.ZodArray<z.ZodString>;
675
+ scopes: z.ZodArray<z.ZodEnum<{
676
+ FULL: "FULL";
677
+ PARTIAL: "PARTIAL";
678
+ }>>;
594
679
  minQuantity: z.ZodNullable<z.ZodInt>;
595
680
  maxQuantity: z.ZodNullable<z.ZodInt>;
596
681
  available: z.ZodBoolean;
@@ -714,6 +799,7 @@ export interface PreviewRuleInput {
714
799
  readonly level: RuleLevel;
715
800
  readonly quantityFormula: string | null;
716
801
  readonly costFormula: string;
802
+ readonly laborFormula?: string | null;
717
803
  readonly coefficients: Readonly<Record<string, number>>;
718
804
  readonly sample: RuleSample;
719
805
  }
@@ -724,7 +810,7 @@ export declare function levenshtein(a: string, b: string): number;
724
810
  export declare function suggestNearest(name: string, candidates: readonly string[], maxDistance?: number): string | undefined;
725
811
  //#endregion
726
812
  //#region src/formula/validate.d.ts
727
- export type FormulaKind = 'quantity' | 'cost';
813
+ export type FormulaKind = 'quantity' | 'cost' | 'labor';
728
814
  export type FormulaScope = 'room' | 'product' | 'object';
729
815
  export interface FormulaVariable {
730
816
  readonly name: string;
@@ -733,6 +819,8 @@ export interface FormulaVariable {
733
819
  }
734
820
  export declare const FORMULA_SCOPE_VARIABLES: Record<FormulaScope, readonly FormulaVariable[]>;
735
821
  export declare const FORMULA_QUANTITY_VARIABLE: FormulaVariable;
822
+ export declare const FORMULA_SURFACE_AREA_VARIABLE: FormulaVariable;
823
+ export declare const FORMULA_PUTTY_REQUIRED_VARIABLE: FormulaVariable;
736
824
  export declare const FORMULA_VARIABLES: Record<RuleLevel, readonly FormulaVariable[]>;
737
825
  export interface ValidateFormulaInput {
738
826
  readonly level: RuleLevel;
@@ -755,14 +843,21 @@ export declare function toCents(dollars: number): number;
755
843
  //#endregion
756
844
  //#region src/variables/object.d.ts
757
845
  export interface ObjectVariables {
846
+ readonly scope: Scope;
758
847
  readonly totalArea: number;
759
848
  readonly balconyArea: number;
760
849
  readonly balconyTiles: boolean;
761
850
  readonly finishLevel: FinishLevel;
762
851
  readonly roomsCount: number;
763
852
  readonly bathroomsCount: number;
853
+ readonly roomsFloorArea: number;
854
+ readonly roomsWallArea: number;
855
+ readonly roomsPuttyWallArea: number;
856
+ readonly roomsPerimeter: number;
857
+ readonly wetRoomsCount: number;
764
858
  }
765
- export declare function objectVariables(configuration: Configuration): ObjectVariables;
859
+ export declare function totalAreaOf(scope: Scope, totalAreaSqm: number | null, roomsFloorArea: number): number;
860
+ export declare function objectVariables(configuration: Configuration, categories: readonly PricingCategory[]): ObjectVariables;
766
861
  //#endregion
767
862
  //#region src/variables/product.d.ts
768
863
  export interface ProductVariables {
@@ -773,6 +868,9 @@ export interface ProductVariables {
773
868
  export declare function productVariablesOf(product: Pick<PricingProduct, 'priceCents' | 'unit'>, wastePercent: number): ProductVariables;
774
869
  export declare function productVariables(product: PricingProduct, category: PricingCategory): ProductVariables;
775
870
  //#endregion
871
+ //#region src/variables/putty.d.ts
872
+ export declare function puttyRequiredOn(room: RoomConfiguration, surface: PricingCategory['surface'], categories: readonly PricingCategory[]): boolean;
873
+ //#endregion
776
874
  //#region src/variables/room.d.ts
777
875
  export interface RoomVariables {
778
876
  readonly length: number;