Skip to content

Commit

Permalink
feat: adds services tree types
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Sep 14, 2019
1 parent f99a767 commit 1d5d7a7
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 4 deletions.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@
"husky": "^3.0.5",
"kpo": "^0.11.0",
"onchange": "^6.0.0",
"rxjs": "^6.5.3",
"typescript": "^3.6.3"
},
"dependencies": {},
"dependencies": {
"@types/json-schema": "^7.0.3"
},
"peerDependencies": {
"rxjs": "6.x"
},
"@pika/pack": {
"pipeline": [
[
Expand Down
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export default function main(): null {
return null;
}
export * from './types';
67 changes: 67 additions & 0 deletions src/types/collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { ErrorCode } from './error';
import { Schema } from './schema';
import { Observable } from './observable';

export type Element = Tree | Type | Service;
export type Tree = CollectionTree | ScopeTree;
export type Type = ErrorType | RequestType | ResponseType;
export type Service = QueryService | MutationService | SubscriptionService;

// Tree
export interface CollectionTree {
types: TreeTypes;
services: TreeServices;
scopes: { [key: string]: ScopeTree };
}
export interface ScopeTree {
services: TreeServices;
scopes: { [key: string]: ScopeTree };
}
export interface TreeTypes {
error: { [key: string]: ErrorType };
request: { [key: string]: RequestType };
response: { [key: string]: ResponseType };
}
export interface TreeServices {
query: { [key: string]: QueryService };
mutation: { [key: string]: MutationService };
subscription: { [key: string]: SubscriptionService };
}

// Types
export interface ErrorType {
code: ErrorCode;
}
export interface RequestType {
schema: Schema;
}
export interface ResponseType<T = any> {
schema: Schema;
children: ResponseTypeChildren<T>;
}
export interface ResponseTypeChildren<I = any> {
query: { [key: string]: QueryService<I> };
subscription: { [key: string]: SubscriptionService<I> };
}

// Services
export interface QueryService<I = any, O = any> {
types: ServiceTypes;
resolve(data: I, context: any): O | Promise<O>;
}
export interface MutationService<I = any, O = any> {
types: ServiceTypes;
resolve(data: I, context: any): O | Promise<O>;
}
export interface SubscriptionService<I = any, O = any> {
types: ServiceTypes;
resolve(
data: I,
context: any
): Observable<O | Promise<O>> | Promise<Observable<O | Promise<O>>>;
}
export interface ServiceTypes {
errors: string[];
request: string;
response: string;
}
17 changes: 17 additions & 0 deletions src/types/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export type ErrorCode = ClientErrorCode | ServerErrorCode;

export type ClientErrorCode =
| 'ClientError'
| 'ClientNotFound'
| 'ClientForbidden'
| 'ClientUnauthorized'
| 'ClientConflict'
| 'ClientUnsupported'
| 'ClientTooEarly'
| 'ClientRateLimit';

export type ServerErrorCode =
| 'ServerError'
| 'ServerNotImplemented'
| 'ServerUnavailable'
| 'ServerTimeout';
4 changes: 4 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './collection';
export * from './error';
export * from './observable';
export * from './schema';
1 change: 1 addition & 0 deletions src/types/observable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Observable } from 'rxjs';
3 changes: 3 additions & 0 deletions src/types/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { JSONSchema4 } from 'json-schema';

export type Schema = JSONSchema4;

0 comments on commit 1d5d7a7

Please sign in to comment.