Skip to content

Commit

Permalink
feat: added JSON types
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhaticus committed Nov 10, 2024
1 parent d2387db commit d496c9b
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/decorators/meta.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { buildSymbol } from '../utils/buildSymbol';
import { isValidKey } from '../utils/isValidKey';

import type { JSONAPIDataTypes } from '../types/dataTypes';
import type { JSONAPIDataTypes } from '../types/json/dataTypes';

export const metaSymbol = buildSymbol('meta');

Expand Down
4 changes: 0 additions & 4 deletions src/types/array.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/types/attributesObject.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type { JSONAPIObject } from "./object";
import type { JSONObject } from "./json/object";

export type JSONAPIAttributesObject = JSONAPIObject;
export type JSONAPIAttributesObject = JSONObject;
5 changes: 0 additions & 5 deletions src/types/dataTypes.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/types/errorObject.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { JSONAPILinkObject } from "./linkObject";
import type { JSONAPILinksObject } from "./linksObject";
import type { JSONAPIMetaObject } from "./metaObject";
import type { JSONAPIObject } from "./object";
import type { JSONObject } from "./json/object";
import type { Satisfies } from "./helpers/satisfies";

export type JSONAPIErrorObject = Satisfies<{
Expand All @@ -15,9 +15,9 @@ export type JSONAPIErrorObject = Satisfies<{
title: string;
detail: string;
source: {
pointer: JSONAPIObject;
pointer: JSONObject;
parameter: string;
header: string;
}
meta: JSONAPIMetaObject;
}, JSONAPIObject>;
}, JSONObject>;
5 changes: 1 addition & 4 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
export * from './array';
export * from './json';
export * from './attributesObject';
export * from './dataTypes';
export * from './linkObject';
export * from './linksObject';
export * from './metaObject';
export * from './object';
export * from './primitives';
export * from './relationshipsObject';
export * from './relationshipObject';
export * from './resourceObject';
Expand Down
4 changes: 4 additions & 0 deletions src/types/json/array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { JSONObject } from './object';
import type { JSONPrimitives } from './primitives';

export type JSONArray = JSONObject[] | JSONPrimitives[];
5 changes: 5 additions & 0 deletions src/types/json/dataTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { JSONArray } from './array';
import type { JSONObject } from './object';
import type { JSONPrimitives } from './primitives';

export type JSONDataTypes = JSONPrimitives | JSONArray | JSONObject;
4 changes: 4 additions & 0 deletions src/types/json/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './dataTypes';
export * from './primitives';
export * from './object';
export * from './array';
3 changes: 3 additions & 0 deletions src/types/json/object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { JSONDataTypes } from './dataTypes';

export type JSONObject = { [key: string]: JSONDataTypes };
1 change: 1 addition & 0 deletions src/types/json/primitives.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type JSONPrimitives = string | number | boolean | null;
8 changes: 8 additions & 0 deletions src/types/jsonApiObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Satisfies } from "./helpers/satisfies";
import type { JSONObject } from "./json/object";

export type JSONAPIObject = Satisfies<{
verison?: string;
ext?: string[];
profile?: string[];
}, JSONObject>;
4 changes: 2 additions & 2 deletions src/types/linkObject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { JSONAPIMetaObject } from './metaObject';
import type { JSONAPIObject } from './object';
import type { JSONObject } from './json/object';
import type { Satisfies } from './helpers/satisfies';

export type JSONAPILinkObject = Satisfies<
Expand All @@ -12,5 +12,5 @@ export type JSONAPILinkObject = Satisfies<
hreflang?: string;
meta?: JSONAPIMetaObject;
},
JSONAPIObject
JSONObject
>;
4 changes: 2 additions & 2 deletions src/types/linksObject.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { JSONAPIObject } from "./object";
import type { JSONObject } from "./json/object";
import type { Satisfies } from "./helpers/satisfies";

export type JSONAPILinksObject = Satisfies<{ [key: string]: string | JSONAPILinksObject | null }, JSONAPIObject>;
export type JSONAPILinksObject = Satisfies<{ [key: string]: string | JSONAPILinksObject | null }, JSONObject>;
4 changes: 2 additions & 2 deletions src/types/metaObject.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type { JSONAPIObject } from './object';
import type { JSONObject } from './json/object';

