@raytio/core 10.1.0 → 11.1.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.
Files changed (208) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +198 -59
  3. package/dist/{util/hash.d.ts → __tests__/docs.test.d.ts} +1 -1
  4. package/dist/__tests__/docs.test.js +24 -0
  5. package/dist/accessApplication/createAA.d.ts +17 -17
  6. package/dist/accessApplication/createAA.js +71 -71
  7. package/dist/accessApplication/index.d.ts +1 -1
  8. package/dist/accessApplication/index.js +17 -17
  9. package/dist/crypto/cognitoAttributes.d.ts +15 -15
  10. package/dist/crypto/cognitoAttributes.js +33 -33
  11. package/dist/crypto/decryptKeys.d.ts +1 -1
  12. package/dist/crypto/decryptKeys.js +33 -33
  13. package/dist/crypto/decryptSharedData.d.ts +26 -26
  14. package/dist/crypto/decryptSharedData.js +38 -38
  15. package/dist/crypto/getAADecryptor.d.ts +16 -16
  16. package/dist/crypto/getAADecryptor.js +20 -20
  17. package/dist/crypto/helpers.d.ts +18 -18
  18. package/dist/crypto/helpers.js +26 -26
  19. package/dist/crypto/index.d.ts +4 -4
  20. package/dist/crypto/index.js +21 -21
  21. package/dist/general/conditional.d.ts +17 -17
  22. package/dist/general/conditional.js +32 -32
  23. package/dist/general/date.d.ts +2 -2
  24. package/dist/general/date.js +18 -18
  25. package/dist/general/index.d.ts +4 -4
  26. package/dist/general/index.js +20 -20
  27. package/dist/general/password.d.ts +10 -10
  28. package/dist/general/password.js +31 -31
  29. package/dist/general/types.d.ts +6 -6
  30. package/dist/general/types.js +13 -13
  31. package/dist/index.d.ts +6 -6
  32. package/dist/index.js +22 -22
  33. package/dist/rules/calculateScore.d.ts +28 -23
  34. package/dist/rules/calculateScore.js +82 -76
  35. package/dist/rules/convertInstanceToRuleInput.d.ts +3 -3
  36. package/dist/rules/convertInstanceToRuleInput.js +138 -139
  37. package/dist/rules/evaluateScoreCondition.d.ts +2 -2
  38. package/dist/rules/evaluateScoreCondition.js +44 -45
  39. package/dist/{verifications/checkVerifications.d.ts → rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.d.ts} +1 -1
  40. package/dist/rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.js +27 -0
  41. package/dist/{verifications/checkVerificationsNew.d.ts → rules/helpers/__tests__/checkTypeofValue.test.d.ts} +1 -1
  42. package/dist/rules/helpers/__tests__/checkTypeofValue.test.js +49 -0
  43. package/dist/{verifications/verifyCheck/util/canonicalJsonify.d.ts → rules/helpers/__tests__/getValuesFromPath.test.d.ts} +1 -1
  44. package/dist/rules/helpers/__tests__/getValuesFromPath.test.js +67 -0
  45. package/dist/rules/helpers/__tests__/thresholds.test.d.ts +1 -0
  46. package/dist/rules/helpers/__tests__/thresholds.test.js +32 -0
  47. package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +8 -8
  48. package/dist/rules/helpers/addInfiniteThresholdBoundaries.js +11 -11
  49. package/dist/rules/helpers/checkTypeofValue.d.ts +9 -9
  50. package/dist/rules/helpers/checkTypeofValue.js +60 -55
  51. package/dist/rules/helpers/getValuesFromPath.d.ts +3 -3
  52. package/dist/rules/helpers/getValuesFromPath.js +50 -50
  53. package/dist/rules/helpers/index.d.ts +5 -5
  54. package/dist/rules/helpers/index.js +21 -21
  55. package/dist/rules/helpers/symbols.d.ts +2 -2
  56. package/dist/rules/helpers/symbols.js +5 -5
  57. package/dist/rules/helpers/thresholds.d.ts +5 -5
  58. package/dist/rules/helpers/thresholds.js +46 -47
  59. package/dist/rules/index.d.ts +7 -7
  60. package/dist/rules/index.js +25 -25
  61. package/dist/rules/operators/__tests__/bool.test.d.ts +1 -0
  62. package/dist/rules/operators/__tests__/bool.test.js +21 -0
  63. package/dist/rules/operators/__tests__/date.test.d.ts +1 -0
  64. package/dist/rules/operators/__tests__/date.test.js +81 -0
  65. package/dist/rules/operators/__tests__/hfield.test.d.ts +1 -0
  66. package/dist/rules/operators/__tests__/hfield.test.js +38 -0
  67. package/dist/rules/operators/__tests__/hschema.test.d.ts +1 -0
  68. package/dist/rules/operators/__tests__/hschema.test.js +24 -0
  69. package/dist/rules/operators/__tests__/number.test.d.ts +1 -0
  70. package/dist/rules/operators/__tests__/number.test.js +53 -0
  71. package/dist/rules/operators/__tests__/string.test.d.ts +1 -0
  72. package/dist/rules/operators/__tests__/string.test.js +74 -0
  73. package/dist/rules/operators/bool.d.ts +2 -2
  74. package/dist/rules/operators/bool.js +17 -17
  75. package/dist/rules/operators/date.d.ts +2 -2
  76. package/dist/rules/operators/date.js +91 -91
  77. package/dist/rules/operators/hfield.d.ts +2 -2
  78. package/dist/rules/operators/hfield.js +33 -33
  79. package/dist/rules/operators/hschema.d.ts +2 -2
  80. package/dist/rules/operators/hschema.js +21 -21
  81. package/dist/rules/operators/index.d.ts +3 -3
  82. package/dist/rules/operators/index.js +11 -11
  83. package/dist/rules/operators/number.d.ts +2 -2
  84. package/dist/rules/operators/number.js +41 -41
  85. package/dist/rules/operators/string.d.ts +2 -2
  86. package/dist/rules/operators/string.js +58 -58
  87. package/dist/rules/types/config.d.ts +95 -91
  88. package/dist/rules/types/config.js +2 -2
  89. package/dist/rules/types/dataValueTypes.d.ts +19 -19
  90. package/dist/rules/types/dataValueTypes.js +4 -4
  91. package/dist/rules/types/index.d.ts +3 -3
  92. package/dist/rules/types/index.js +19 -19
  93. package/dist/rules/types/internal.d.ts +20 -20
  94. package/dist/rules/types/internal.js +2 -2
  95. package/dist/rules/validate.d.ts +6 -6
  96. package/dist/rules/validate.js +14 -14
  97. package/dist/rules/version.d.ts +1 -1
  98. package/dist/rules/version.js +5 -5
  99. package/dist/schema/expandSchema/__tests__/addLoadingTimes.test.d.ts +1 -0
  100. package/dist/schema/expandSchema/__tests__/addLoadingTimes.test.js +24 -0
  101. package/dist/schema/expandSchema/__tests__/expandSchema.test.d.ts +1 -0
  102. package/dist/schema/expandSchema/__tests__/expandSchema.test.js +95 -0
  103. package/dist/schema/expandSchema/__tests__/i18n.test.d.ts +1 -0
  104. package/dist/schema/expandSchema/__tests__/i18n.test.js +32 -0
  105. package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.d.ts +1 -0
  106. package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.js +98 -0
  107. package/dist/schema/expandSchema/__tests__/processSchema.test.d.ts +1 -0
  108. package/dist/schema/expandSchema/__tests__/processSchema.test.js +326 -0
  109. package/dist/schema/expandSchema/__tests__/sortSchemaProperties.test.d.ts +1 -0
  110. package/dist/schema/expandSchema/__tests__/sortSchemaProperties.test.js +182 -0
  111. package/dist/schema/expandSchema/__tests__/util.test.d.ts +1 -0
  112. package/dist/schema/expandSchema/__tests__/util.test.js +19 -0
  113. package/dist/schema/expandSchema/addLoadingTimes.d.ts +2 -0
  114. package/dist/schema/expandSchema/addLoadingTimes.js +12 -0
  115. package/dist/schema/expandSchema/constants.d.ts +2 -0
  116. package/dist/schema/expandSchema/constants.js +11 -0
  117. package/dist/schema/expandSchema/expandSchema.d.ts +7 -0
  118. package/dist/schema/expandSchema/expandSchema.js +19 -0
  119. package/dist/schema/expandSchema/i18n.d.ts +5 -0
  120. package/dist/schema/expandSchema/i18n.js +20 -0
  121. package/dist/schema/expandSchema/index.d.ts +3 -0
  122. package/dist/schema/expandSchema/index.js +21 -0
  123. package/dist/schema/expandSchema/maybeUseI18n.d.ts +2 -0
  124. package/dist/schema/expandSchema/maybeUseI18n.js +40 -0
  125. package/dist/schema/expandSchema/processSchema.d.ts +4 -0
  126. package/dist/schema/expandSchema/processSchema.js +94 -0
  127. package/dist/schema/expandSchema/removePrivateFields.d.ts +119 -0
  128. package/dist/schema/expandSchema/removePrivateFields.js +15 -0
  129. package/dist/schema/expandSchema/sortSchemaProperties.d.ts +21 -0
  130. package/dist/schema/expandSchema/sortSchemaProperties.js +40 -0
  131. package/dist/schema/expandSchema/unwrapSchema.d.ts +6 -0
  132. package/dist/schema/expandSchema/unwrapSchema.js +7 -0
  133. package/dist/schema/expandSchema/util.d.ts +6 -0
  134. package/dist/schema/expandSchema/util.js +15 -0
  135. package/dist/schema/index.d.ts +2 -1
  136. package/dist/schema/index.js +18 -17
  137. package/dist/schema/labels.d.ts +2 -2
  138. package/dist/schema/labels.js +20 -20
  139. package/dist/util/canonicalJsonify.d.ts +1 -1
  140. package/dist/util/canonicalJsonify.js +50 -50
  141. package/dist/util/handleResponse.d.ts +1 -1
  142. package/dist/util/handleResponse.js +21 -21
  143. package/dist/util/index.d.ts +2 -2
  144. package/dist/util/index.js +18 -18
  145. package/dist/verifications/cleanInstance.d.ts +9 -9
  146. package/dist/verifications/cleanInstance.js +15 -15
  147. package/dist/verifications/getPOVerification.d.ts +19 -16
  148. package/dist/verifications/getPOVerification.js +105 -94
  149. package/dist/verifications/getVerifiedBy.d.ts +1 -1
  150. package/dist/verifications/getVerifiedBy.js +19 -19
  151. package/dist/verifications/index.d.ts +5 -5
  152. package/dist/verifications/index.js +21 -21
  153. package/dist/verifications/maybeRereference.d.ts +1 -1
  154. package/dist/verifications/maybeRereference.js +10 -10
  155. package/dist/verifications/safeHarbour.d.ts +20 -20
  156. package/dist/verifications/safeHarbour.js +67 -74
  157. package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.d.ts +1 -0
  158. package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.js +152 -0
  159. package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.d.ts +1 -0
  160. package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.js +205 -0
  161. package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -13
  162. package/dist/verifications/verifyCheck/getOwnRealVerifications.js +66 -64
  163. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +19 -19
  164. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +72 -72
  165. package/dist/verifications/verifyCheck/index.d.ts +3 -3
  166. package/dist/verifications/verifyCheck/index.js +21 -21
  167. package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.d.ts +1 -0
  168. package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.js +91 -0
  169. package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.d.ts +1 -0
  170. package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.js +49 -0
  171. package/dist/verifications/verifyCheck/operations/__tests__/sampleBundle.json +43 -0
  172. package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +15 -15
  173. package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +39 -39
  174. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -1
  175. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.js +16 -16
  176. package/dist/verifications/verifyCheck/operations/index.d.ts +2 -2
  177. package/dist/verifications/verifyCheck/operations/index.js +18 -18
  178. package/package.json +13 -10
  179. package/dist/rules/helpers/getLhsTypeofValue.d.ts +0 -0
  180. package/dist/rules/helpers/getLhsTypeofValue.js +0 -1
  181. package/dist/rules/helpers/getValueFromPath.d.ts +0 -2
  182. package/dist/rules/helpers/getValueFromPath.js +0 -35
  183. package/dist/rules/helpers/rebuildInfiniteValues.d.ts +0 -3
  184. package/dist/rules/helpers/rebuildInfiniteValues.js +0 -6
  185. package/dist/rules/isScoreResultValid.d.ts +0 -2
  186. package/dist/rules/isScoreResultValid.js +0 -9
  187. package/dist/rules/operators/array.d.ts +0 -2
  188. package/dist/rules/operators/array.js +0 -74
  189. package/dist/rules/types/operators.d.ts +0 -19
  190. package/dist/rules/types/operators.js +0 -2
  191. package/dist/rules/types/score.d.ts +0 -50
  192. package/dist/rules/types/score.js +0 -2
  193. package/dist/util/conditional.d.ts +0 -7
  194. package/dist/util/conditional.js +0 -15
  195. package/dist/util/hash.js +0 -11
  196. package/dist/verifications/checkSingleVerification.d.ts +0 -9
  197. package/dist/verifications/checkSingleVerification.js +0 -29
  198. package/dist/verifications/checkVerifications.js +0 -16
  199. package/dist/verifications/checkVerificationsNew.js +0 -16
  200. package/dist/verifications/getOwnRealVerifications.d.ts +0 -14
  201. package/dist/verifications/getOwnRealVerifications.js +0 -64
  202. package/dist/verifications/getRealVerifications.d.ts +0 -22
  203. package/dist/verifications/getRealVerifications.js +0 -71
  204. package/dist/verifications/verifyCheck/util/canonicalJsonify.js +0 -48
  205. package/dist/verifications/verifyCheck/util/getValuesForAField.d.ts +0 -2
  206. package/dist/verifications/verifyCheck/util/getValuesForAField.js +0 -9
  207. package/dist/verifications/verifyCheck/util/index.d.ts +0 -2
  208. package/dist/verifications/verifyCheck/util/index.js +0 -14
