Skip to content

Commit f82aafb

Browse files
authored
Merge pull request #240 from overture-stack/release-2.0.0-beta.3
Release 2.0.0 beta.3
2 parents 4099e34 + c93b977 commit f82aafb

File tree

10 files changed

+77
-6
lines changed

10 files changed

+77
-6
lines changed

apps/server/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@overture-stack/lectern-server",
33
"private": true,
4-
"version": "2.0.0-beta.2",
4+
"version": "2.0.0-beta.3",
55
"description": "Overture Data Dictionary Management",
66
"scripts": {
77
"build": "tsc -p tsconfig.build.json",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@overture-stack/lectern",
33
"private": true,
4-
"version": "2.0.0-beta.2",
4+
"version": "2.0.0-beta.3",
55
"description": "Schema Manager and Validation for Data Dictionaries",
66
"scripts": {
77
"build:all": "pnpm nx run-many --all --target=build",

packages/client/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@overture-stack/lectern-client",
3-
"version": "2.0.0-beta.2",
3+
"version": "2.0.0-beta.3",
44
"files": [
55
"dist/"
66
],

packages/client/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export type {
4545
ParseDictionaryData,
4646
ParseDictionaryFailure,
4747
ParseDictionaryResult,
48+
ParseFieldError,
4849
ParseSchemaError,
4950
ParseSchemaFailureData,
5051
ParseSchemaResult,

packages/dictionary/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@overture-stack/lectern-dictionary",
3-
"version": "2.0.0-beta.2",
3+
"version": "2.0.0-beta.3",
44
"description": "",
55
"files": [
66
"dist/"

packages/validation/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@overture-stack/lectern-validation",
3-
"version": "2.0.0-beta.2",
3+
"version": "2.0.0-beta.3",
44
"description": "Logic for validating data using a Lectern dictionary",
55
"files": [
66
"dist/"

packages/validation/src/parseValues/matchCodeListFormatting.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const collectAllNestedCodeLists = (
2929
return TypeUtils.asArray(restrictions).flatMap((restrictionsObject) => {
3030
if ('if' in restrictionsObject) {
3131
const thenCodeLists = restrictionsObject.then ? collectAllNestedCodeLists(restrictionsObject.then) : [];
32-
const elseCodeLists = restrictionsObject.else ? collectAllNestedCodeLists(restrictionsObject) : [];
32+
const elseCodeLists = restrictionsObject.else ? collectAllNestedCodeLists(restrictionsObject.else) : [];
3333
return [...thenCodeLists, ...elseCodeLists];
3434
} else {
3535
return restrictionsObject.codeList ? restrictionsObject.codeList : [];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { SchemaField, type SchemaStringField } from '@overture-stack/lectern-dictionary';
2+
import { fieldStringNoRestriction } from '../noRestrictions/fieldStringNoRestriction';
3+
import { validateFixture } from '../../../testUtils/validateFixture';
4+
5+
export const fieldStringConditionalExistsWithouthThenElse = {
6+
name: 'conditional-field',
7+
valueType: 'string',
8+
description: 'Required if `fieldStringNoRestriction` field exists, otherwise must be empty',
9+
restrictions: {
10+
if: {
11+
conditions: [
12+
{
13+
fields: [fieldStringNoRestriction.name],
14+
match: {
15+
exists: true,
16+
},
17+
},
18+
],
19+
},
20+
},
21+
} as const satisfies SchemaStringField;
22+
23+
validateFixture(
24+
fieldStringConditionalExistsWithouthThenElse,
25+
SchemaField,
26+
'fieldStringConditionalExistsWithouthThenElse is not a valid SchemaField',
27+
);

packages/validation/test/parseValues/parseField.spec.ts

+30
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import { fieldBooleanArrayRequired } from '../fixtures/fields/simpleRestrictions
3030
import { fieldStringCodeList } from '../fixtures/fields/simpleRestrictions/string/fieldStringCodeList';
3131
import { codeListString } from '../fixtures/restrictions/codeListsFixtures';
3232
import { fieldStringArrayCodeList } from '../fixtures/fields/simpleRestrictions/string/fieldStringArrayCodeList';
33+
import { fieldStringConditionalExists } from '../fixtures/fields/conditionalRestrictions/fieldStringConditionalExists';
34+
import { fieldStringConditionalExistsWithouthThenElse } from '../fixtures/fields/conditionalRestrictions/fieldStringConditionalExistsWithoutThenElse';
3335

3436
describe('Parse Values - parseFieldValue', () => {
3537
describe('Single Value Fields', () => {
@@ -165,6 +167,34 @@ describe('Parse Values - parseFieldValue', () => {
165167
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringNoRestriction).success).true;
166168
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringNoRestriction).data).equals('!@#$%^&* ()_+');
167169
});
170+
it('Successfuly parses strings, with conditional restrictions', () => {
171+
const value = 'any random string value!!!';
172+
const result = parseFieldValue(value, fieldStringConditionalExists);
173+
expect(result.success).true;
174+
expect(result.data).equal(value);
175+
176+
expect(parseFieldValue(' 123', fieldStringConditionalExists).success).true;
177+
expect(parseFieldValue(' 123', fieldStringConditionalExists).data).equals('123');
178+
expect(parseFieldValue('false ', fieldStringConditionalExists).success).true;
179+
expect(parseFieldValue('false ', fieldStringConditionalExists).data).equals('false');
180+
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringConditionalExists).success).true;
181+
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringConditionalExists).data).equals('!@#$%^&* ()_+');
182+
});
183+
it('Successfuly parses strings, with conditional restrictions without then or else', () => {
184+
const value = 'any random string value!!!';
185+
const result = parseFieldValue(value, fieldStringConditionalExistsWithouthThenElse);
186+
expect(result.success).true;
187+
expect(result.data).equal(value);
188+
189+
expect(parseFieldValue(' 123', fieldStringConditionalExistsWithouthThenElse).success).true;
190+
expect(parseFieldValue(' 123', fieldStringConditionalExistsWithouthThenElse).data).equals('123');
191+
expect(parseFieldValue('false ', fieldStringConditionalExistsWithouthThenElse).success).true;
192+
expect(parseFieldValue('false ', fieldStringConditionalExistsWithouthThenElse).data).equals('false');
193+
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringConditionalExistsWithouthThenElse).success).true;
194+
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringConditionalExistsWithouthThenElse).data).equals(
195+
'!@#$%^&* ()_+',
196+
);
197+
});
168198
it('Updates string to match formatting of codeList value', () => {
169199
const value = 'banana';
170200
const result = parseFieldValue(value, fieldStringCodeList);

packages/validation/test/validateField/resolveFieldRestrictions.spec.ts

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { fieldBooleanNoRestriction } from '../fixtures/fields/noRestrictions/fie
3333
import { fieldNumberNoRestriction } from '../fixtures/fields/noRestrictions/fieldNumberNoRestriction';
3434
import { fieldStringNoRestriction } from '../fixtures/fields/noRestrictions/fieldStringNoRestriction';
3535
import { regexAlphaOnly } from '../fixtures/restrictions/regexFixtures';
36+
import { fieldStringConditionalExistsWithouthThenElse } from '../fixtures/fields/conditionalRestrictions/fieldStringConditionalExistsWithoutThenElse';
3637

3738
describe('Field - resolveFieldRestrictions', () => {
3839
it('Returns empty array when there are no restrictions', () => {
@@ -103,6 +104,18 @@ describe('Field - resolveFieldRestrictions', () => {
103104
const codeListRestriction = restrictions.find((restriction) => restriction.type === 'codeList');
104105
expect(codeListRestriction).not.undefined;
105106
});
107+
it('Does not add any restriction when condition is true and there is no `then`', () => {
108+
const record: DataRecord = {
109+
[fieldStringNoRestriction.name]: 'anything',
110+
[fieldStringConditionalExistsWithouthThenElse.name]: 'anything goes',
111+
};
112+
const restrictions = resolveFieldRestrictions(
113+
record[fieldStringConditionalExistsWithouthThenElse.name],
114+
record,
115+
fieldStringConditionalExistsWithouthThenElse,
116+
);
117+
expect(restrictions.length).equal(0);
118+
});
106119
it('Does not add any restriction when condition fails and there is no `else`', () => {
107120
const record: DataRecord = {
108121
[fieldNumberNoRestriction.name]: 0,

0 commit comments

Comments
 (0)