rest-client-sdk
Advanced tools
Comparing version 5.0.0-rc.6 to 5.0.0-rc.7
# Changelog | ||
## 5.0.0-rc.7 | ||
### Changed | ||
- `config.authorizationType` is in fact optional (default to "Bearer"), so update the types accordingly | ||
- Update typescript-eslint and fix eslint issues | ||
- Make `SerializerInterace` and `Serializer` input and output understandable | ||
## 5.0.0-rc.6 | ||
@@ -4,0 +12,0 @@ |
@@ -12,4 +12,4 @@ import URI from 'urijs'; | ||
constructor(sdk: RestClientSdk<SdkMetadata>, metadata: ClassMetadata); | ||
getDefaultParameters(): object; | ||
getPathBase(pathParameters: object): string; | ||
getDefaultParameters(): Record<string, unknown>; | ||
getPathBase(pathParameters: Record<string, unknown>): string; | ||
getEntityURI(entity: D['entity']): string; | ||
@@ -20,45 +20,45 @@ /** | ||
* @param {string|number} id the entity identifier | ||
* @param {object} queryParam query parameters that will be added to the request | ||
* @param {object} pathParameters path parameters, will be pass to the `getPathBase` method | ||
* @param {object} requestParams parameters that will be send as second parameter to the `fetch` call | ||
* @param {Record<string, unknown>} queryParam query parameters that will be added to the request | ||
* @param {Record<string, unknown>} pathParameters path parameters, will be pass to the `getPathBase` method | ||
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call | ||
*/ | ||
find(id: string | number, queryParam?: {}, pathParameters?: {}, requestParams?: {}): Promise<D['entity']>; | ||
find(id: string | number, queryParam?: Record<string, unknown>, pathParameters?: Record<string, unknown>, requestParams?: Record<string, unknown>): Promise<D['entity']>; | ||
/** | ||
* get a list of entities by some parameters | ||
* | ||
* @param {object} queryParam query parameters that will be added to the request | ||
* @param {object} pathParameters path parameters, will be pass to the `getPathBase` method | ||
* @param {object} requestParams parameters that will be send as second parameter to the `fetch` call | ||
* @param {Record<string, unknown>} queryParam query parameters that will be added to the request | ||
* @param {Record<string, unknown>} pathParameters path parameters, will be pass to the `getPathBase` method | ||
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call | ||
*/ | ||
findBy(queryParam: object, pathParameters?: {}, requestParams?: {}): Promise<D['list']>; | ||
findBy(queryParam: Record<string, unknown>, pathParameters?: Record<string, unknown>, requestParams?: Record<string, unknown>): Promise<D['list']>; | ||
/** | ||
* get a list of all entities | ||
* | ||
* @param {object} queryParam query parameters that will be added to the request | ||
* @param {object} pathParameters path parameters, will be pass to the `getPathBase` method | ||
* @param {object} requestParams parameters that will be send as second parameter to the `fetch` call | ||
* @param {Record<string, unknown>} queryParam query parameters that will be added to the request | ||
* @param {Record<string, unknown>} pathParameters path parameters, will be pass to the `getPathBase` method | ||
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call | ||
*/ | ||
findAll(queryParam?: {}, pathParameters?: {}, requestParams?: {}): Promise<D['list']>; | ||
findAll(queryParam?: Record<string, unknown>, pathParameters?: Record<string, unknown>, requestParams?: Record<string, unknown>): Promise<D['list']>; | ||
/** | ||
* create an entity | ||
* | ||
* @param {object} entity the entity to persist | ||
* @param {object} queryParam query parameters that will be added to the request | ||
* @param {object} pathParameters path parameters, will be pass to the `getPathBase` method | ||
* @param {object} requestParams parameters that will be send as second parameter to the `fetch` call | ||
* @param {Record<string, unknown>} entity the entity to persist | ||
* @param {Record<string, unknown>} queryParam query parameters that will be added to the request | ||
* @param {Record<string, unknown>} pathParameters path parameters, will be pass to the `getPathBase` method | ||
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call | ||
*/ | ||
create(entity: D['entity'], queryParam?: {}, pathParameters?: {}, requestParams?: {}): Promise<D['entity']>; | ||
create(entity: D['entity'], queryParam?: Record<string, unknown>, pathParameters?: Record<string, unknown>, requestParams?: Record<string, unknown>): Promise<D['entity']>; | ||
/** | ||
* update an entity | ||
* | ||
* @param {object} entity the entity to update | ||
* @param {object} queryParam query parameters that will be added to the request | ||
* @param {object} requestParams parameters that will be send as second parameter to the `fetch` call | ||
* @param {Record<string, unknown>} entity the entity to update | ||
* @param {Record<string, unknown>} queryParam query parameters that will be added to the request | ||
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call | ||
*/ | ||
update(entity: D['entity'], queryParam?: {}, requestParams?: {}): Promise<D['entity']>; | ||
update(entity: D['entity'], queryParam?: Record<string, unknown>, requestParams?: Record<string, unknown>): Promise<D['entity']>; | ||
/** | ||
* delete an entity | ||
* | ||
* @param {object} the entity to delete | ||
* @param {object} requestParams parameters that will be send as second parameter to the `fetch` call | ||
* @param {Record<string, unknown>} the entity to delete | ||
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call | ||
*/ | ||
@@ -69,3 +69,3 @@ delete(entity: D['entity'], requestParams?: {}): Promise<Response>; | ||
authorizedFetch(input: string | URI, requestParams?: {}): Promise<Response>; | ||
_generateUrlFromParams(queryParam: object, pathParameters?: {}, id?: null | string | number): URI; | ||
_generateUrlFromParams(queryParam: Record<string, unknown>, pathParameters?: Record<string, unknown>, id?: null | string | number): URI; | ||
_fetchWithToken(input: string, requestParams?: {}): Promise<Response>; | ||
@@ -75,4 +75,4 @@ _refreshTokenAndRefetch(input: string, requestParams?: RequestInit): Promise<Response>; | ||
_doFetch(accessToken: null | string, input: string, requestParams: RequestInit): Promise<Response>; | ||
_getEntityIdentifier(object: object): null | string | number; | ||
_getEntityIdentifier(object: Record<string, unknown>): null | string | number; | ||
} | ||
export default AbstractClient; |
@@ -6,4 +6,4 @@ import ClassMetadata from './Mapping/ClassMetadata'; | ||
constructor(idPrefix?: string, config?: {}); | ||
getConfig(): object; | ||
setConfig(config: object): void; | ||
getConfig(): Record<string, unknown>; | ||
setConfig(config: Record<string, unknown>): void; | ||
setMapping(classMetadataList?: ClassMetadata[]): void; | ||
@@ -10,0 +10,0 @@ getMappingKeys(): string[]; |
@@ -12,3 +12,3 @@ import UnitOfWork from './UnitOfWork'; | ||
segment?: string; | ||
authorizationType: string; | ||
authorizationType?: string; | ||
useDefaultParameters?: boolean; | ||
@@ -15,0 +15,0 @@ }; |
import Serializer from './Serializer'; | ||
import ClassMetadata from '../Mapping/ClassMetadata'; | ||
declare class JsSerializer extends Serializer { | ||
encodeItem(object: object, classMetadata: ClassMetadata): string; | ||
decodeItem(rawData: string, classMetadata: ClassMetadata, response: Response): object; | ||
decodeList(rawListData: string, classMetadata: ClassMetadata, response: Response): object | object[]; | ||
encodeItem(object: Record<string, unknown>, classMetadata: ClassMetadata): string; | ||
decodeItem(rawData: string, classMetadata: ClassMetadata, response: Response): Record<string, unknown>; | ||
decodeList(rawListData: string, classMetadata: ClassMetadata, response: Response): Iterable<Record<string, unknown>>; | ||
} | ||
export default JsSerializer; |
@@ -1,2 +0,2 @@ | ||
import SerializerInterface from './SerializerInterface'; | ||
import SerializerInterface, { Entity, NormalizedObject, NormalizedList, EntityList } from './SerializerInterface'; | ||
import ClassMetadata from '../Mapping/ClassMetadata'; | ||
@@ -6,7 +6,7 @@ declare class Serializer implements SerializerInterface { | ||
* convert an entity to a plain javascript object | ||
* @param {any} entity - The entity to convert | ||
* @param {object} entity - The entity to convert | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
* @return {object} the object to serialize | ||
*/ | ||
normalizeItem(entity: object, classMetadata: ClassMetadata): object; | ||
normalizeItem(entity: Entity, classMetadata: ClassMetadata): NormalizedObject; | ||
/** | ||
@@ -18,3 +18,3 @@ * convert a plain javascript object to string | ||
*/ | ||
encodeItem(object: object, classMetadata: ClassMetadata): string; | ||
encodeItem(object: NormalizedObject, classMetadata: ClassMetadata): string; | ||
/** | ||
@@ -26,11 +26,11 @@ * convert an entity to string that will be sent as the request content | ||
*/ | ||
serializeItem(object: object, classMetadata: ClassMetadata): string; | ||
serializeItem(object: Entity, classMetadata: ClassMetadata): string; | ||
/** | ||
* convert a plain object to an entity | ||
* @param {string} object - The plain javascript object | ||
* @param {object} object - The plain javascript object | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
* @param {object} response - the HTTP response | ||
* @return {any} an entity | ||
* @param {Record<string, unknown>} response - the HTTP response | ||
* @return {object} an entity | ||
*/ | ||
denormalizeItem(object: object, classMetadata: ClassMetadata, response: Response): object; | ||
denormalizeItem(object: NormalizedObject, classMetadata: ClassMetadata, response: Response): Entity; | ||
/** | ||
@@ -40,6 +40,6 @@ * convert a string containing an object to a plain javascript object | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
* @param {object} response - the HTTP response | ||
* @param {Record<string, unknown>} response - the HTTP response | ||
* @return {object} the normalized object | ||
*/ | ||
decodeItem(rawData: string, classMetadata: ClassMetadata, response: Response): object; | ||
decodeItem(rawData: string, classMetadata: ClassMetadata, response: Response): NormalizedObject; | ||
/** | ||
@@ -49,14 +49,14 @@ * convert a string containing an object to an entity | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
* @param {object} response - the HTTP response | ||
* @param {Record<string, unknown>} response - the HTTP response | ||
* @return {object} the entity | ||
*/ | ||
deserializeItem(rawData: string, classMetadata: ClassMetadata, response: Response): object; | ||
deserializeItem(rawData: string, classMetadata: ClassMetadata, response: Response): Entity; | ||
/** | ||
* convert a plain object list to an entity list | ||
* @param {object|object[]} objectList - The plain javascript object list (or an iterable object) | ||
* @param {Iterable<object>} objectList - The plain javascript object list (or an iterable object) | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
* @param {object} response - the HTTP response | ||
* @return {object | object[]} a list of entities | ||
* @param {Record<string, unknown>} response - the HTTP response | ||
* @return {Iterable<object>} a list of entities | ||
*/ | ||
denormalizeList(objectList: object | object[], classMetadata: ClassMetadata, response: Response): object | object[]; | ||
denormalizeList(objectList: NormalizedList, classMetadata: ClassMetadata, response: Response): EntityList; | ||
/** | ||
@@ -66,6 +66,6 @@ * convert a string containing a list of objects to a list of plain javascript objects | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
* @param {object} response - the HTTP response | ||
* @return {any} a list of normalized objects | ||
* @param {Record<string, unknown>} response - the HTTP response | ||
* @return {Iterable<object>} a list of normalized objects | ||
*/ | ||
decodeList(rawListData: string, classMetadata: ClassMetadata, response: Response): object | object[]; | ||
decodeList(rawListData: string, classMetadata: ClassMetadata, response: Response): NormalizedList; | ||
/** | ||
@@ -75,7 +75,7 @@ * convert a string containing a list of objects to a list of entities | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
* @param {object} response - the HTTP response | ||
* @return {any} a list of entities | ||
* @param {Record<string, unknown>} response - the HTTP response | ||
* @return {Iterable<object>} a list of entities | ||
*/ | ||
deserializeList(rawListData: string, classMetadata: ClassMetadata, response: Response): object | object[]; | ||
deserializeList(rawListData: string, classMetadata: ClassMetadata, response: Response): EntityList; | ||
} | ||
export default Serializer; |
import ClassMetadata from '../Mapping/ClassMetadata'; | ||
export declare type Entity = Record<string, unknown>; | ||
export declare type NormalizedObject = Record<string, unknown>; | ||
export declare type NormalizedList = Iterable<Record<string, unknown>>; | ||
export declare type EntityList = Iterable<Entity>; | ||
export default interface SerializerInterface { | ||
@@ -9,3 +13,3 @@ /** | ||
*/ | ||
normalizeItem(entity: object, classMetadata: ClassMetadata): object; | ||
normalizeItem(entity: Entity, classMetadata: ClassMetadata): NormalizedObject; | ||
/** | ||
@@ -17,6 +21,6 @@ * convert a plain javascript object to string | ||
*/ | ||
encodeItem(object: object, classMetadata: ClassMetadata): string; | ||
encodeItem(object: NormalizedObject, classMetadata: ClassMetadata): string; | ||
/** | ||
* convert a plain object to an entity | ||
* @param {string} object - The plain javascript object | ||
* @param {object} object - The plain javascript object | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
@@ -26,3 +30,3 @@ * @param {object} response - the HTTP response | ||
*/ | ||
denormalizeItem(object: object, classMetadata: ClassMetadata, response: Response): object; | ||
denormalizeItem(object: NormalizedObject, classMetadata: ClassMetadata, response: Response): Entity; | ||
/** | ||
@@ -35,11 +39,11 @@ * convert a string containing an object to a plain javascript object | ||
*/ | ||
decodeItem(rawData: string, classMetadata: ClassMetadata, response: Response): object; | ||
decodeItem(rawData: string, classMetadata: ClassMetadata, response: Response): NormalizedObject; | ||
/** | ||
* convert a plain object list to an entity list | ||
* @param {object|object[]} objectList - The plain javascript object list (or an iterable object) | ||
* @param {Iterable<object>} objectList - The plain javascript object list (or an iterable object) | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
* @param {object} response - the HTTP response | ||
* @return {object | object[]} a list of entities | ||
* @return {Iterable<object>} a list of entities | ||
*/ | ||
denormalizeList(objectList: object | object[], classMetadata: ClassMetadata, response: Response): object | object[]; | ||
denormalizeList(objectList: NormalizedList, classMetadata: ClassMetadata, response: Response): EntityList; | ||
/** | ||
@@ -50,5 +54,5 @@ * convert a string containing a list of objects to a list of plain javascript objects | ||
* @param {object} response - the HTTP response | ||
* @return {object|object[]} a list of normalized objects or an iterable object containint the list | ||
* @return {Iterable<object>} a list of normalized objects or an iterable object containint the list | ||
*/ | ||
decodeList(rawListData: string, classMetadata: ClassMetadata, response: Response): object | object[]; | ||
decodeList(rawListData: string, classMetadata: ClassMetadata, response: Response): NormalizedList; | ||
/** | ||
@@ -59,5 +63,5 @@ * convert a string containing a list of objects to a list of entities | ||
* @param {object} response - the HTTP response | ||
* @return {L} a list of entities | ||
* @return {Iterable<object>} a list of entities | ||
*/ | ||
deserializeList(rawListData: string, classMetadata: ClassMetadata, response: Response): object | object[]; | ||
deserializeList(rawListData: string, classMetadata: ClassMetadata, response: Response): EntityList; | ||
} |
@@ -13,5 +13,6 @@ import TokenGeneratorInterface from './TokenGeneratorInterface'; | ||
}; | ||
declare type RefreshTokenFunc = () => Promise<ProvidedToken>; | ||
declare class ProvidedTokenGenerator implements TokenGeneratorInterface<ProvidedToken> { | ||
#private; | ||
constructor(token: string, refreshTokenFunc?: null | Function); | ||
constructor(token: string, refreshTokenFunc?: null | RefreshTokenFunc); | ||
generateToken(parameters: Parameters): Promise<ProvidedToken>; | ||
@@ -18,0 +19,0 @@ refreshToken(accessToken: ProvidedToken): Promise<ProvidedToken>; |
@@ -5,5 +5,3 @@ import Mapping from './Mapping'; | ||
declare type Id = string | number; | ||
declare type StringKeyObject = { | ||
[key: string]: any; | ||
}; | ||
declare type StringKeyObject = Record<string, any>; | ||
declare class UnitOfWork { | ||
@@ -13,8 +11,8 @@ #private; | ||
constructor(mapping: Mapping); | ||
registerClean(id: Id, entity: object): void; | ||
getDirtyEntity(id: Id): object; | ||
registerClean(id: Id, entity: Record<string, unknown>): void; | ||
getDirtyEntity(id: Id): Record<string, unknown>; | ||
clear(id: Id): void; | ||
getDirtyData(newSerializedModel: object, oldSerializedModel: object, classMetadata: ClassMetadata): StringKeyObject; | ||
_getDirtyFieldsForAttribute(dirtyFieldsParam: StringKeyObject, key: string, attribute: Attribute, oldValue: object, newValue: object): StringKeyObject; | ||
_getDirtyFieldsForManyToOne(dirtyFieldsParam: StringKeyObject, key: string, oldValue: object, newValue: object, relationMetadata: ClassMetadata, idSerializedKey: string): StringKeyObject; | ||
getDirtyData(newSerializedModel: Record<string, unknown>, oldSerializedModel: Record<string, unknown>, classMetadata: ClassMetadata): StringKeyObject; | ||
_getDirtyFieldsForAttribute(dirtyFieldsParam: StringKeyObject, key: string, attribute: Attribute, oldValue: Record<string, unknown>, newValue: Record<string, unknown>): StringKeyObject; | ||
_getDirtyFieldsForManyToOne(dirtyFieldsParam: StringKeyObject, key: string, oldValue: Record<string, unknown>, newValue: Record<string, unknown>, relationMetadata: ClassMetadata, idSerializedKey: string): StringKeyObject; | ||
_getDirtyFieldsForOneToMany(dirtyFieldsParam: StringKeyObject, key: string, idSerializedKey: string, relationMetadata: ClassMetadata, oldValue: any[], newValue: any[]): StringKeyObject; | ||
@@ -21,0 +19,0 @@ _getDirtyFields(newSerializedModel: StringKeyObject, oldSerializedModel: StringKeyObject, classMetadata: ClassMetadata): StringKeyObject; |
{ | ||
"name": "rest-client-sdk", | ||
"version": "5.0.0-rc.6", | ||
"version": "5.0.0-rc.7", | ||
"description": "Rest Client SDK for API", | ||
@@ -31,11 +31,11 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.0.0", | ||
"@babel/plugin-proposal-class-properties": "^7.8.3", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.9.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"@babel/preset-typescript": "^7.9.0", | ||
"@babel/core": "^7.10.5", | ||
"@babel/plugin-proposal-class-properties": "^7.10.4", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.10.4", | ||
"@babel/preset-env": "^7.10.4", | ||
"@babel/preset-typescript": "^7.10.4", | ||
"@types/deep-diff": "^1.0.0", | ||
"@types/urijs": "^1.19.9", | ||
"@typescript-eslint/eslint-plugin": "^2.26.0", | ||
"@typescript-eslint/parser": "^2.26.0", | ||
"@typescript-eslint/eslint-plugin": "^3.6.1", | ||
"@typescript-eslint/parser": "^3.6.1", | ||
"babel-jest": "^25.2.6", | ||
@@ -42,0 +42,0 @@ "bundlesize": "^0.18.0", |
@@ -31,3 +31,3 @@ import URI from 'urijs'; | ||
getDefaultParameters(): object { | ||
getDefaultParameters(): Record<string, unknown> { | ||
return {}; | ||
@@ -37,3 +37,3 @@ } | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
getPathBase(pathParameters: object): string { | ||
getPathBase(pathParameters: Record<string, unknown>): string { | ||
return `/${this.metadata.pathRoot}`; | ||
@@ -68,11 +68,11 @@ } | ||
* @param {string|number} id the entity identifier | ||
* @param {object} queryParam query parameters that will be added to the request | ||
* @param {object} pathParameters path parameters, will be pass to the `getPathBase` method | ||
* @param {object} requestParams parameters that will be send as second parameter to the `fetch` call | ||
* @param {Record<string, unknown>} queryParam query parameters that will be added to the request | ||
* @param {Record<string, unknown>} pathParameters path parameters, will be pass to the `getPathBase` method | ||
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call | ||
*/ | ||
find( | ||
id: string | number, | ||
queryParam = {}, | ||
pathParameters = {}, | ||
requestParams = {} | ||
queryParam: Record<string, unknown> = {}, | ||
pathParameters: Record<string, unknown> = {}, | ||
requestParams: Record<string, unknown> = {} | ||
): Promise<D['entity']> { | ||
@@ -90,10 +90,10 @@ const url = this._generateUrlFromParams(queryParam, pathParameters, id); | ||
* | ||
* @param {object} queryParam query parameters that will be added to the request | ||
* @param {object} pathParameters path parameters, will be pass to the `getPathBase` method | ||
* @param {object} requestParams parameters that will be send as second parameter to the `fetch` call | ||
* @param {Record<string, unknown>} queryParam query parameters that will be added to the request | ||
* @param {Record<string, unknown>} pathParameters path parameters, will be pass to the `getPathBase` method | ||
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call | ||
*/ | ||
findBy( | ||
queryParam: object, | ||
pathParameters = {}, | ||
requestParams = {} | ||
queryParam: Record<string, unknown>, | ||
pathParameters: Record<string, unknown> = {}, | ||
requestParams: Record<string, unknown> = {} | ||
): Promise<D['list']> { | ||
@@ -111,10 +111,10 @@ const url = this._generateUrlFromParams(queryParam, pathParameters); | ||
* | ||
* @param {object} queryParam query parameters that will be added to the request | ||
* @param {object} pathParameters path parameters, will be pass to the `getPathBase` method | ||
* @param {object} requestParams parameters that will be send as second parameter to the `fetch` call | ||
* @param {Record<string, unknown>} queryParam query parameters that will be added to the request | ||
* @param {Record<string, unknown>} pathParameters path parameters, will be pass to the `getPathBase` method | ||
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call | ||
*/ | ||
findAll( | ||
queryParam = {}, | ||
pathParameters = {}, | ||
requestParams = {} | ||
queryParam: Record<string, unknown> = {}, | ||
pathParameters: Record<string, unknown> = {}, | ||
requestParams: Record<string, unknown> = {} | ||
): Promise<D['list']> { | ||
@@ -127,12 +127,12 @@ return this.findBy(queryParam, pathParameters, requestParams); | ||
* | ||
* @param {object} entity the entity to persist | ||
* @param {object} queryParam query parameters that will be added to the request | ||
* @param {object} pathParameters path parameters, will be pass to the `getPathBase` method | ||
* @param {object} requestParams parameters that will be send as second parameter to the `fetch` call | ||
* @param {Record<string, unknown>} entity the entity to persist | ||
* @param {Record<string, unknown>} queryParam query parameters that will be added to the request | ||
* @param {Record<string, unknown>} pathParameters path parameters, will be pass to the `getPathBase` method | ||
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call | ||
*/ | ||
create( | ||
entity: D['entity'], | ||
queryParam = {}, | ||
pathParameters = {}, | ||
requestParams = {} | ||
queryParam: Record<string, unknown> = {}, | ||
pathParameters: Record<string, unknown> = {}, | ||
requestParams: Record<string, unknown> = {} | ||
): Promise<D['entity']> { | ||
@@ -167,10 +167,10 @@ const url = new URI(this.getPathBase(pathParameters)); | ||
* | ||
* @param {object} entity the entity to update | ||
* @param {object} queryParam query parameters that will be added to the request | ||
* @param {object} requestParams parameters that will be send as second parameter to the `fetch` call | ||
* @param {Record<string, unknown>} entity the entity to update | ||
* @param {Record<string, unknown>} queryParam query parameters that will be added to the request | ||
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call | ||
*/ | ||
update( | ||
entity: D['entity'], | ||
queryParam = {}, | ||
requestParams = {} | ||
queryParam: Record<string, unknown> = {}, | ||
requestParams: Record<string, unknown> = {} | ||
): Promise<D['entity']> { | ||
@@ -212,4 +212,4 @@ const url = new URI(this.getEntityURI(entity)); | ||
* | ||
* @param {object} the entity to delete | ||
* @param {object} requestParams parameters that will be send as second parameter to the `fetch` call | ||
* @param {Record<string, unknown>} the entity to delete | ||
* @param {Record<string, unknown>} requestParams parameters that will be send as second parameter to the `fetch` call | ||
*/ | ||
@@ -318,4 +318,4 @@ delete(entity: D['entity'], requestParams = {}): Promise<Response> { | ||
_generateUrlFromParams( | ||
queryParam: object, | ||
pathParameters = {}, | ||
queryParam: Record<string, unknown>, | ||
pathParameters: Record<string, unknown> = {}, | ||
id: null | string | number = null | ||
@@ -486,6 +486,8 @@ ): URI { | ||
_getEntityIdentifier(object: object): null | string | number { | ||
_getEntityIdentifier( | ||
object: Record<string, unknown> | ||
): null | string | number { | ||
const idKey = this.metadata.getIdentifierAttribute().serializedKey; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
@@ -492,0 +494,0 @@ return object[idKey]; |
@@ -1,2 +0,2 @@ | ||
/* eslint-disable max-classes-per-file, @typescript-eslint/no-use-before-define */ | ||
/* eslint-disable max-classes-per-file, no-use-before-define */ | ||
/** | ||
@@ -3,0 +3,0 @@ * It's a bit tricky to extends native errors |
@@ -10,3 +10,3 @@ import ClassMetadata from './Mapping/ClassMetadata'; | ||
#config!: object; | ||
#config!: Record<string, unknown>; | ||
@@ -23,7 +23,7 @@ #classMetadataList: ClassMetadata[]; | ||
getConfig(): object { | ||
getConfig(): Record<string, unknown> { | ||
return this.#config; | ||
} | ||
setConfig(config: object): void { | ||
setConfig(config: Record<string, unknown>): void { | ||
this.#config = { ...DEFAULT_CONFIG, ...config }; | ||
@@ -30,0 +30,0 @@ } |
@@ -14,3 +14,3 @@ import JsSerializer from './serializer/JsSerializer'; | ||
segment?: string; | ||
authorizationType: string; // default to "Bearer", but can be "Basic" or anything | ||
authorizationType?: string; // default to "Bearer", but can be "Basic" or anything | ||
useDefaultParameters?: boolean; | ||
@@ -17,0 +17,0 @@ }; |
@@ -6,3 +6,6 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
class JsSerializer extends Serializer { | ||
encodeItem(object: object, classMetadata: ClassMetadata): string { | ||
encodeItem( | ||
object: Record<string, unknown>, | ||
classMetadata: ClassMetadata | ||
): string { | ||
return JSON.stringify(object); | ||
@@ -15,3 +18,3 @@ } | ||
response: Response | ||
): object { | ||
): Record<string, unknown> { | ||
return JSON.parse(rawData); | ||
@@ -24,3 +27,3 @@ } | ||
response: Response | ||
): object | object[] { | ||
): Iterable<Record<string, unknown>> { | ||
return JSON.parse(rawListData); | ||
@@ -27,0 +30,0 @@ } |
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import SerializerInterface from './SerializerInterface'; | ||
import SerializerInterface, { | ||
Entity, | ||
NormalizedObject, | ||
NormalizedList, | ||
EntityList, | ||
} from './SerializerInterface'; | ||
import ClassMetadata from '../Mapping/ClassMetadata'; | ||
@@ -8,7 +13,10 @@ | ||
* convert an entity to a plain javascript object | ||
* @param {any} entity - The entity to convert | ||
* @param {object} entity - The entity to convert | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
* @return {object} the object to serialize | ||
*/ | ||
normalizeItem(entity: object, classMetadata: ClassMetadata): object { | ||
normalizeItem( | ||
entity: Entity, | ||
classMetadata: ClassMetadata | ||
): NormalizedObject { | ||
return entity; | ||
@@ -23,3 +31,3 @@ } | ||
*/ | ||
encodeItem(object: object, classMetadata: ClassMetadata): string { | ||
encodeItem(object: NormalizedObject, classMetadata: ClassMetadata): string { | ||
throw new TypeError('`encodeItem` method must be implemented'); | ||
@@ -34,3 +42,3 @@ } | ||
*/ | ||
serializeItem(object: object, classMetadata: ClassMetadata): string { | ||
serializeItem(object: Entity, classMetadata: ClassMetadata): string { | ||
const noralizedData = this.normalizeItem(object, classMetadata); | ||
@@ -42,12 +50,12 @@ return this.encodeItem(noralizedData, classMetadata); | ||
* convert a plain object to an entity | ||
* @param {string} object - The plain javascript object | ||
* @param {object} object - The plain javascript object | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
* @param {object} response - the HTTP response | ||
* @return {any} an entity | ||
* @param {Record<string, unknown>} response - the HTTP response | ||
* @return {object} an entity | ||
*/ | ||
denormalizeItem( | ||
object: object, | ||
object: NormalizedObject, | ||
classMetadata: ClassMetadata, | ||
response: Response | ||
): object { | ||
): Entity { | ||
return object; | ||
@@ -60,3 +68,3 @@ } | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
* @param {object} response - the HTTP response | ||
* @param {Record<string, unknown>} response - the HTTP response | ||
* @return {object} the normalized object | ||
@@ -68,3 +76,3 @@ */ | ||
response: Response | ||
): object { | ||
): NormalizedObject { | ||
throw new TypeError('`decodeItem` method must be implemented'); | ||
@@ -77,3 +85,3 @@ } | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
* @param {object} response - the HTTP response | ||
* @param {Record<string, unknown>} response - the HTTP response | ||
* @return {object} the entity | ||
@@ -85,3 +93,3 @@ */ | ||
response: Response | ||
): object { | ||
): Entity { | ||
const object = this.decodeItem(rawData, classMetadata, response); | ||
@@ -93,12 +101,12 @@ return this.denormalizeItem(object, classMetadata, response); | ||
* convert a plain object list to an entity list | ||
* @param {object|object[]} objectList - The plain javascript object list (or an iterable object) | ||
* @param {Iterable<object>} objectList - The plain javascript object list (or an iterable object) | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
* @param {object} response - the HTTP response | ||
* @return {object | object[]} a list of entities | ||
* @param {Record<string, unknown>} response - the HTTP response | ||
* @return {Iterable<object>} a list of entities | ||
*/ | ||
denormalizeList( | ||
objectList: object | object[], | ||
objectList: NormalizedList, | ||
classMetadata: ClassMetadata, | ||
response: Response | ||
): object | object[] { | ||
): EntityList { | ||
return objectList; // weird conversion as the declaration of list type is fuzzy | ||
@@ -111,4 +119,4 @@ } | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
* @param {object} response - the HTTP response | ||
* @return {any} a list of normalized objects | ||
* @param {Record<string, unknown>} response - the HTTP response | ||
* @return {Iterable<object>} a list of normalized objects | ||
*/ | ||
@@ -119,3 +127,3 @@ decodeList( | ||
response: Response | ||
): object | object[] { | ||
): NormalizedList { | ||
throw new TypeError('`deserializeList` method must be implemented'); | ||
@@ -128,4 +136,4 @@ } | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
* @param {object} response - the HTTP response | ||
* @return {any} a list of entities | ||
* @param {Record<string, unknown>} response - the HTTP response | ||
* @return {Iterable<object>} a list of entities | ||
*/ | ||
@@ -136,3 +144,3 @@ deserializeList( | ||
response: Response | ||
): object | object[] { | ||
): EntityList { | ||
const objectList = this.decodeList(rawListData, classMetadata, response); | ||
@@ -139,0 +147,0 @@ return this.denormalizeList(objectList, classMetadata, response); |
import ClassMetadata from '../Mapping/ClassMetadata'; | ||
export type Entity = Record<string, unknown>; | ||
export type NormalizedObject = Record<string, unknown>; | ||
export type NormalizedList = Iterable<Record<string, unknown>>; | ||
export type EntityList = Iterable<Entity>; | ||
export default interface SerializerInterface { | ||
@@ -10,3 +15,3 @@ /** | ||
*/ | ||
normalizeItem(entity: object, classMetadata: ClassMetadata): object; | ||
normalizeItem(entity: Entity, classMetadata: ClassMetadata): NormalizedObject; | ||
@@ -19,7 +24,7 @@ /** | ||
*/ | ||
encodeItem(object: object, classMetadata: ClassMetadata): string; | ||
encodeItem(object: NormalizedObject, classMetadata: ClassMetadata): string; | ||
/** | ||
* convert a plain object to an entity | ||
* @param {string} object - The plain javascript object | ||
* @param {object} object - The plain javascript object | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
@@ -30,6 +35,6 @@ * @param {object} response - the HTTP response | ||
denormalizeItem( | ||
object: object, | ||
object: NormalizedObject, | ||
classMetadata: ClassMetadata, | ||
response: Response | ||
): object; | ||
): Entity; | ||
@@ -47,16 +52,16 @@ /** | ||
response: Response | ||
): object; | ||
): NormalizedObject; | ||
/** | ||
* convert a plain object list to an entity list | ||
* @param {object|object[]} objectList - The plain javascript object list (or an iterable object) | ||
* @param {Iterable<object>} objectList - The plain javascript object list (or an iterable object) | ||
* @param {ClassMetadata} classMetadata - the class metadata | ||
* @param {object} response - the HTTP response | ||
* @return {object | object[]} a list of entities | ||
* @return {Iterable<object>} a list of entities | ||
*/ | ||
denormalizeList( | ||
objectList: object | object[], | ||
objectList: NormalizedList, | ||
classMetadata: ClassMetadata, | ||
response: Response | ||
): object | object[]; | ||
): EntityList; | ||
@@ -68,3 +73,3 @@ /** | ||
* @param {object} response - the HTTP response | ||
* @return {object|object[]} a list of normalized objects or an iterable object containint the list | ||
* @return {Iterable<object>} a list of normalized objects or an iterable object containint the list | ||
*/ | ||
@@ -75,3 +80,3 @@ decodeList( | ||
response: Response | ||
): object | object[]; | ||
): NormalizedList; | ||
@@ -83,3 +88,3 @@ /** | ||
* @param {object} response - the HTTP response | ||
* @return {L} a list of entities | ||
* @return {Iterable<object>} a list of entities | ||
*/ | ||
@@ -90,3 +95,3 @@ deserializeList( | ||
response: Response | ||
): object | object[]; | ||
): EntityList; | ||
} |
@@ -1,2 +0,2 @@ | ||
/* eslint-disable @typescript-eslint/camelcase */ | ||
/* eslint-disable camelcase */ | ||
import URI from 'urijs'; | ||
@@ -3,0 +3,0 @@ import AbstractTokenGenerator from './AbstractTokenGenerator'; |
@@ -1,2 +0,2 @@ | ||
/* eslint-disable @typescript-eslint/camelcase */ | ||
/* eslint-disable camelcase */ | ||
import URI from 'urijs'; | ||
@@ -3,0 +3,0 @@ import AbstractTokenGenerator from './AbstractTokenGenerator'; |
@@ -1,2 +0,2 @@ | ||
/* eslint-disable @typescript-eslint/camelcase */ | ||
/* eslint-disable camelcase */ | ||
import TokenGeneratorInterface from './TokenGeneratorInterface'; | ||
@@ -17,8 +17,10 @@ import { Token } from './types'; | ||
type RefreshTokenFunc = () => Promise<ProvidedToken>; | ||
class ProvidedTokenGenerator implements TokenGeneratorInterface<ProvidedToken> { | ||
#token: string; | ||
#refreshTokenFunc: null | Function; | ||
#refreshTokenFunc: null | RefreshTokenFunc; | ||
constructor(token: string, refreshTokenFunc: null | Function = null) { | ||
constructor(token: string, refreshTokenFunc: null | RefreshTokenFunc = null) { | ||
this.#token = token; | ||
@@ -25,0 +27,0 @@ this.#refreshTokenFunc = refreshTokenFunc; |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable camelcase */ | ||
export interface Token { | ||
@@ -2,0 +3,0 @@ access_token: string; |
@@ -1,2 +0,2 @@ | ||
/* eslint-disable @typescript-eslint/camelcase */ | ||
/* eslint-disable camelcase */ | ||
import TokenGeneratorInterface from './TokenGenerator/TokenGeneratorInterface'; | ||
@@ -3,0 +3,0 @@ import { Token, TokenGeneratorParameters } from './TokenGenerator/types'; |
@@ -11,3 +11,3 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
type Id = string | number; | ||
type StringKeyObject = { [key: string]: any }; | ||
type StringKeyObject = Record<string, any>; | ||
@@ -17,3 +17,6 @@ /** | ||
*/ | ||
function objectDiffers(left: object, right: object): boolean { | ||
function objectDiffers( | ||
left: Record<string, unknown>, | ||
right: Record<string, unknown> | ||
): boolean { | ||
const result = diff(left, right); | ||
@@ -28,3 +31,3 @@ | ||
function getEntityId( | ||
stringOrEntity: string | object, | ||
stringOrEntity: string | Record<string, unknown>, | ||
idSerializedKey: string | ||
@@ -36,3 +39,3 @@ ): Id { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
@@ -52,2 +55,4 @@ return stringOrEntity[idSerializedKey] as Id; | ||
const idSerializedKey = classMetadata.getIdentifierAttribute().serializedKey; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
const relationValueId = getEntityId(newRelationValue, idSerializedKey); | ||
@@ -100,3 +105,3 @@ | ||
#storage: { [key in Id]: object }; | ||
#storage: { [key in Id]: Record<string, unknown> }; | ||
@@ -109,3 +114,3 @@ constructor(mapping: Mapping) { | ||
registerClean(id: Id, entity: object): void { | ||
registerClean(id: Id, entity: Record<string, unknown>): void { | ||
if (isImmutable(entity)) { | ||
@@ -118,3 +123,3 @@ this.#storage[id] = entity; | ||
getDirtyEntity(id: Id): object { | ||
getDirtyEntity(id: Id): Record<string, unknown> { | ||
return this.#storage[id]; | ||
@@ -128,4 +133,4 @@ } | ||
getDirtyData( | ||
newSerializedModel: object, | ||
oldSerializedModel: object, | ||
newSerializedModel: Record<string, unknown>, | ||
oldSerializedModel: Record<string, unknown>, | ||
classMetadata: ClassMetadata | ||
@@ -144,4 +149,4 @@ ): StringKeyObject { | ||
attribute: Attribute, | ||
oldValue: object, | ||
newValue: object | ||
oldValue: Record<string, unknown>, | ||
newValue: Record<string, unknown> | ||
): StringKeyObject { | ||
@@ -164,4 +169,4 @@ const dirtyFields = dirtyFieldsParam; | ||
key: string, | ||
oldValue: object, | ||
newValue: object, | ||
oldValue: Record<string, unknown>, | ||
newValue: Record<string, unknown>, | ||
relationMetadata: ClassMetadata, | ||
@@ -168,0 +173,0 @@ idSerializedKey: string |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
526659
6867