Skip to content

Commit

Permalink
Merge branch 'chore/drop-runtypes' into 'develop'
Browse files Browse the repository at this point in the history
OEQ-1438 chore: drop dependency runtypes in REST Module

See merge request edalex-group/development/oeq/openequella!260
  • Loading branch information
PenghaiZhang committed Sep 28, 2023
2 parents afaafab + 41b470e commit 873f4ea
Show file tree
Hide file tree
Showing 32 changed files with 593 additions and 441 deletions.
11 changes: 0 additions & 11 deletions oeq-ts-rest-api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion oeq-ts-rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"monocle-ts": "2.3.13",
"newtype-ts": "0.3.5",
"query-string": "^7.0.0",
"runtypes": "6.7.0",
"tough-cookie": "^4.0.0"
},
"devDependencies": {
Expand Down
14 changes: 0 additions & 14 deletions oeq-ts-rest-api/src/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
import { pipe } from 'fp-ts/function';
import * as t from 'io-ts';
import { Literal, Union } from 'runtypes';
import {
BaseEntityCodec,
BaseEntitySummaryCodec,
Expand Down Expand Up @@ -109,19 +108,6 @@ export const isBaseEntitySummaryArray = (
): instance is BaseEntitySummary[] =>
pipe(instance, validate(t.array(BaseEntitySummaryCodec)));

export const ItemStatuses = Union(
Literal('ARCHIVED'),
Literal('DELETED'),
Literal('DRAFT'),
Literal('LIVE'),
Literal('MODERATING'),
Literal('PERSONAL'),
Literal('REJECTED'),
Literal('REVIEW'),
Literal('SUSPENDED')
);

// todo: fix this type alias which is not in sync with the runtype. Jira ticket: OEQ-1438
export type ItemStatus =
| 'ARCHIVED'
| 'DELETED'
Expand Down
12 changes: 0 additions & 12 deletions oeq-ts-rest-api/src/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* limitations under the License.
*/
import { stringify } from 'query-string';
import { Literal, Union } from 'runtypes';
import { GET, HEAD, POST } from './AxiosInstance';
import type { i18nString, ItemStatus } from './Common';
import { SearchResultCodec, SearchResultItemRawCodec } from './gen/Search';
Expand All @@ -28,17 +27,6 @@ import { convertDateFields, validate } from './Utils';
*/
export type Must = [string, string[]];

export const SortOrderRunTypes = Union(
Literal('rank'),
Literal('datemodified'),
Literal('datecreated'),
Literal('name'),
Literal('rating'),
Literal('task_lastaction'),
Literal('task_submitted')
);

// todo: fix this type alias which is not in sync with the runtype. Jira ticket: OEQ-1438
export type SortOrder =
| 'rank'
| 'datemodified'
Expand Down
8 changes: 0 additions & 8 deletions oeq-ts-rest-api/src/SearchSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Literal, Union } from 'runtypes';
import { GET, PUT } from './AxiosInstance';
import { SettingsCodec } from './gen/SearchSettings';
import type { SortOrder } from './Search';
import { validate } from './Utils';

export const ContentIndexLevelRunTypes = Union(
Literal(0),
Literal(1),
Literal(2)
);

// todo: fix this type alias which is not in sync with the runtype. Jira ticket: OEQ-1438
export type ContentIndexLevel = 0 | 1 | 2;

export interface Settings {
Expand Down
18 changes: 0 additions & 18 deletions oeq-ts-rest-api/src/WizardControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Literal, Union } from 'runtypes';
import type { UuidString } from './Common';
import type { SelectionRestriction, TermStorageFormat } from './Taxonomy';
import type {
Expand All @@ -24,23 +23,6 @@ import type {
WizardDateFormat,
} from './WizardCommonTypes';

/**
* Runtypes definition for Wizard control type.
*/
export const RuntypesControlType = Union(
Literal('calendar'),
Literal('checkboxgroup'),
Literal('editbox'),
Literal('html'),
Literal('listbox'),
Literal('radiogroup'),
Literal('shufflebox'),
Literal('shufflelist'),
Literal('termselector'),
Literal('userselector')
);

// todo: fix this type alias which is not in sync with the runtype. Jira ticket: OEQ-1438
/**
* Supported Wizard Control types.
*/
Expand Down
10 changes: 10 additions & 0 deletions oeq-ts-rest-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as CommonCodec from './gen/Common';
import * as SearchCodec from './gen/Search';
import * as WizardControlCodec from './gen/WizardControl';

export * as Acl from './Acl';
export * as AdvancedSearch from './AdvancedSearch';
export * as Auth from './Auth';
Expand Down Expand Up @@ -44,3 +48,9 @@ export * as UserQuery from './UserQuery';
export * as Utils from './Utils';
export * as WizardCommonTypes from './WizardCommonTypes';
export * as WizardControl from './WizardControl';

export const Codec = {
Common: CommonCodec,
Search: SearchCodec,
WizardControl: WizardControlCodec,
};
48 changes: 24 additions & 24 deletions react-front-end/__mocks__/ACLRecipientModule.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
LOGGED_IN_USER_ROLE_ID,
} from "../tsrc/modules/ACLRecipientModule";

export const ownerRecipient = {
export const ownerRecipient: ACLRecipient = {
expression: "$OWNER",
type: "$OWNER",
};
Expand All @@ -32,7 +32,7 @@ export const ownerRecipientWithName: ACLRecipient = {
name: ownerRecipientHumanReadableExpression,
};

export const everyoneRecipient = {
export const everyoneRecipient: ACLRecipient = {
expression: "*",
type: "*",
};
Expand All @@ -43,7 +43,7 @@ export const everyoneRecipientWithName: ACLRecipient = {
name: everyoneRecipientHumanReadableExpression,
};

export const user100Recipient = {
export const user100Recipient: ACLRecipient = {
expression: "20483af2-fe56-4499-a54b-8d7452156895",
type: "U",
};
Expand All @@ -56,16 +56,16 @@ export const user100RecipientWithName = {
name: user100RecipientHumanReadableExpression,
};

export const user200Recipient = {
export const user200Recipient: ACLRecipient = {
expression: "f9ec8b09-cf64-44ff-8a0a-08a8f2f9272a",
type: "U",
};
export const user200RecipientWithName = {
export const user200RecipientWithName: ACLRecipient = {
...user200Recipient,
name: "Racheal Carlyle [user200]",
};

export const user300Recipient = {
export const user300Recipient: ACLRecipient = {
expression: "eb75a832-6533-4d72-93f4-2b7a1b108951",
type: "U",
};
Expand All @@ -74,26 +74,26 @@ export const user300RecipientWithName = {
name: "Yasmin Day [user300]",
};

export const user400Recipient = {
export const user400Recipient: ACLRecipient = {
expression: "1c2ff1d0-9040-4985-a450-0ff6422ba5ef",
type: "U",
};
export const user400RecipientWithName = {
export const user400RecipientWithName: ACLRecipient = {
...user400Recipient,
name: "Ronny Southgate [user400]",
};

export const userAdminRecipient = {
export const userAdminRecipient: ACLRecipient = {
expression: "75abbd62-d91c-4ce5-b4b5-339e0d44ac0e",
type: "U",
};

export const userContentAdminRecipient = {
export const userContentAdminRecipient: ACLRecipient = {
expression: "2",
type: "U",
};

export const roleGuestRecipient = {
export const roleGuestRecipient: ACLRecipient = {
expression: GUEST_USER_ROLE_ID,
type: "R",
};
Expand All @@ -105,14 +105,14 @@ export const roleGuestRecipientWithName = {
};

export const LOGGED_IN_USER_ROLE_NAME = "Logged In User Role";
export const roleLoggedRecipientWithName = {
export const roleLoggedRecipientWithName: ACLRecipient = {
expression: LOGGED_IN_USER_ROLE_ID,
type: "R",
name: LOGGED_IN_USER_ROLE_NAME,
};
export const roleLoggedRecipientRawExpression = `R:${LOGGED_IN_USER_ROLE_ID}`;

export const role100RecipientWithName = {
export const role100RecipientWithName: ACLRecipient = {
expression: "fda99983-9eda-440a-ac68-0f746173fdcb",
type: "R",
name: "role100",
Expand All @@ -124,7 +124,7 @@ export const role200RecipientWithName = {
name: "role200",
};

export const groupStudentRecipient = {
export const groupStudentRecipient: ACLRecipient = {
expression: "99806ac8-410e-4c60-b3ab-22575276f0f0",
type: "G",
};
Expand All @@ -133,36 +133,36 @@ export const groupStudentRecipientRawExpression =
export const groupStudentRecipientHumanReadableExpression =
"Engineering & Computer Science Students";

export const groupStaffRecipient = {
export const groupStaffRecipient: ACLRecipient = {
expression: "d0265a33-8f89-4cea-8a36-45fd3c4cf5a1",
type: "G",
};

export const group100RecipientWithName = {
export const group100RecipientWithName: ACLRecipient = {
expression: "303e758c-0051-4aea-9a8e-421f93ed9d1a",
type: "G",
name: "group100",
};

export const group200RecipientWithName = {
export const group200RecipientWithName: ACLRecipient = {
expression: "d7dd1907-5731-4244-9a65-e0e847f68604",
type: "G",
name: "group200",
};

export const group300RecipientWithName = {
export const group300RecipientWithName: ACLRecipient = {
expression: "f921a6e3-69a6-4ec4-8cf8-bc193beda5f6",
type: "G",
name: "group300",
};

export const group400RecipientWithName = {
export const group400RecipientWithName: ACLRecipient = {
expression: "a2576dea-bd5c-490b-a065-637068e1a4fb",
type: "G",
name: "group400",
};

export const ssoMoodleRecipient = {
export const ssoMoodleRecipient: ACLRecipient = {
expression: "moodle",
type: "T",
};
Expand All @@ -174,26 +174,26 @@ export const ssoMoodleRecipientWithName = {
};

// helper function to generate an IP recipient
export const ipRecipient = (ip: string) => ({
export const ipRecipient = (ip: string): ACLRecipient => ({
expression: ip,
type: "I",
});

// helper function to generate an IP recipient with name
export const ipRecipientWithName = (ip: string) => ({
export const ipRecipientWithName = (ip: string): ACLRecipient => ({
expression: ip,
type: "I",
name: `From ${ip}`,
});

// helper function to generate an refer recipient
export const referRecipient = (refer: string) => ({
export const referRecipient = (refer: string): ACLRecipient => ({
expression: refer,
type: "F",
});

// helper function to generate a referrer recipient with name
export const referRecipientWithName = (refer: string) => ({
export const referRecipientWithName = (refer: string): ACLRecipient => ({
...referRecipient(refer),
name: `From ${decodeURIComponent(refer)}`,
});
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe("<ACLExpressionBuilder/>", () => {
// delete recipient
await clickDeleteButtonForRecipient(
container,
user200RecipientWithName.name
user200RecipientWithName.name!
);
// click ok button to see if the result is what we want
await userEvent.click(getByText(okLabel));
Expand Down Expand Up @@ -247,14 +247,14 @@ describe("<ACLExpressionBuilder/>", () => {
[
"group",
groupsRadioLabel,
group100RecipientWithName.name,
group100RecipientWithName.name!,
searchGroup,
"G:303e758c-0051-4aea-9a8e-421f93ed9d1a",
],
[
"role",
rolesRadioLabel,
role100RecipientWithName.name,
role100RecipientWithName.name!,
searchRole,
"R:fda99983-9eda-440a-ac68-0f746173fdcb",
],
Expand Down Expand Up @@ -446,7 +446,7 @@ describe("<ACLExpressionBuilder/>", () => {
// click add button
await userEvent.click(getByText(addLabel));
// wait for adding action
await findByText(ipRecipient.name);
await findByText(ipRecipient.name!);

// click ok button to check the result
await userEvent.click(getByText(okLabel));
Expand Down Expand Up @@ -486,7 +486,7 @@ describe("<ACLExpressionBuilder/>", () => {
// click add button
await userEvent.click(getByText(addLabel));
// wait for adding action
await findByText(httpReferrerRecipient.name);
await findByText(httpReferrerRecipient.name!);

// click ok button to check the result
await userEvent.click(getByText(okLabel));
Expand Down
Loading

0 comments on commit 873f4ea

Please sign in to comment.