@balena/open-balena-api 38.0.0-build-Limit-size-ofl-arge-fields-3a101838568f7ce669c484581668e2e59fbeb045-1 → 38.0.0-build-enum-fields-8071a198139c7245f548c1508e292bf48bae450b-2

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.
@@ -1,37 +0,0 @@
1
- // TODO: We should cleanup the data and delete this file.
2
- import { hooks, errors as pinejsErrors } from '@balena/pinejs';
3
- import { odataNameToSqlName } from '@balena/odata-to-abstract-sql';
4
- const { BadRequestError } = pinejsErrors;
5
- const vowels = ['a', 'e', 'i', 'o', 'u'];
6
- /**
7
- * This is a HACH and should only be used when pre-existing data blocks us from adding the respective Necessity directly in the sbvr.
8
- */
9
- export function addHooksForFieldSizeLimitChecks(model, resource, fieldSizeLimits) {
10
- const fieldSizeLimitEntries = Object.entries(fieldSizeLimits);
11
- const hook = {
12
- POSTPARSE: ({ request }) => {
13
- for (const [field, limits] of fieldSizeLimitEntries) {
14
- const value = request.values[field];
15
- if (typeof value !== 'string') {
16
- continue;
17
- }
18
- const [min, max] = Array.isArray(limits) ? limits : [null, limits];
19
- if (value.length > max || (min != null && value.length <= min)) {
20
- const [term, verb = 'has'] = odataNameToSqlName(field)
21
- .split('-')
22
- .reverse();
23
- // hacky way to decide whether to use "a" or "an"
24
- // should improve one we find cases that this isn't returning the correct results.
25
- const aOrAn = vowels.includes(term[0]) ? 'an' : 'a';
26
- const factType = `${verb} ${aOrAn} ${term}`;
27
- const isGreaterThanAnd = min != null ? `is greater than ${min} and ` : '';
28
- throw new BadRequestError(`It is necessary that each ${odataNameToSqlName(resource)} that ${factType}, ${factType} that has a Length (Type) that ${isGreaterThanAnd}is less than or equal to ${max}.`);
29
- }
30
- }
31
- },
32
- };
33
- for (const method of ['POST', 'PATCH', 'PUT']) {
34
- hooks.addPureHook(method, model, resource, hook);
35
- }
36
- }
37
- //# sourceMappingURL=setup-field-size-limits.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup-field-size-limits.js","sourceRoot":"","sources":["../../../src/features/field-size-limits/setup-field-size-limits.ts"],"names":[],"mappings":"AAAA,yDAAyD;AAGzD,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,MAAM,EAAE,eAAe,EAAE,GAAG,YAAY,CAAC;AAEzC,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAEzC;;GAEG;AACH,MAAM,UAAU,+BAA+B,CAC9C,KAAa,EACb,QAAgB,EAChB,eAAkE;IAElE,MAAM,qBAAqB,GAAG,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAC9D,MAAM,IAAI,GAAoB;QAC7B,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;YAC1B,KAAK,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,qBAAqB,EAAE,CAAC;gBACrD,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACpC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;oBAC/B,SAAS;gBACV,CAAC;gBACD,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;gBACnE,IAAI,KAAK,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC,EAAE,CAAC;oBAChE,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,KAAK,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC;yBACpD,KAAK,CAAC,GAAG,C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