Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.0.0 beta.3 #240

Merged
merged 7 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@overture-stack/lectern-server",
"private": true,
"version": "2.0.0-beta.2",
"version": "2.0.0-beta.3",
"description": "Overture Data Dictionary Management",
"scripts": {
"build": "tsc -p tsconfig.build.json",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@overture-stack/lectern",
"private": true,
"version": "2.0.0-beta.2",
"version": "2.0.0-beta.3",
"description": "Schema Manager and Validation for Data Dictionaries",
"scripts": {
"build:all": "pnpm nx run-many --all --target=build",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@overture-stack/lectern-client",
"version": "2.0.0-beta.2",
"version": "2.0.0-beta.3",
"files": [
"dist/"
],
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export type {
ParseDictionaryData,
ParseDictionaryFailure,
ParseDictionaryResult,
ParseFieldError,
ParseSchemaError,
ParseSchemaFailureData,
ParseSchemaResult,
Expand Down
2 changes: 1 addition & 1 deletion packages/dictionary/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@overture-stack/lectern-dictionary",
"version": "2.0.0-beta.2",
"version": "2.0.0-beta.3",
"description": "",
"files": [
"dist/"
Expand Down
2 changes: 1 addition & 1 deletion packages/validation/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@overture-stack/lectern-validation",
"version": "2.0.0-beta.2",
"version": "2.0.0-beta.3",
"description": "Logic for validating data using a Lectern dictionary",
"files": [
"dist/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const collectAllNestedCodeLists = (
return TypeUtils.asArray(restrictions).flatMap((restrictionsObject) => {
if ('if' in restrictionsObject) {
const thenCodeLists = restrictionsObject.then ? collectAllNestedCodeLists(restrictionsObject.then) : [];
const elseCodeLists = restrictionsObject.else ? collectAllNestedCodeLists(restrictionsObject) : [];
const elseCodeLists = restrictionsObject.else ? collectAllNestedCodeLists(restrictionsObject.else) : [];
return [...thenCodeLists, ...elseCodeLists];
} else {
return restrictionsObject.codeList ? restrictionsObject.codeList : [];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { SchemaField, type SchemaStringField } from '@overture-stack/lectern-dictionary';
import { fieldStringNoRestriction } from '../noRestrictions/fieldStringNoRestriction';
import { validateFixture } from '../../../testUtils/validateFixture';

export const fieldStringConditionalExistsWithouthThenElse = {
name: 'conditional-field',
valueType: 'string',
description: 'Required if `fieldStringNoRestriction` field exists, otherwise must be empty',
restrictions: {
if: {
conditions: [
{
fields: [fieldStringNoRestriction.name],
match: {
exists: true,
},
},
],
},
},
} as const satisfies SchemaStringField;

validateFixture(
fieldStringConditionalExistsWithouthThenElse,
SchemaField,
'fieldStringConditionalExistsWithouthThenElse is not a valid SchemaField',
);
30 changes: 30 additions & 0 deletions packages/validation/test/parseValues/parseField.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { fieldBooleanArrayRequired } from '../fixtures/fields/simpleRestrictions
import { fieldStringCodeList } from '../fixtures/fields/simpleRestrictions/string/fieldStringCodeList';
import { codeListString } from '../fixtures/restrictions/codeListsFixtures';
import { fieldStringArrayCodeList } from '../fixtures/fields/simpleRestrictions/string/fieldStringArrayCodeList';
import { fieldStringConditionalExists } from '../fixtures/fields/conditionalRestrictions/fieldStringConditionalExists';
import { fieldStringConditionalExistsWithouthThenElse } from '../fixtures/fields/conditionalRestrictions/fieldStringConditionalExistsWithoutThenElse';

describe('Parse Values - parseFieldValue', () => {
describe('Single Value Fields', () => {
Expand Down Expand Up @@ -165,6 +167,34 @@ describe('Parse Values - parseFieldValue', () => {
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringNoRestriction).success).true;
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringNoRestriction).data).equals('!@#$%^&* ()_+');
});
it('Successfuly parses strings, with conditional restrictions', () => {
const value = 'any random string value!!!';
const result = parseFieldValue(value, fieldStringConditionalExists);
expect(result.success).true;
expect(result.data).equal(value);

expect(parseFieldValue(' 123', fieldStringConditionalExists).success).true;
expect(parseFieldValue(' 123', fieldStringConditionalExists).data).equals('123');
expect(parseFieldValue('false ', fieldStringConditionalExists).success).true;
expect(parseFieldValue('false ', fieldStringConditionalExists).data).equals('false');
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringConditionalExists).success).true;
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringConditionalExists).data).equals('!@#$%^&* ()_+');
});
it('Successfuly parses strings, with conditional restrictions without then or else', () => {
const value = 'any random string value!!!';
const result = parseFieldValue(value, fieldStringConditionalExistsWithouthThenElse);
expect(result.success).true;
expect(result.data).equal(value);

expect(parseFieldValue(' 123', fieldStringConditionalExistsWithouthThenElse).success).true;
expect(parseFieldValue(' 123', fieldStringConditionalExistsWithouthThenElse).data).equals('123');
expect(parseFieldValue('false ', fieldStringConditionalExistsWithouthThenElse).success).true;
expect(parseFieldValue('false ', fieldStringConditionalExistsWithouthThenElse).data).equals('false');
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringConditionalExistsWithouthThenElse).success).true;
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringConditionalExistsWithouthThenElse).data).equals(
'!@#$%^&* ()_+',
);
});
it('Updates string to match formatting of codeList value', () => {
const value = 'banana';
const result = parseFieldValue(value, fieldStringCodeList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { fieldBooleanNoRestriction } from '../fixtures/fields/noRestrictions/fie
import { fieldNumberNoRestriction } from '../fixtures/fields/noRestrictions/fieldNumberNoRestriction';
import { fieldStringNoRestriction } from '../fixtures/fields/noRestrictions/fieldStringNoRestriction';
import { regexAlphaOnly } from '../fixtures/restrictions/regexFixtures';
import { fieldStringConditionalExistsWithouthThenElse } from '../fixtures/fields/conditionalRestrictions/fieldStringConditionalExistsWithoutThenElse';

describe('Field - resolveFieldRestrictions', () => {
it('Returns empty array when there are no restrictions', () => {
Expand Down Expand Up @@ -103,6 +104,18 @@ describe('Field - resolveFieldRestrictions', () => {
const codeListRestriction = restrictions.find((restriction) => restriction.type === 'codeList');
expect(codeListRestriction).not.undefined;
});
it('Does not add any restriction when condition is true and there is no `then`', () => {
const record: DataRecord = {
[fieldStringNoRestriction.name]: 'anything',
[fieldStringConditionalExistsWithouthThenElse.name]: 'anything goes',
};
const restrictions = resolveFieldRestrictions(
record[fieldStringConditionalExistsWithouthThenElse.name],
record,
fieldStringConditionalExistsWithouthThenElse,
);
expect(restrictions.length).equal(0);
});
it('Does not add any restriction when condition fails and there is no `else`', () => {
const record: DataRecord = {
[fieldNumberNoRestriction.name]: 0,
Expand Down