@roomwise/calc-engine 0.1.0 → 0.3.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/README.md CHANGED
@@ -136,7 +136,6 @@ const preview = previewRule({
136
136
  totalAreaSqm: 62,
137
137
  balconyAreaSqm: 4,
138
138
  balconyTiles: true,
139
- gas: false,
140
139
  kitchenType: 'SEPARATE',
141
140
  finishLevel: 'PRE_FINISH',
142
141
  roomsCount: 1,
@@ -202,7 +201,7 @@ roomType == 'KITCHEN' ? ceil(floorArea / 2) : 0
202
201
  | product | `waste` | number, a fraction (5% is `0.05`): the product override, else the category value |
203
202
  | product | `unit` | `SQM`, `LINEAR_M`, `PIECE` |
204
203
  | object | `totalArea`, `balconyArea` | number |
205
- | object | `balconyTiles`, `gas` | boolean |
204
+ | object | `balconyTiles` | boolean |
206
205
  | object | `kitchenType` | `SEPARATE`, `KITCHEN_LIVING` |
207
206
  | object | `finishLevel` | `ROUGH`, `PRE_FINISH` |
208
207
  | object | `roomsCount`, `bathroomsCount` | number (living rooms, bedrooms and kitchen-living rooms count as rooms) |
package/dist/index.cjs CHANGED
@@ -118,7 +118,7 @@ function optionLine(configuration, option, selection) {
118
118
  params: { optionId: option.id }
119
119
  });
120
120
  const selected = configuration.rooms.filter((room) => selection.roomClientIds?.includes(room.clientId));
121
- const allowed = selected.filter((room) => option.roomTypeCodes.includes(room.roomTypeCode));
121
+ const allowed = option.roomTypeCodes.length === 0 ? selected : selected.filter((room) => option.roomTypeCodes.includes(room.roomTypeCode));
122
122
  const rejected = selected.filter((room) => !allowed.includes(room));
123
123
  const quantity = unitQuantity(option.unit, allowed, selection.quantity ?? option.minQuantity ?? 1);
124
124
  return pricedLine({
@@ -208,7 +208,6 @@ function objectVariables(configuration) {
208
208
  totalArea: configuration.totalAreaSqm,
209
209
  balconyArea: configuration.balconyAreaSqm,
210
210
  balconyTiles: configuration.balconyTiles,
211
- gas: configuration.gas,
212
211
  kitchenType: configuration.kitchenType,
213
212
  finishLevel: configuration.finishLevel,
214
213
  roomsCount: configuration.rooms.filter((room) => COUNTED_AS_ROOMS.includes(room.roomTypeCode)).length,
@@ -791,6 +790,7 @@ const OptionUnitSchema = zod.z.enum([
791
790
  "PROJECT"
792
791
  ]);
793
792
  const OptionKindSchema = zod.z.enum(["ENGINEERING", "ADDITIONAL"]);
793
+ const OptionCodeSchema = zod.z.enum(["HEATED_FLOOR"]);
794
794
  const RoomTypeCodeSchema = zod.z.enum([
795
795
  "LIVING_ROOM",
796
796
  "BEDROOM",
@@ -827,6 +827,7 @@ const RoomSelectionSchema = zod.z.object({
827
827
  });
828
828
  const RoomConfigurationSchema = zod.z.object({
829
829
  clientId: zod.z.string(),
830
+ name: zod.z.string().trim().min(1).max(60).optional(),
830
831
  roomTypeCode: RoomTypeCodeSchema,
831
832
  lengthM: zod.z.number().positive(),
832
833
  widthM: zod.z.number().positive(),
@@ -853,7 +854,6 @@ const ConfigurationSchema = zod.z.object({
853
854
  totalAreaSqm: zod.z.number().positive(),
854
855
  balconyAreaSqm: zod.z.number().min(0),
855
856
  balconyTiles: zod.z.boolean(),
856
- gas: zod.z.boolean(),
857
857
  kitchenType: KitchenTypeSchema,
858
858
  rooms: zod.z.array(RoomConfigurationSchema),
859
859
  options: zod.z.array(OptionSelectionSchema),
@@ -944,6 +944,7 @@ const PricingPackageItemSchema = zod.z.object({
944
944
  });
945
945
  const PricingOptionSchema = zod.z.object({
946
946
  id: zod.z.string(),
947
+ code: OptionCodeSchema.nullable(),
947
948
  kind: OptionKindSchema,
948
949
  priceCents: CentsSchema,
949
950
  unit: OptionUnitSchema,
@@ -1028,7 +1029,6 @@ const RuleSampleSchema = zod.z.object({
1028
1029
  totalAreaSqm: zod.z.number().positive(),
1029
1030
  balconyAreaSqm: zod.z.number().min(0),
1030
1031
  balconyTiles: zod.z.boolean(),
1031
- gas: zod.z.boolean(),
1032
1032
  kitchenType: KitchenTypeSchema,
1033
1033
  finishLevel: FinishLevelSchema,
1034
1034
  roomsCount: zod.z.int().min(0),
@@ -1187,7 +1187,6 @@ function objectScope({ object }) {
1187
1187
  totalArea: object.totalAreaSqm,
1188
1188
  balconyArea: object.balconyAreaSqm,
1189
1189
  balconyTiles: object.balconyTiles,
1190
- gas: object.gas,
1191
1190
  kitchenType: object.kitchenType,
1192
1191
  finishLevel: object.finishLevel,
1193
1192
  roomsCount: object.roomsCount,
@@ -1316,7 +1315,6 @@ const FORMULA_SCOPE_VARIABLES = {
1316
1315
  number("totalArea"),
1317
1316
  number("balconyArea"),
1318
1317
  boolean("balconyTiles"),
1319
- boolean("gas"),
1320
1318
  enumeration("kitchenType", KitchenTypeSchema.options),
1321
1319
  enumeration("finishLevel", FinishLevelSchema.options),
1322
1320
  number("roomsCount"),
@@ -1570,6 +1568,7 @@ exports.FinishLevelSchema = FinishLevelSchema;
1570
1568
  exports.KitchenTypeSchema = KitchenTypeSchema;
1571
1569
  exports.LineStatusSchema = LineStatusSchema;
1572
1570
  exports.LocalizedTextSchema = LocalizedTextSchema;
1571
+ exports.OptionCodeSchema = OptionCodeSchema;
1573
1572
  exports.OptionKindSchema = OptionKindSchema;
1574
1573
  exports.OptionSelectionSchema = OptionSelectionSchema;
1575
1574
  exports.OptionUnitSchema = OptionUnitSchema;
package/dist/index.d.cts CHANGED
@@ -46,6 +46,10 @@ export declare const OptionKindSchema: z.ZodEnum<{
46
46
  ADDITIONAL: "ADDITIONAL";
47
47
  }>;
48
48
  export type OptionKind = z.infer<typeof OptionKindSchema>;
49
+ export declare const OptionCodeSchema: z.ZodEnum<{
50
+ HEATED_FLOOR: "HEATED_FLOOR";
51
+ }>;
52
+ export type OptionCode = z.infer<typeof OptionCodeSchema>;
49
53
  export declare const RoomTypeCodeSchema: z.ZodEnum<{
50
54
  LIVING_ROOM: "LIVING_ROOM";
51
55
  BEDROOM: "BEDROOM";
@@ -96,6 +100,7 @@ export declare const RoomSelectionSchema: z.ZodObject<{
96
100
  export type RoomSelection = z.infer<typeof RoomSelectionSchema>;
97
101
  export declare const RoomConfigurationSchema: z.ZodObject<{
98
102
  clientId: z.ZodString;
103
+ name: z.ZodOptional<z.ZodString>;
99
104
  roomTypeCode: z.ZodEnum<{
100
105
  LIVING_ROOM: "LIVING_ROOM";
101
106
  BEDROOM: "BEDROOM";
@@ -127,13 +132,13 @@ export declare const ConfigurationSchema: z.ZodObject<{
127
132
  totalAreaSqm: z.ZodNumber;
128
133
  balconyAreaSqm: z.ZodNumber;
129
134
  balconyTiles: z.ZodBoolean;
130
- gas: z.ZodBoolean;
131
135
  kitchenType: z.ZodEnum<{
132
136
  KITCHEN_LIVING: "KITCHEN_LIVING";
133
137
  SEPARATE: "SEPARATE";
134
138
  }>;
135
139
  rooms: z.ZodArray<z.ZodObject<{
136
140
  clientId: z.ZodString;
141
+ name: z.ZodOptional<z.ZodString>;
137
142
  roomTypeCode: z.ZodEnum<{
138
143
  LIVING_ROOM: "LIVING_ROOM";
139
144
  BEDROOM: "BEDROOM";
@@ -332,7 +337,6 @@ export declare const RuleSampleSchema: z.ZodObject<{
332
337
  totalAreaSqm: z.ZodNumber;
333
338
  balconyAreaSqm: z.ZodNumber;
334
339
  balconyTiles: z.ZodBoolean;
335
- gas: z.ZodBoolean;
336
340
  kitchenType: z.ZodEnum<{
337
341
  KITCHEN_LIVING: "KITCHEN_LIVING";
338
342
  SEPARATE: "SEPARATE";
@@ -465,6 +469,9 @@ export declare const PricingPackageItemSchema: z.ZodObject<{
465
469
  export type PricingPackageItem = z.infer<typeof PricingPackageItemSchema>;
466
470
  export declare const PricingOptionSchema: z.ZodObject<{
467
471
  id: z.ZodString;
472
+ code: z.ZodNullable<z.ZodEnum<{
473
+ HEATED_FLOOR: "HEATED_FLOOR";
474
+ }>>;
468
475
  kind: z.ZodEnum<{
469
476
  ENGINEERING: "ENGINEERING";
470
477
  ADDITIONAL: "ADDITIONAL";
@@ -582,6 +589,9 @@ export declare const PricingDataSchema: z.ZodObject<{
582
589
  }, z.core.$strip>>;
583
590
  options: z.ZodArray<z.ZodObject<{
584
591
  id: z.ZodString;
592
+ code: z.ZodNullable<z.ZodEnum<{
593
+ HEATED_FLOOR: "HEATED_FLOOR";
594
+ }>>;
585
595
  kind: z.ZodEnum<{
586
596
  ENGINEERING: "ENGINEERING";
587
597
  ADDITIONAL: "ADDITIONAL";
@@ -761,7 +771,6 @@ export interface ObjectVariables {
761
771
  readonly totalArea: number;
762
772
  readonly balconyArea: number;
763
773
  readonly balconyTiles: boolean;
764
- readonly gas: boolean;
765
774
  readonly kitchenType: KitchenType;
766
775
  readonly finishLevel: FinishLevel;
767
776
  readonly roomsCount: number;
package/dist/index.d.ts CHANGED
@@ -46,6 +46,10 @@ export declare const OptionKindSchema: z.ZodEnum<{
46
46
  ADDITIONAL: "ADDITIONAL";
47
47
  }>;
48
48
  export type OptionKind = z.infer<typeof OptionKindSchema>;
49
+ export declare const OptionCodeSchema: z.ZodEnum<{
50
+ HEATED_FLOOR: "HEATED_FLOOR";
51
+ }>;
52
+ export type OptionCode = z.infer<typeof OptionCodeSchema>;
49
53
  export declare const RoomTypeCodeSchema: z.ZodEnum<{
50
54
  LIVING_ROOM: "LIVING_ROOM";
51
55
  BEDROOM: "BEDROOM";
@@ -96,6 +100,7 @@ export declare const RoomSelectionSchema: z.ZodObject<{
96
100
  export type RoomSelection = z.infer<typeof RoomSelectionSchema>;
97
101
  export declare const RoomConfigurationSchema: z.ZodObject<{
98
102
  clientId: z.ZodString;
103
+ name: z.ZodOptional<z.ZodString>;
99
104
  roomTypeCode: z.ZodEnum<{
100
105
  LIVING_ROOM: "LIVING_ROOM";
101
106
  BEDROOM: "BEDROOM";
@@ -127,13 +132,13 @@ export declare const ConfigurationSchema: z.ZodObject<{
127
132
  totalAreaSqm: z.ZodNumber;
128
133
  balconyAreaSqm: z.ZodNumber;
129
134
  balconyTiles: z.ZodBoolean;
130
- gas: z.ZodBoolean;
131
135
  kitchenType: z.ZodEnum<{
132
136
  KITCHEN_LIVING: "KITCHEN_LIVING";
133
137
  SEPARATE: "SEPARATE";
134
138
  }>;
135
139
  rooms: z.ZodArray<z.ZodObject<{
136
140
  clientId: z.ZodString;
141
+ name: z.ZodOptional<z.ZodString>;
137
142
  roomTypeCode: z.ZodEnum<{
138
143
  LIVING_ROOM: "LIVING_ROOM";
139
144
  BEDROOM: "BEDROOM";
@@ -332,7 +337,6 @@ export declare const RuleSampleSchema: z.ZodObject<{
332
337
  totalAreaSqm: z.ZodNumber;
333
338
  balconyAreaSqm: z.ZodNumber;
334
339
  balconyTiles: z.ZodBoolean;
335
- gas: z.ZodBoolean;
336
340
  kitchenType: z.ZodEnum<{
337
341
  KITCHEN_LIVING: "KITCHEN_LIVING";
338
342
  SEPARATE: "SEPARATE";
@@ -465,6 +469,9 @@ export declare const PricingPackageItemSchema: z.ZodObject<{
465
469
  export type PricingPackageItem = z.infer<typeof PricingPackageItemSchema>;
466
470
  export declare const PricingOptionSchema: z.ZodObject<{
467
471
  id: z.ZodString;
472
+ code: z.ZodNullable<z.ZodEnum<{
473
+ HEATED_FLOOR: "HEATED_FLOOR";
474
+ }>>;
468
475
  kind: z.ZodEnum<{
469
476
  ENGINEERING: "ENGINEERING";
470
477
  ADDITIONAL: "ADDITIONAL";
@@ -582,6 +589,9 @@ export declare const PricingDataSchema: z.ZodObject<{
582
589
  }, z.core.$strip>>;
583
590
  options: z.ZodArray<z.ZodObject<{
584
591
  id: z.ZodString;
592
+ code: z.ZodNullable<z.ZodEnum<{
593
+ HEATED_FLOOR: "HEATED_FLOOR";
594
+ }>>;
585
595
  kind: z.ZodEnum<{
586
596
  ENGINEERING: "ENGINEERING";
587
597
  ADDITIONAL: "ADDITIONAL";
@@ -761,7 +771,6 @@ export interface ObjectVariables {
761
771
  readonly totalArea: number;
762
772
  readonly balconyArea: number;
763
773
  readonly balconyTiles: boolean;
764
- readonly gas: boolean;
765
774
  readonly kitchenType: KitchenType;
766
775
  readonly finishLevel: FinishLevel;
767
776
  readonly roomsCount: number;
package/dist/index.js CHANGED
@@ -93,7 +93,7 @@ function optionLine(configuration, option, selection) {
93
93
  params: { optionId: option.id }
94
94
  });
95
95
  const selected = configuration.rooms.filter((room) => selection.roomClientIds?.includes(room.clientId));
96
- const allowed = selected.filter((room) => option.roomTypeCodes.includes(room.roomTypeCode));
96
+ const allowed = option.roomTypeCodes.length === 0 ? selected : selected.filter((room) => option.roomTypeCodes.includes(room.roomTypeCode));
97
97
  const rejected = selected.filter((room) => !allowed.includes(room));
98
98
  const quantity = unitQuantity(option.unit, allowed, selection.quantity ?? option.minQuantity ?? 1);
99
99
  return pricedLine({
@@ -183,7 +183,6 @@ function objectVariables(configuration) {
183
183
  totalArea: configuration.totalAreaSqm,
184
184
  balconyArea: configuration.balconyAreaSqm,
185
185
  balconyTiles: configuration.balconyTiles,
186
- gas: configuration.gas,
187
186
  kitchenType: configuration.kitchenType,
188
187
  finishLevel: configuration.finishLevel,
189
188
  roomsCount: configuration.rooms.filter((room) => COUNTED_AS_ROOMS.includes(room.roomTypeCode)).length,
@@ -766,6 +765,7 @@ const OptionUnitSchema = z.enum([
766
765
  "PROJECT"
767
766
  ]);
768
767
  const OptionKindSchema = z.enum(["ENGINEERING", "ADDITIONAL"]);
768
+ const OptionCodeSchema = z.enum(["HEATED_FLOOR"]);
769
769
  const RoomTypeCodeSchema = z.enum([
770
770
  "LIVING_ROOM",
771
771
  "BEDROOM",
@@ -802,6 +802,7 @@ const RoomSelectionSchema = z.object({
802
802
  });
803
803
  const RoomConfigurationSchema = z.object({
804
804
  clientId: z.string(),
805
+ name: z.string().trim().min(1).max(60).optional(),
805
806
  roomTypeCode: RoomTypeCodeSchema,
806
807
  lengthM: z.number().positive(),
807
808
  widthM: z.number().positive(),
@@ -828,7 +829,6 @@ const ConfigurationSchema = z.object({
828
829
  totalAreaSqm: z.number().positive(),
829
830
  balconyAreaSqm: z.number().min(0),
830
831
  balconyTiles: z.boolean(),
831
- gas: z.boolean(),
832
832
  kitchenType: KitchenTypeSchema,
833
833
  rooms: z.array(RoomConfigurationSchema),
834
834
  options: z.array(OptionSelectionSchema),
@@ -919,6 +919,7 @@ const PricingPackageItemSchema = z.object({
919
919
  });
920
920
  const PricingOptionSchema = z.object({
921
921
  id: z.string(),
922
+ code: OptionCodeSchema.nullable(),
922
923
  kind: OptionKindSchema,
923
924
  priceCents: CentsSchema,
924
925
  unit: OptionUnitSchema,
@@ -1003,7 +1004,6 @@ const RuleSampleSchema = z.object({
1003
1004
  totalAreaSqm: z.number().positive(),
1004
1005
  balconyAreaSqm: z.number().min(0),
1005
1006
  balconyTiles: z.boolean(),
1006
- gas: z.boolean(),
1007
1007
  kitchenType: KitchenTypeSchema,
1008
1008
  finishLevel: FinishLevelSchema,
1009
1009
  roomsCount: z.int().min(0),
@@ -1162,7 +1162,6 @@ function objectScope({ object }) {
1162
1162
  totalArea: object.totalAreaSqm,
1163
1163
  balconyArea: object.balconyAreaSqm,
1164
1164
  balconyTiles: object.balconyTiles,
1165
- gas: object.gas,
1166
1165
  kitchenType: object.kitchenType,
1167
1166
  finishLevel: object.finishLevel,
1168
1167
  roomsCount: object.roomsCount,
@@ -1291,7 +1290,6 @@ const FORMULA_SCOPE_VARIABLES = {
1291
1290
  number("totalArea"),
1292
1291
  number("balconyArea"),
1293
1292
  boolean("balconyTiles"),
1294
- boolean("gas"),
1295
1293
  enumeration("kitchenType", KitchenTypeSchema.options),
1296
1294
  enumeration("finishLevel", FinishLevelSchema.options),
1297
1295
  number("roomsCount"),
@@ -1524,4 +1522,4 @@ function validateFormula(input) {
1524
1522
  };
1525
1523
  }
1526
1524
  //#endregion
1527
- export { BaseRateSchema, COEFFICIENT_NAMESPACE, CentsSchema, ConfigurationSchema, CurrencySchema, EstimateLineSchema, EstimateMessageSchema, EstimateSchema, EstimateTotalsSchema, EstimateWarningSchema, ExchangeRateSchema, FORMULA_FUNCTIONS, FORMULA_FUNCTION_TABLE, FORMULA_LIMITS, FORMULA_QUANTITY_VARIABLE, FORMULA_SCOPE_VARIABLES, FORMULA_VARIABLES, FinishLevelSchema, KitchenTypeSchema, LineStatusSchema, LocalizedTextSchema, OptionKindSchema, OptionSelectionSchema, OptionUnitSchema, PricingCategorySchema, PricingDataSchema, PricingLimitsSchema, PricingMaterialTypeSchema, PricingOptionSchema, PricingPackageItemSchema, PricingProductSchema, PricingRoomTypeSchema, PricingRuleSchema, ProductUnitSchema, RangeSchema, RateSourceSchema, RoomConfigurationSchema, RoomSelectionSchema, RoomTypeCodeSchema, RuleLevelSchema, RulePreviewSchema, RuleSampleSchema, SectionSchema, SectionTotalSchema, SurfaceKindSchema, checkLimits, convertCentsToKopecks, estimate, evaluate, levenshtein, objectVariables, parse, previewRule, productVariables, productVariablesOf, roomVariables, suggestNearest, toCents, validateFormula };
1525
+ export { BaseRateSchema, COEFFICIENT_NAMESPACE, CentsSchema, ConfigurationSchema, CurrencySchema, EstimateLineSchema, EstimateMessageSchema, EstimateSchema, EstimateTotalsSchema, EstimateWarningSchema, ExchangeRateSchema, FORMULA_FUNCTIONS, FORMULA_FUNCTION_TABLE, FORMULA_LIMITS, FORMULA_QUANTITY_VARIABLE, FORMULA_SCOPE_VARIABLES, FORMULA_VARIABLES, FinishLevelSchema, KitchenTypeSchema, LineStatusSchema, LocalizedTextSchema, OptionCodeSchema, OptionKindSchema, OptionSelectionSchema, OptionUnitSchema, PricingCategorySchema, PricingDataSchema, PricingLimitsSchema, PricingMaterialTypeSchema, PricingOptionSchema, PricingPackageItemSchema, PricingProductSchema, PricingRoomTypeSchema, PricingRuleSchema, ProductUnitSchema, RangeSchema, RateSourceSchema, RoomConfigurationSchema, RoomSelectionSchema, RoomTypeCodeSchema, RuleLevelSchema, RulePreviewSchema, RuleSampleSchema, SectionSchema, SectionTotalSchema, SurfaceKindSchema, checkLimits, convertCentsToKopecks, estimate, evaluate, levenshtein, objectVariables, parse, previewRule, productVariables, productVariablesOf, roomVariables, suggestNearest, toCents, validateFormula };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roomwise/calc-engine",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -50,6 +50,6 @@
50
50
  "tsdown": "^0.23.0",
51
51
  "typescript": "^5.9.3",
52
52
  "vitest": "^4.1.11",
53
- "zod": "4.6.5"
53
+ "zod": "4.6.6"
54
54
  }
55
55
  }