@ecogood/e-calculator-schemas 2.2.1 → 2.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.
@@ -30,7 +30,7 @@ export declare const BalanceSheetCreateRequestBodySchema: z.ZodObject<{
30
30
  industryCode?: string | undefined;
31
31
  costs?: number | undefined;
32
32
  }>, "many">>;
33
- employeesFractions: z.ZodDefault<z.ZodArray<z.ZodObject<{
33
+ employeesFractions: z.ZodDefault<z.ZodEffects<z.ZodArray<z.ZodObject<{
34
34
  countryCode: z.ZodOptional<z.ZodString>;
35
35
  percentage: z.ZodNumber;
36
36
  }, "strip", z.ZodTypeAny, {
@@ -39,8 +39,14 @@ export declare const BalanceSheetCreateRequestBodySchema: z.ZodObject<{
39
39
  }, {
40
40
  percentage: number;
41
41
  countryCode?: string | undefined;
42
- }>, "many">>;
43
- industrySectors: z.ZodDefault<z.ZodArray<z.ZodObject<{
42
+ }>, "many">, {
43
+ percentage: number;
44
+ countryCode?: string | undefined;
45
+ }[], {
46
+ percentage: number;
47
+ countryCode?: string | undefined;
48
+ }[]>>;
49
+ industrySectors: z.ZodDefault<z.ZodEffects<z.ZodArray<z.ZodObject<{
44
50
  industryCode: z.ZodOptional<z.ZodString>;
45
51
  amountOfTotalTurnover: z.ZodNumber;
46
52
  description: z.ZodDefault<z.ZodString>;
@@ -52,7 +58,15 @@ export declare const BalanceSheetCreateRequestBodySchema: z.ZodObject<{
52
58
  amountOfTotalTurnover: number;
53
59
  description?: string | undefined;
54
60
  industryCode?: string | undefined;
55
- }>, "many">>;
61
+ }>, "many">, {
62
+ description: string;
63
+ amountOfTotalTurnover: number;
64
+ industryCode?: string | undefined;
65
+ }[], {
66
+ amountOfTotalTurnover: number;
67
+ description?: string | undefined;
68
+ industryCode?: string | undefined;
69
+ }[]>>;
56
70
  mainOriginOfOtherSuppliers: z.ZodOptional<z.ZodString>;
57
71
  }, "strip", z.ZodTypeAny, {
58
72
  totalPurchaseFromSuppliers: number;
@@ -249,7 +263,7 @@ export declare const BalanceSheetPatchRequestBodySchema: z.ZodObject<{
249
263
  industryCode?: string | undefined;
250
264
  costs?: number | undefined;
251
265
  }>, "many">>>;
252
- employeesFractions: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
266
+ employeesFractions: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodArray<z.ZodObject<{
253
267
  countryCode: z.ZodOptional<z.ZodString>;
254
268
  percentage: z.ZodNumber;
255
269
  }, "strip", z.ZodTypeAny, {
@@ -258,8 +272,14 @@ export declare const BalanceSheetPatchRequestBodySchema: z.ZodObject<{
258
272
  }, {
259
273
  percentage: number;
260
274
  countryCode?: string | undefined;
261
- }>, "many">>>;
262
- industrySectors: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
275
+ }>, "many">, {
276
+ percentage: number;
277
+ countryCode?: string | undefined;
278
+ }[], {
279
+ percentage: number;
280
+ countryCode?: string | undefined;
281
+ }[]>>>;
282
+ industrySectors: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodArray<z.ZodObject<{
263
283
  industryCode: z.ZodOptional<z.ZodString>;
264
284
  amountOfTotalTurnover: z.ZodNumber;
265
285
  description: z.ZodDefault<z.ZodString>;
@@ -271,7 +291,15 @@ export declare const BalanceSheetPatchRequestBodySchema: z.ZodObject<{
271
291
  amountOfTotalTurnover: number;
272
292
  description?: string | undefined;
273
293
  industryCode?: string | undefined;
274
- }>, "many">>>;
294
+ }>, "many">, {
295
+ description: string;
296
+ amountOfTotalTurnover: number;
297
+ industryCode?: string | undefined;
298
+ }[], {
299
+ amountOfTotalTurnover: number;
300
+ description?: string | undefined;
301
+ industryCode?: string | undefined;
302
+ }[]>>>;
275
303
  mainOriginOfOtherSuppliers: z.ZodOptional<z.ZodOptional<z.ZodString>>;
276
304
  }, "strip", z.ZodTypeAny, {
277
305
  totalPurchaseFromSuppliers?: number | undefined;
@@ -518,7 +546,7 @@ export declare const BalanceSheetResponseBodySchema: z.ZodObject<{
518
546
  industryCode?: string | undefined;
519
547
  costs?: number | undefined;
520
548
  }>, "many">;
521
- employeesFractions: z.ZodArray<z.ZodObject<{
549
+ employeesFractions: z.ZodEffects<z.ZodArray<z.ZodObject<{
522
550
  countryCode: z.ZodOptional<z.ZodString>;
523
551
  percentage: z.ZodNumber;
524
552
  }, "strip", z.ZodTypeAny, {
@@ -527,8 +555,14 @@ export declare const BalanceSheetResponseBodySchema: z.ZodObject<{
527
555
  }, {
528
556
  percentage: number;
529
557
  countryCode?: string | undefined;
530
- }>, "many">;
531
- industrySectors: z.ZodArray<z.ZodObject<{
558
+ }>, "many">, {
559
+ percentage: number;
560
+ countryCode?: string | undefined;
561
+ }[], {
562
+ percentage: number;
563
+ countryCode?: string | undefined;
564
+ }[]>;
565
+ industrySectors: z.ZodEffects<z.ZodArray<z.ZodObject<{
532
566
  industryCode: z.ZodOptional<z.ZodString>;
533
567
  amountOfTotalTurnover: z.ZodNumber;
534
568
  description: z.ZodDefault<z.ZodString>;
@@ -540,7 +574,15 @@ export declare const BalanceSheetResponseBodySchema: z.ZodObject<{
540
574
  amountOfTotalTurnover: number;
541
575
  description?: string | undefined;
542
576
  industryCode?: string | undefined;
543
- }>, "many">;
577
+ }>, "many">, {
578
+ description: string;
579
+ amountOfTotalTurnover: number;
580
+ industryCode?: string | undefined;
581
+ }[], {
582
+ amountOfTotalTurnover: number;
583
+ description?: string | undefined;
584
+ industryCode?: string | undefined;
585
+ }[]>;
544
586
  mainOriginOfOtherSuppliers: z.ZodObject<{
545
587
  countryCode: z.ZodOptional<z.ZodString>;
546
588
  costs: z.ZodNumber;
@@ -1,4 +1,54 @@
1
1
  import { z } from 'zod';
2
+ export declare const SupplyFractionSchema: z.ZodArray<z.ZodObject<{
3
+ countryCode: z.ZodOptional<z.ZodString>;
4
+ industryCode: z.ZodOptional<z.ZodString>;
5
+ costs: z.ZodDefault<z.ZodNumber>;
6
+ }, "strip", z.ZodTypeAny, {
7
+ costs: number;
8
+ countryCode?: string | undefined;
9
+ industryCode?: string | undefined;
10
+ }, {
11
+ countryCode?: string | undefined;
12
+ industryCode?: string | undefined;
13
+ costs?: number | undefined;
14
+ }>, "many">;
15
+ export declare const EmployeesFractionSchema: z.ZodEffects<z.ZodArray<z.ZodObject<{
16
+ countryCode: z.ZodOptional<z.ZodString>;
17
+ percentage: z.ZodNumber;
18
+ }, "strip", z.ZodTypeAny, {
19
+ percentage: number;
20
+ countryCode?: string | undefined;
21
+ }, {
22
+ percentage: number;
23
+ countryCode?: string | undefined;
24
+ }>, "many">, {
25
+ percentage: number;
26
+ countryCode?: string | undefined;
27
+ }[], {
28
+ percentage: number;
29
+ countryCode?: string | undefined;
30
+ }[]>;
31
+ export declare const IndustrySectorSchema: z.ZodEffects<z.ZodArray<z.ZodObject<{
32
+ industryCode: z.ZodOptional<z.ZodString>;
33
+ amountOfTotalTurnover: z.ZodNumber;
34
+ description: z.ZodDefault<z.ZodString>;
35
+ }, "strip", z.ZodTypeAny, {
36
+ description: string;
37
+ amountOfTotalTurnover: number;
38
+ industryCode?: string | undefined;
39
+ }, {
40
+ amountOfTotalTurnover: number;
41
+ description?: string | undefined;
42
+ industryCode?: string | undefined;
43
+ }>, "many">, {
44
+ description: string;
45
+ amountOfTotalTurnover: number;
46
+ industryCode?: string | undefined;
47
+ }[], {
48
+ amountOfTotalTurnover: number;
49
+ description?: string | undefined;
50
+ industryCode?: string | undefined;
51
+ }[]>;
2
52
  export declare const CompanyFactsCreateRequestBodySchema: z.ZodObject<{
3
53
  totalPurchaseFromSuppliers: z.ZodDefault<z.ZodNumber>;
4
54
  totalStaffCosts: z.ZodDefault<z.ZodNumber>;
@@ -26,7 +76,7 @@ export declare const CompanyFactsCreateRequestBodySchema: z.ZodObject<{
26
76
  industryCode?: string | undefined;
27
77
  costs?: number | undefined;
28
78
  }>, "many">>;
29
- employeesFractions: z.ZodDefault<z.ZodArray<z.ZodObject<{
79
+ employeesFractions: z.ZodDefault<z.ZodEffects<z.ZodArray<z.ZodObject<{
30
80
  countryCode: z.ZodOptional<z.ZodString>;
31
81
  percentage: z.ZodNumber;
32
82
  }, "strip", z.ZodTypeAny, {
@@ -35,8 +85,14 @@ export declare const CompanyFactsCreateRequestBodySchema: z.ZodObject<{
35
85
  }, {
36
86
  percentage: number;
37
87
  countryCode?: string | undefined;
38
- }>, "many">>;
39
- industrySectors: z.ZodDefault<z.ZodArray<z.ZodObject<{
88
+ }>, "many">, {
89
+ percentage: number;
90
+ countryCode?: string | undefined;
91
+ }[], {
92
+ percentage: number;
93
+ countryCode?: string | undefined;
94
+ }[]>>;
95
+ industrySectors: z.ZodDefault<z.ZodEffects<z.ZodArray<z.ZodObject<{
40
96
  industryCode: z.ZodOptional<z.ZodString>;
41
97
  amountOfTotalTurnover: z.ZodNumber;
42
98
  description: z.ZodDefault<z.ZodString>;
@@ -48,7 +104,15 @@ export declare const CompanyFactsCreateRequestBodySchema: z.ZodObject<{
48
104
  amountOfTotalTurnover: number;
49
105
  description?: string | undefined;
50
106
  industryCode?: string | undefined;
51
- }>, "many">>;
107
+ }>, "many">, {
108
+ description: string;
109
+ amountOfTotalTurnover: number;
110
+ industryCode?: string | undefined;
111
+ }[], {
112
+ amountOfTotalTurnover: number;
113
+ description?: string | undefined;
114
+ industryCode?: string | undefined;
115
+ }[]>>;
52
116
  mainOriginOfOtherSuppliers: z.ZodOptional<z.ZodString>;
53
117
  }, "strip", z.ZodTypeAny, {
54
118
  totalPurchaseFromSuppliers: number;
@@ -136,7 +200,7 @@ export declare const CompanyFactsPatchRequestBodySchema: z.ZodObject<{
136
200
  industryCode?: string | undefined;
137
201
  costs?: number | undefined;
138
202
  }>, "many">>>;
139
- employeesFractions: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
203
+ employeesFractions: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodArray<z.ZodObject<{
140
204
  countryCode: z.ZodOptional<z.ZodString>;
141
205
  percentage: z.ZodNumber;
142
206
  }, "strip", z.ZodTypeAny, {
@@ -145,8 +209,14 @@ export declare const CompanyFactsPatchRequestBodySchema: z.ZodObject<{
145
209
  }, {
146
210
  percentage: number;
147
211
  countryCode?: string | undefined;
148
- }>, "many">>>;
149
- industrySectors: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodObject<{
212
+ }>, "many">, {
213
+ percentage: number;
214
+ countryCode?: string | undefined;
215
+ }[], {
216
+ percentage: number;
217
+ countryCode?: string | undefined;
218
+ }[]>>>;
219
+ industrySectors: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodArray<z.ZodObject<{
150
220
  industryCode: z.ZodOptional<z.ZodString>;
151
221
  amountOfTotalTurnover: z.ZodNumber;
152
222
  description: z.ZodDefault<z.ZodString>;
@@ -158,7 +228,15 @@ export declare const CompanyFactsPatchRequestBodySchema: z.ZodObject<{
158
228
  amountOfTotalTurnover: number;
159
229
  description?: string | undefined;
160
230
  industryCode?: string | undefined;
161
- }>, "many">>>;
231
+ }>, "many">, {
232
+ description: string;
233
+ amountOfTotalTurnover: number;
234
+ industryCode?: string | undefined;
235
+ }[], {
236
+ amountOfTotalTurnover: number;
237
+ description?: string | undefined;
238
+ industryCode?: string | undefined;
239
+ }[]>>>;
162
240
  mainOriginOfOtherSuppliers: z.ZodOptional<z.ZodOptional<z.ZodString>>;
163
241
  }, "strip", z.ZodTypeAny, {
164
242
  totalPurchaseFromSuppliers?: number | undefined;
@@ -246,7 +324,7 @@ export declare const CompanyFactsResponseBodySchema: z.ZodObject<{
246
324
  industryCode?: string | undefined;
247
325
  costs?: number | undefined;
248
326
  }>, "many">;
249
- employeesFractions: z.ZodArray<z.ZodObject<{
327
+ employeesFractions: z.ZodEffects<z.ZodArray<z.ZodObject<{
250
328
  countryCode: z.ZodOptional<z.ZodString>;
251
329
  percentage: z.ZodNumber;
252
330
  }, "strip", z.ZodTypeAny, {
@@ -255,8 +333,14 @@ export declare const CompanyFactsResponseBodySchema: z.ZodObject<{
255
333
  }, {
256
334
  percentage: number;
257
335
  countryCode?: string | undefined;
258
- }>, "many">;
259
- industrySectors: z.ZodArray<z.ZodObject<{
336
+ }>, "many">, {
337
+ percentage: number;
338
+ countryCode?: string | undefined;
339
+ }[], {
340
+ percentage: number;
341
+ countryCode?: string | undefined;
342
+ }[]>;
343
+ industrySectors: z.ZodEffects<z.ZodArray<z.ZodObject<{
260
344
  industryCode: z.ZodOptional<z.ZodString>;
261
345
  amountOfTotalTurnover: z.ZodNumber;
262
346
  description: z.ZodDefault<z.ZodString>;
@@ -268,7 +352,15 @@ export declare const CompanyFactsResponseBodySchema: z.ZodObject<{
268
352
  amountOfTotalTurnover: number;
269
353
  description?: string | undefined;
270
354
  industryCode?: string | undefined;
271
- }>, "many">;
355
+ }>, "many">, {
356
+ description: string;
357
+ amountOfTotalTurnover: number;
358
+ industryCode?: string | undefined;
359
+ }[], {
360
+ amountOfTotalTurnover: number;
361
+ description?: string | undefined;
362
+ industryCode?: string | undefined;
363
+ }[]>;
272
364
  mainOriginOfOtherSuppliers: z.ZodObject<{
273
365
  countryCode: z.ZodOptional<z.ZodString>;
274
366
  costs: z.ZodNumber;
@@ -1,21 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CompanyFactsResponseBodySchema = exports.CompanyFactsPatchRequestBodySchema = exports.CompanyFactsCreateRequestBodySchema = void 0;
3
+ exports.CompanyFactsResponseBodySchema = exports.CompanyFactsPatchRequestBodySchema = exports.CompanyFactsCreateRequestBodySchema = exports.IndustrySectorSchema = exports.EmployeesFractionSchema = exports.SupplyFractionSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const shared_schemas_1 = require("./shared.schemas");
6
- const SupplyFractionRequestBodySchema = zod_1.z.object({
6
+ function isSumGreaterThan(array, value) {
7
+ // Calculate the sum of the array
8
+ const sum = array.reduce((acc, curr) => acc + curr, 0);
9
+ // Check if the sum is greater than the specified value
10
+ return sum > value;
11
+ }
12
+ const sumOfPercentagesSmallerEqual100Msg = 'The sum of all percentage values should not be greater than 100.';
13
+ exports.SupplyFractionSchema = zod_1.z
14
+ .object({
7
15
  countryCode: shared_schemas_1.isCountryCode.optional(),
8
16
  industryCode: shared_schemas_1.isIndustryCode.optional(),
9
- costs: shared_schemas_1.isPositiveNumber,
10
- });
11
- const EmployeesFractionRequestBodySchema = zod_1.z.object({
17
+ costs: shared_schemas_1.isPositiveNumberNotZero,
18
+ })
19
+ .array();
20
+ exports.EmployeesFractionSchema = zod_1.z
21
+ .object({
12
22
  countryCode: shared_schemas_1.isCountryCode.optional(),
13
23
  percentage: shared_schemas_1.isPercentage,
24
+ })
25
+ .array()
26
+ .refine((efs) => !isSumGreaterThan(efs.map((ef) => ef.percentage), 100), {
27
+ message: sumOfPercentagesSmallerEqual100Msg,
14
28
  });
15
- const IndustrySectorRequestBodySchema = zod_1.z.object({
29
+ exports.IndustrySectorSchema = zod_1.z
30
+ .object({
16
31
  industryCode: shared_schemas_1.isIndustryCode.optional(),
17
32
  amountOfTotalTurnover: shared_schemas_1.isPercentage,
18
33
  description: zod_1.z.string().default(''),
34
+ })
35
+ .array()
36
+ .refine((is) => !isSumGreaterThan(is.map((is) => is.amountOfTotalTurnover), 100), {
37
+ message: sumOfPercentagesSmallerEqual100Msg,
19
38
  });
20
39
  const CompanyFactsRequestBodySchema = zod_1.z.object({
21
40
  totalPurchaseFromSuppliers: shared_schemas_1.isPositiveNumber,
@@ -31,9 +50,9 @@ const CompanyFactsRequestBodySchema = zod_1.z.object({
31
50
  hasCanteen: zod_1.z.oboolean(),
32
51
  averageJourneyToWorkForStaffInKm: shared_schemas_1.isPositiveNumber,
33
52
  isB2B: zod_1.z.boolean().default(false),
34
- supplyFractions: SupplyFractionRequestBodySchema.array().default([]),
35
- employeesFractions: EmployeesFractionRequestBodySchema.array().default([]),
36
- industrySectors: IndustrySectorRequestBodySchema.array().default([]),
53
+ supplyFractions: exports.SupplyFractionSchema.default([]),
54
+ employeesFractions: exports.EmployeesFractionSchema.default([]),
55
+ industrySectors: exports.IndustrySectorSchema.default([]),
37
56
  mainOriginOfOtherSuppliers: shared_schemas_1.isCountryCode.optional(),
38
57
  });
39
58
  exports.CompanyFactsCreateRequestBodySchema = CompanyFactsRequestBodySchema;
@@ -52,9 +71,9 @@ exports.CompanyFactsResponseBodySchema = zod_1.z.object({
52
71
  hasCanteen: zod_1.z.oboolean(),
53
72
  averageJourneyToWorkForStaffInKm: shared_schemas_1.isPositiveNumber,
54
73
  isB2B: zod_1.z.boolean(),
55
- supplyFractions: SupplyFractionRequestBodySchema.array(),
56
- employeesFractions: EmployeesFractionRequestBodySchema.array(),
57
- industrySectors: IndustrySectorRequestBodySchema.array(),
74
+ supplyFractions: exports.SupplyFractionSchema,
75
+ employeesFractions: exports.EmployeesFractionSchema,
76
+ industrySectors: exports.IndustrySectorSchema,
58
77
  mainOriginOfOtherSuppliers: zod_1.z.object({
59
78
  countryCode: shared_schemas_1.isCountryCode.optional(),
60
79
  costs: zod_1.z.number(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecogood/e-calculator-schemas",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "description": "A package providing the schemas for the e-calculator application.",
5
5
  "main": "dist/e-calculator-schemas",
6
6
  "types": "dist/e-calculator-schemas",