@@ -1,19 +1,19 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./dataValueTypes"), exports);
18
- __exportStar(require("./config"), exports);
19
- __exportStar(require("./internal"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./dataValueTypes"), exports);
18
+ __exportStar(require("./config"), exports);
19
+ __exportStar(require("./internal"), exports);
@@ -1,20 +1,20 @@
1
- import { HField, HSchema, GetTSType } from "./dataValueTypes";
2
- import { FieldValueTypes, ValueType } from "./config";
3
- export declare type RuleDataProperty<T extends FieldValueTypes> = {
4
- type: T;
5
- value: GetTSType<T>;
6
- hField: HField;
7
- };
8
- export declare type RuleData = {
9
- [schemaName: string]: {
10
- hSchema: HSchema;
11
- properties: {
12
- [fieldName: string]: RuleDataProperty<FieldValueTypes>;
13
- };
14
- }[];
15
- };
16
- export declare type OperatorDef = {
17
- /** the first operand is the LHS, all others are RHS */
18
- operands: ValueType[];
19
- implementation: (...args: any[]) => boolean;
20
- };
1
+ import { HField, HSchema, GetTSType } from "./dataValueTypes";
2
+ import { FieldValueTypes, ValueType } from "./config";
3
+ export type RuleDataProperty<T extends FieldValueTypes> = {
4
+ type: T;
5
+ value: GetTSType<T>;
6
+ hField: HField;
7
+ };
8
+ export type RuleData = {
9
+ [schemaName: string]: {
10
+ hSchema: HSchema;
11
+ properties: {
12
+ [fieldName: string]: RuleDataProperty<FieldValueTypes>;
13
+ };
14
+ }[];
15
+ };
16
+ export type OperatorDef = {
17
+ /** the first operand is the LHS, all others are RHS */
18
+ operands: ValueType[];
19
+ implementation: (...args: any[]) => boolean;
20
+ };
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,6 @@
1
- import { ScoreResult } from "./calculateScore";
2
- import { ScoreConfig } from "./types";
3
- /** determines whether a `ScoreResult` object is valid */
4
- export declare const isScoreResultValid: (x: unknown) => x is ScoreResult;
5
- /** determines whether a `ScoreConfig` object is valid */
6
- export declare const isScoreConfigValid: (x: unknown) => x is ScoreConfig;
1
+ import { ScoreResult } from "./calculateScore";
2
+ import { ScoreConfig } from "./types";
3
+ /** determines whether a `ScoreResult` object is valid */
4
+ export declare const isScoreResultValid: (x: unknown) => x is ScoreResult;
5
+ /** determines whether a `ScoreConfig` object is valid */
6
+ export declare const isScoreConfigValid: (x: unknown) => x is ScoreConfig;
@@ -1,14 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isScoreConfigValid = exports.isScoreResultValid = void 0;
4
- const ramda_1 = require("ramda");
5
- /** @internal - separate function so that TS understands whats going on */
6
- const isObjectLike = (x) => typeof x === "object" && !!x && "score" in x && "category" in x;
7
- /** determines whether a `ScoreResult` object is valid */
8
- const isScoreResultValid = (x) => isObjectLike(x) &&
9
- typeof x.category === "string" &&
10
- typeof x.score === "number";
11
- exports.isScoreResultValid = isScoreResultValid;
12
- /** determines whether a `ScoreConfig` object is valid */
13
- const isScoreConfigValid = (x) => typeof x === "object" && !!x && !(0, ramda_1.isEmpty)(x) && !Array.isArray(x);
14
- exports.isScoreConfigValid = isScoreConfigValid;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isScoreConfigValid = exports.isScoreResultValid = void 0;
4
+ const ramda_1 = require("ramda");
5
+ /** @internal - separate function so that TS understands whats going on */
6
+ const isObjectLike = (x) => typeof x === "object" && !!x && "score" in x && "category" in x;
7
+ /** determines whether a `ScoreResult` object is valid */
8
+ const isScoreResultValid = (x) => isObjectLike(x) &&
9
+ typeof x.category === "string" &&
10
+ typeof x.score === "number";
11
+ exports.isScoreResultValid = isScoreResultValid;
12
+ /** determines whether a `ScoreConfig` object is valid */
13
+ const isScoreConfigValid = (x) => typeof x === "object" && !!x && !(0, ramda_1.isEmpty)(x) && !Array.isArray(x);
14
+ exports.isScoreConfigValid = isScoreConfigValid;
@@ -1 +1 @@
1
- export declare const SUBMISSION_RULES_VERSION = "sr1.3.0";
1
+ export declare const SUBMISSION_RULES_VERSION = "sr1.4.0";
@@ -1,5 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SUBMISSION_RULES_VERSION = void 0;
4
- // this must be kept in sync with ./CHANGELOG.md. See that file for more info
5
- exports.SUBMISSION_RULES_VERSION = "sr1.3.0";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SUBMISSION_RULES_VERSION = void 0;
4
+ // this must be kept in sync with ./CHANGELOG.md. See that file for more info
5
+ exports.SUBMISSION_RULES_VERSION = "sr1.4.0";
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const addLoadingTimes_1 = require("../addLoadingTimes");
4
+ describe("addLoadingTimes", () => {
5
+ it("parses loading times from the schema tags", () => {
6
+ const schema = {
7
+ name: "hi",
8
+ tags: [
9
+ "a:b",
10
+ "c",
11
+ "time:action1:20",
12
+ "time:action2:5",
13
+ "time:action3:0",
14
+ "time:action4:not a number",
15
+ ],
16
+ };
17
+ expect((0, addLoadingTimes_1.addLoadingTimes)(schema)).toStrictEqual(Object.assign(Object.assign({}, schema), { timing: {
18
+ action1: 20,
19
+ action2: 5,
20
+ action3: 0,
21
+ action4: NaN,
22
+ } }));
23
+ });
24
+ });
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const expandSchema_1 = require("../expandSchema");
4
+ const fromAPI = [
5
+ {
6
+ name: "ps_Vessel",
7
+ start_date: "1970-01-01T00:00:00+00:00",
8
+ end_date: "2222-12-31T23:59:59+00:00",
9
+ active: true,
10
+ version_current: true,
11
+ version: "0.0.7",
12
+ type: "ps",
13
+ schema: {
14
+ $id: "https://api.rayt.io/graph/v1/schema/ps/ps_Vessel",
15
+ $schema: "http://json-schema.org/draft-07/schema#",
16
+ title: "Vessel/Boat",
17
+ description: "A schema that describes a maritime vessel",
18
+ i18n: {
19
+ "mi-NZ": {
20
+ $schema: { title: "Waka" },
21
+ vesselName: { title: "nga waka ingoa" },
22
+ },
23
+ },
24
+ tags: ["time:action1:20"],
25
+ required: ["vesselName"],
26
+ properties: {
27
+ manufacture_year: {
28
+ allOf: [
29
+ { $ref: "#/definitions/ss_birth_year_integer" },
30
+ { tags: ["aaa"], priority: 700 },
31
+ ],
32
+ },
33
+ vesselName: { type: "string", title: "Vessel Name", priority: 1000 },
34
+ },
35
+ definitions: {
36
+ ss_birth_year_integer: { $ref: "urn:schema:ss_birth_year_integer" },
37
+ },
38
+ },
39
+ },
40
+ {
41
+ name: "ss_birth_year_integer",
42
+ version: "0.0.1",
43
+ schema: {
44
+ $id: "this field often has typos. in this case its blatantly wrong",
45
+ $schema: "https://whatever",
46
+ maximum: 2022,
47
+ minimum: 1900,
48
+ tags: ["type:globally_unique_field"],
49
+ title: "Year of birth",
50
+ },
51
+ },
52
+ ];
53
+ describe("expandSchema", () => {
54
+ it("can do the entire expansion process", () => {
55
+ expect((0, expandSchema_1.expandSchema)(fromAPI[0], fromAPI, ["lb-LU"])).toStrictEqual({
56
+ wasExpandedByClient: true,
57
+ // $schema was removed
58
+ name: "ps_Vessel",
59
+ title: "Vessel/Boat",
60
+ description: "A schema that describes a maritime vessel",
61
+ start_date: "1970-01-01T00:00:00+00:00",
62
+ end_date: "2222-12-31T23:59:59+00:00",
63
+ version: "0.0.7",
64
+ i18n: fromAPI[0].schema.i18n,
65
+ isProfileSchema: true,
66
+ isSpSchema: false,
67
+ properties: {
68
+ manufacture_year: {
69
+ // $id was removed
70
+ $prop: "manufacture_year",
71
+ $ref: "ss_birth_year_integer",
72
+ maximum: 2022,
73
+ minimum: 1900,
74
+ title: "Year of birth",
75
+ // it merged the allOf into a single object
76
+ priority: 700,
77
+ tags: ["aaa", "type:globally_unique_field"],
78
+ },
79
+ vesselName: {
80
+ $prop: "vesselName",
81
+ // no $ref attribute
82
+ priority: 1000,
83
+ title: "Vessel Name",
84
+ type: "string",
85
+ },
86
+ },
87
+ required: ["vesselName"],
88
+ tags: ["time:action1:20"],
89
+ timing: {
90
+ action1: 20,
91
+ },
92
+ verified_fields: undefined,
93
+ });
94
+ });
95
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const i18n_1 = require("../i18n");
4
+ const DEFAULT_LOCALES = ["de-DE"]; // match what the client does in jest.setup.ts
5
+ describe("getAllLocales", () => {
6
+ it("correctly expands languages with a country-componentand lowercases them", () => {
7
+ const expanded = (0, i18n_1.getAllLocales)([
8
+ "en-NZ",
9
+ "de-CH",
10
+ "be",
11
+ "ar-001",
12
+ "az-Cyrl-AZ",
13
+ ]);
14
+ expect(expanded).toStrictEqual([
15
+ "en-nz",
16
+ "en",
17
+ "de-ch",
18
+ "de",
19
+ "be",
20
+ "ar-001",
21
+ "ar",
22
+ "az-cyrl-az",
23
+ "az",
24
+ ]);
25
+ });
26
+ });
27
+ describe("findSuitableLocale", () => {
28
+ it("picks the most appropriate option", () => {
29
+ // the users's locale is `de-DE`, so it picked the most appropriate one from the options: `de-AT`
30
+ expect((0, i18n_1.findSuitableLocale)(["en-029", "de-AT", "fr-FR"], DEFAULT_LOCALES)).toBe("de-AT");
31
+ });
32
+ });
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const maybeUseI18n_1 = require("../maybeUseI18n");
4
+ const DEFAULT_LOCALES = ["de-DE"]; // match what the client does in jest.setup.ts
5
+ describe("maybeUseI18n", () => {
6
+ it("correctly applies schema-wise overrides", () => {
7
+ const originalSchema = {
8
+ schema_group: "old_schemas",
9
+ title: "Default title",
10
+ description: "default desc",
11
+ i18n: {
12
+ "de-de": {
13
+ $schema: {
14
+ title: "der Name dieses Schema",
15
+ description: "eine Beschreibung in Deutsch",
16
+ },
17
+ old_schemas: {
18
+ title_plural: "All the old sChema",
19
+ },
20
+ },
21
+ },
22
+ };
23
+ const translatedSchema = (0, maybeUseI18n_1.maybeUseI18n)(originalSchema, DEFAULT_LOCALES);
24
+ expect(translatedSchema).toStrictEqual({
25
+ schema_group: "old_schemas",
26
+ group_title: "All the old sChema",
27
+ title: "der Name dieses Schema",
28
+ description: "eine Beschreibung in Deutsch",
29
+ clientLocale: "de-de",
30
+ groupNames: {},
31
+ properties: {},
32
+ i18n: originalSchema.i18n,
33
+ });
34
+ });
35
+ it("corretly creates a groupNames property with the correct locale", () => {
36
+ const originalSchema = {
37
+ i18n: {
38
+ "en-nz": {
39
+ "group:DoB": { title: "Your date of birth" },
40
+ },
41
+ "fr-fr": {
42
+ "group:DoB": { title: "anniversaire" },
43
+ },
44
+ "de-de": {
45
+ "group:DoB": { title: "dein Geburtstag" },
46
+ },
47
+ },
48
+ properties: {
49
+ year_of_birth: {
50
+ tags: ["group:DoB"],
51
+ },
52
+ },
53
+ };
54
+ const translatedSchema = (0, maybeUseI18n_1.maybeUseI18n)(originalSchema, DEFAULT_LOCALES);
55
+ expect(translatedSchema).toStrictEqual({
56
+ clientLocale: "de-de",
57
+ groupNames: {
58
+ DoB: "dein Geburtstag",
59
+ },
60
+ group_title: undefined,
61
+ properties: originalSchema.properties,
62
+ i18n: originalSchema.i18n,
63
+ });
64
+ });
65
+ it("correctly applies overrides to certain schema fields", () => {
66
+ const originalSchema = {
67
+ i18n: {
68
+ "en-029": {
69
+ year_of_birth: { title: "Your year of birth" },
70
+ },
71
+ de: {
72
+ // also testing whether it utilizes "de" even tho locale is "de-DE"
73
+ year_of_birth: { title: "dein Geburtsjahr", randomProp: 1 },
74
+ },
75
+ },
76
+ properties: {
77
+ year_of_birth: {
78
+ title: "Default field title",
79
+ tags: ["group:DoB"],
80
+ },
81
+ },
82
+ };
83
+ const translatedSchema = (0, maybeUseI18n_1.maybeUseI18n)(originalSchema, DEFAULT_LOCALES);
84
+ expect(translatedSchema).toStrictEqual({
85
+ clientLocale: "de",
86
+ groupNames: {},
87
+ group_title: undefined,
88
+ properties: {
89
+ year_of_birth: {
90
+ title: "dein Geburtsjahr",
91
+ randomProp: 1,
92
+ tags: ["group:DoB"],
93
+ },
94
+ },
95
+ i18n: originalSchema.i18n,
96
+ });
97
+ });
98
+ });