export type JSONAPIMetaObject = JSONAPIObject;
export type JSONAPIMetaObject = JSONObject;
3 changes: 0 additions & 3 deletions src/types/object.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/types/primitives.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/types/relationshipObject.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { JSONAPIResourceIdentifierObject } from "./resourceIdentifierObject";
import type { JSONAPILinksObject } from "./linksObject";
import type { JSONAPIMetaObject } from "./metaObject";
import type { JSONAPIObject } from "./object";
import type { JSONObject } from "./json/object";
import type { Satisfies } from "./helpers/satisfies";

export type JSONAPIRelationshipObject = Satisfies<{
data: JSONAPIResourceIdentifierObject;
links?: JSONAPILinksObject;
meta?: JSONAPIMetaObject;
}, JSONAPIObject>;
}, JSONObject>;
4 changes: 2 additions & 2 deletions src/types/relationshipsObject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { JSONAPIObject } from "./object";
import type { JSONObject } from "./json/object";
import type { Satisfies } from "./helpers/satisfies";
import type { JSONAPIRelationshipObject } from "./relationshipObject";

export type JSONAPIRelationshipsObject = Satisfies<{ [key: string]: JSONAPIRelationshipObject }, JSONAPIObject>;
export type JSONAPIRelationshipsObject = Satisfies<{ [key: string]: JSONAPIRelationshipObject }, JSONObject>;
4 changes: 2 additions & 2 deletions src/types/resourceIdentifierObject.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { JSONAPIObject } from "./object";
import type { JSONObject } from "./json/object";
import type { Satisfies } from "./helpers/satisfies";

export type JSONAPIResourceIdentifierObject = Satisfies<{
type: string;
} & (
{ id: string }
| { lid: string }
), JSONAPIObject>;
), JSONObject>;
4 changes: 2 additions & 2 deletions src/types/resourceObject.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { JSONAPIAttributesObject } from "./attributesObject";
import type { JSONAPILinksObject } from "./linksObject";
import type { JSONAPIMetaObject } from "./metaObject";
import type { JSONAPIObject } from "./object";
import type { JSONObject } from "./json/object";
import type { JSONAPIRelationshipsObject } from "./relationshipsObject";
import type { JSONAPILinkObject } from "./linkObject";
import type { Satisfies } from "./helpers/satisfies";
Expand All @@ -17,4 +17,4 @@ export type JSONAPIResourceObject = Satisfies<
};
meta?: JSONAPIMetaObject;
}
, JSONAPIObject>;
, JSONObject>;
11 changes: 4 additions & 7 deletions src/types/topLevelObject.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
import type { JSONAPIErrorObject } from "./errorObject";
import type { JSONAPILinksObject } from "./linksObject";
import type { JSONAPIMetaObject } from "./metaObject";
import type { JSONAPIObject } from "./object";
import type { JSONObject } from "./json/object";
import type { JSONAPIResourceObject } from "./resourceObject"
import type { JSONAPILinkObject } from "./linkObject";
import type { JSONAPIPaginationLinks } from "./paginationLinks";
import type { JSONAPIResourceIdentifierObject } from "./resourceIdentifierObject";
import type { Satisfies } from "./helpers/satisfies";
import type { JSONAPIObject } from "./jsonApiObject";

export type JSONAPITopLevelObject = Satisfies<({
data: JSONAPIResourceObject | JSONAPIResourceObject[] | JSONAPIResourceIdentifierObject | JSONAPIResourceIdentifierObject[] | null;
included?: JSONAPIResourceObject[];
} | {
errors: JSONAPIErrorObject[];
}) & {
jsonapi?: {
verison?: string;
ext?: string[];
profile?: string[];
},
jsonapi?: JSONAPIObject,
meta?: JSONAPIMetaObject;
links?: JSONAPILinksObject & {
self?: JSONAPILinkObject;
related?: JSONAPILinkObject;
describedby?: JSONAPILinkObject;
} & JSONAPIPaginationLinks;
}, JSONAPIObject>;
}, JSONObject>;

0 comments on commit d496c9b

Please sign in to comment.