Skip to content
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
34 changes: 20 additions & 14 deletions libraries/common/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

export class ConflictError extends Error {
export class BadRequestError extends Error {
constructor(message: string) {
super(message);
this.name = 'Conflict';
this.name = 'BadRequest';
}
}

export class BadRequestError extends Error {
export class ConflictError extends Error {
constructor(message: string) {
super(message);
this.name = 'BadRequest';
this.name = 'Conflict';
}
}

export class MalformedVersionError extends Error {
export class ForbiddenError extends Error {
constructor(message: string) {
super(message);
this.name = 'MalformedVersion';
this.name = 'Forbidden';
}
}

Expand All @@ -45,30 +45,36 @@ export class InternalServerError extends Error {
}
}

export class NotFoundError extends Error {
export class InvalidArgument extends Error {
constructor(argumentName: string) {
super(`Invalid argument : ${argumentName}`);
}
}

export class InvalidReferenceError extends Error {
constructor(message: string) {
super(message);
this.name = 'NotFound';
this.name = 'InvalidReference';
}
}

export class UnauthorizedError extends Error {
export class MalformedVersionError extends Error {
constructor(message: string) {
super(message);
this.name = 'Unauthorized';
this.name = 'MalformedVersion';
}
}

export class ForbiddenError extends Error {
export class NotFoundError extends Error {
constructor(message: string) {
super(message);
this.name = 'Forbidden';
this.name = 'NotFound';
}
}

export class InvalidReferenceError extends Error {
export class UnauthorizedError extends Error {
constructor(message: string) {
super(message);
this.name = 'InvalidReference';
this.name = 'Unauthorized';
}
}
1 change: 1 addition & 0 deletions libraries/common/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './generics';
export * from './result';
export * from './singular';
16 changes: 16 additions & 0 deletions libraries/common/src/types/singular.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Utility type that finds the type or types from inside an Array or nested Arrays.
*
* @example
* type String = Singular<string>; // `String` is `string`
* type JustAString = Singular<string[]>; // `JustAString` is `string`
* type StillJustAString = Singular<(string[][][][][]>; // `StillJustAString` is `string`
* type StringOrNumberFromUnion = Singular<(string[] | number)[] | string>; // `StringOrNumber` is `string | number`
* type TupleContents = Singular<[number, string, boolean]> // `TupleContents` is `number | string | boolean`
* type ArrayOfTuplesContents = Singular<[number, string, boolean]> // `ArrayOfTuplesContents` is `number | string | boolean`
*/
export type Singular<T> = T extends Array<infer ElementTypes>
? Singular<ElementTypes>
: T extends ReadonlyArray<infer ElementTypes>
? Singular<ElementTypes>
: T;
3 changes: 3 additions & 0 deletions libraries/dictionary/src/types/dictionaryTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export type SchemaFieldValueType = zod.infer<typeof SchemaFieldValueType>;
* ************ */
export const RestrictionScript = zod.array(zod.string().or(ReferenceTag)).min(1); //TODO: script formatting validation
export type RestrictionScript = zod.infer<typeof RestrictionScript>;

export const RestrictionNumberRange = zod
.object({
exclusiveMax: zod.number().optional(),
Expand Down Expand Up @@ -99,6 +100,8 @@ export const RestrictionIntegerRange = zod
(data) => !(data.exclusiveMax !== undefined && data.max !== undefined),
'Range restriction cannot have both `exclusiveMax` and `max`.',
);

export const RestrictionRange = RestrictionNumberRange;
export type RestrictionRange = zod.infer<typeof RestrictionIntegerRange>;

export const RestrictionRegex = zod.string().superRefine((data, context) => {
Expand Down
27 changes: 25 additions & 2 deletions libraries/dictionary/src/types/diffTypes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* Copyright (c) 2024 The Ontario Institute for Cancer Research. All rights reserved
*
* This program and the accompanying materials are made available under the terms of
* the GNU Affero General Public License v3.0. You should have received a copy of the
* GNU Affero General Public License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import { z as zod } from 'zod';
import { SchemaField } from './dictionaryTypes';

Expand All @@ -24,8 +43,12 @@ export type ValueChange = zod.infer<typeof ValueChange>;
// in case of created/delete field we get Change
// in case of simple field change we get {"fieldName": {"data":.., "type": ..}}
// in case of nested fields: {"fieldName1": {"fieldName2": {"data":.., "type": ..}}}
export type FieldChanges = { [field: string]: FieldChanges } | ValueChange;
export const FieldChanges: zod.ZodType<FieldChanges> = zod.union([zod.lazy(() => FieldChanges), ValueChange]);
export type FieldChanges = { [field: string]: FieldChanges } | ValueChange | undefined;
export const FieldChanges: zod.ZodType<FieldChanges> = zod.union([
zod.lazy(() => FieldChanges),
ValueChange,
zod.undefined(),
]);

export const FieldDiff = zod.object({
left: SchemaField.optional(),
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
"cd": "^0.3.3",
"common": "workspace:^",
"deep-freeze": "^0.0.1",
"dictionary": "workspace:^",
"lodash": "^4.17.21",
"node-fetch": "^2.6.1",
"node-worker-threads-pool": "^1.4.3",
"promise-tools": "^2.1.0",
"winston": "^3.3.3"
},
Expand Down
Loading