Skip to content

Commit

Permalink
convert to Typescript grapqlProtocol files ; fix /add engine types
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Apr 3, 2020
1 parent fe28172 commit 2195720
Show file tree
Hide file tree
Showing 37 changed files with 383 additions and 269 deletions.
3 changes: 2 additions & 1 deletion src/engine/attribute/Attribute.ts
Expand Up @@ -115,7 +115,8 @@ export type Attribute = AttributeBase & {
/**
* name of the attribute
*/
name: string;
// name: string;
name?: string;

/**
* map of target attributes when referencing another entity
Expand Down
8 changes: 4 additions & 4 deletions src/engine/configuration/Configuration.ts
Expand Up @@ -49,7 +49,7 @@ export class Configuration {
}
}

setLanguages(languages): void {
setLanguages(languages: string[]): void {
passOrThrow(
isArray(languages, true),
() => 'Configuration.setLanguages() expects a list of language iso codes',
Expand Down Expand Up @@ -79,7 +79,7 @@ export class Configuration {
return this.getLanguages()[0];
}

setSchema(schema): void {
setSchema(schema: Schema): void {
passOrThrow(isSchema(schema), () => 'Configuration expects a valid schema');

this.schema = schema;
Expand All @@ -91,7 +91,7 @@ export class Configuration {
return this.schema;
}

setProtocolConfiguration(protocolConfiguration): void {
setProtocolConfiguration(protocolConfiguration: ProtocolConfiguration): void {
passOrThrow(
isProtocolConfiguration(protocolConfiguration),
() => 'Configuration expects a valid protocolConfiguration',
Expand All @@ -111,7 +111,7 @@ export class Configuration {
return this.protocolConfiguration;
}

setStorageConfiguration(storageConfiguration): void {
setStorageConfiguration(storageConfiguration: StorageConfiguration): void {
passOrThrow(
isStorageConfiguration(storageConfiguration),
() => 'Configuration expects a valid storageConfiguration',
Expand Down
80 changes: 46 additions & 34 deletions src/engine/cursor.spec.ts
Expand Up @@ -35,15 +35,15 @@ describe('cursor', () => {
indexes: [
new Index({
type: INDEX_UNIQUE,
attributes: [ 'loginName' ],
attributes: ['loginName'],
}),
new Index({
type: INDEX_UNIQUE,
attributes: [ 'firstName', 'lastName' ],
attributes: ['firstName', 'lastName'],
}),
new Index({
type: INDEX_UNIQUE,
attributes: [ 'email' ],
attributes: ['email'],
}),
],
});
Expand All @@ -58,23 +58,23 @@ describe('cursor', () => {

it('should throw if incompatible cursor provided', () => {
function fn() {
processCursor(<Entity>{}, { a: <any>'b' });
processCursor({} as Entity, { a: 'b' as any });
}

expect(fn).toThrowErrorMatchingSnapshot();
});

it('should throw if cursor is malformed', () => {
function fn1() {
processCursor(SomeEntity, { SomeEntity: [ <any>'b' ] }, []);
processCursor(SomeEntity, { SomeEntity: ['b' as any] }, []);
}

function fn2() {
processCursor(SomeEntity, { SomeEntity: [ <any>[ {}, {}, {} ] ] }, []);
processCursor(SomeEntity, { SomeEntity: [[{}, {}, {}] as any] }, []);
}

function fn3() {
processCursor(SomeEntity, { SomeEntity: [ <any>{} ] }, []);
processCursor(SomeEntity, { SomeEntity: [{} as any] }, []);
}

expect(fn1).toThrowErrorMatchingSnapshot();
Expand All @@ -87,7 +87,7 @@ describe('cursor', () => {
processCursor(
SomeEntity,
{
SomeEntity: [ [ 'iDontKnow', 123 ] ],
SomeEntity: [['iDontKnow', 123]],
},
[],
);
Expand All @@ -99,15 +99,15 @@ describe('cursor', () => {
it('should throw if an attribute is used which the data set is not sorted by', () => {
function fn1() {
processCursor(SomeEntity, {
SomeEntity: [ [ 'loginName', 123 ] ],
SomeEntity: [['loginName', 123]],
});
}

function fn2() {
processCursor(
SomeEntity,
{
SomeEntity: [ [ 'loginName', 123 ] ],
SomeEntity: [['loginName', 123]],
},
[
{
Expand All @@ -122,7 +122,10 @@ describe('cursor', () => {
processCursor(
SomeEntity,
{
SomeEntity: [ [ 'loginName', 123 ], [ 'email', 123 ] ],
SomeEntity: [
['loginName', 123],
['email', 123],
],
},
[
{
Expand All @@ -143,7 +146,7 @@ describe('cursor', () => {
processCursor(
SomeEntity,
{
SomeEntity: [ [ 'firstName', 'John' ] ],
SomeEntity: [['firstName', 'John']],
},
[
{
Expand All @@ -158,7 +161,10 @@ describe('cursor', () => {
processCursor(
SomeEntity,
{
SomeEntity: [ [ 'firstName', 'John' ], [ 'lastName', 'Snow' ] ],
SomeEntity: [
['firstName', 'John'],
['lastName', 'Snow'],
],
},
[
{
Expand All @@ -182,7 +188,7 @@ describe('cursor', () => {
const cursor1 = processCursor(
SomeEntity,
{
SomeEntity: [ [ 'loginName', 'user1' ] ],
SomeEntity: [['loginName', 'user1']],
},
[
{
Expand All @@ -201,7 +207,7 @@ describe('cursor', () => {
const cursor2 = processCursor(
SomeEntity,
{
SomeEntity: [ [ 'loginName', 123 ] ],
SomeEntity: [['loginName', 123]],
},
[
{
Expand All @@ -221,8 +227,8 @@ describe('cursor', () => {
SomeEntity,
{
SomeEntity: [
[ 'loginName', 'user1' ],
[ 'email', 'user1@example.com' ],
['loginName', 'user1'],
['email', 'user1@example.com'],
],
},
[
Expand Down Expand Up @@ -250,7 +256,10 @@ describe('cursor', () => {

it('when using attributes that are not all defined as unique', () => {
const row1: CursorType = {
SomeEntity: [ [ 'firstName', 'John' ], [ 'id', 1123 ] ],
SomeEntity: [
['firstName', 'John'],
['id', 1123],
],
};

const cursor1 = processCursor(SomeEntity, row1, [
Expand Down Expand Up @@ -347,9 +356,9 @@ describe('cursor', () => {

const row2: CursorType = {
SomeEntity: [
[ 'firstName', 'John' ],
[ 'lastName', 'Snow' ],
[ 'id', 1123 ],
['firstName', 'John'],
['lastName', 'Snow'],
['id', 1123],
],
};

Expand Down Expand Up @@ -409,10 +418,10 @@ describe('cursor', () => {

const row3: CursorType = {
SomeEntity: [
[ 'firstName', 'John' ],
[ 'email', 'john@example.com' ],
[ 'lastName', 'Snow' ],
[ 'id', 1123 ],
['firstName', 'John'],
['email', 'john@example.com'],
['lastName', 'Snow'],
['id', 1123],
],
};

Expand Down Expand Up @@ -460,7 +469,7 @@ describe('cursor', () => {
const cursor0 = processCursor(
SomeEntity,
{
SomeEntity: [ [ 'loginName', 123 ] ],
SomeEntity: [['loginName', 123]],
},
[
{
Expand All @@ -478,7 +487,10 @@ describe('cursor', () => {
};

const row1: CursorType = {
SomeEntity: [ [ 'firstName', 'John' ], [ 'id', 1123 ] ],
SomeEntity: [
['firstName', 'John'],
['id', 1123],
],
};

const cursor1 = processCursor(
Expand Down Expand Up @@ -595,9 +607,9 @@ describe('cursor', () => {

const row2: CursorType = {
SomeEntity: [
[ 'firstName', 'John' ],
[ 'lastName', 'Snow' ],
[ 'id', 1123 ],
['firstName', 'John'],
['lastName', 'Snow'],
['id', 1123],
],
};

Expand Down Expand Up @@ -667,10 +679,10 @@ describe('cursor', () => {

const row3: CursorType = {
SomeEntity: [
[ 'firstName', 'John' ],
[ 'email', 'john@example.com' ],
[ 'lastName', 'Snow' ],
[ 'id', 1123 ],
['firstName', 'John'],
['email', 'john@example.com'],
['lastName', 'Snow'],
['id', 1123],
],
};

Expand Down
6 changes: 4 additions & 2 deletions src/engine/datatype/DataType.spec.ts
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-function */

import { DataType, DataTypeSetup, isDataType } from './DataType';

import { passOrThrow } from '../util';
Expand All @@ -16,9 +18,9 @@ describe('DataType', () => {
it('should have a description', () => {
function fn() {
// eslint-disable-next-line no-new
new DataType(<DataTypeSetup>{
new DataType({
name: 'example',
});
} as DataTypeSetup);
}

expect(fn).toThrowErrorMatchingSnapshot();
Expand Down
4 changes: 2 additions & 2 deletions src/engine/datatype/DataType.ts
Expand Up @@ -2,8 +2,8 @@ import { passOrThrow, isFunction } from '../util';
import { ComplexDataType } from './ComplexDataType';

export type DataTypeSetup = {
name: string;
description: string;
name?: string;
description?: string;
mock?: () => any;
validate?: () => any;
enforceRequired?: boolean;
Expand Down

0 comments on commit 2195720

Please sign in to comment.