Skip to content

Commit

Permalink
feat: create public api
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-guerin committed Nov 13, 2024
1 parent 9009cce commit 81eca0f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export interface HttpOfflineQueueContext {

/**
* @description
* The time to live of the queued request in milliseconds.
* @default 3600000
*/
timeToLive?: number;

/**
* @description
* The maximum number of requests that can be queued.
* @default 100
*/
maxQueueSize?: number;

/**
* @description
* The maximum number of times a queued request can be retried.
* @default 0
*/
maxRetryCount?: number;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { HttpOfflineQueueContext } from '../configuration/context/http-offline-queue-context.configuration';
import { HTTP_OFFLINE_QUEUE_METADATA_KEY, HttpOfflineQueue } from './http-offline-queue.decorator';

describe('HttpOfflineQueueDecorator', () => {

it('should place http offline queue context in metadata', () => {
const obj: unknown = {};
const context: HttpOfflineQueueContext = {
timeToLive: 6000
};

HttpOfflineQueue(context)(obj);
expect(Reflect.getMetadata(HTTP_OFFLINE_QUEUE_METADATA_KEY, obj)).toEqual(context);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { HttpOfflineQueueContext } from '../configuration/context/http-offline-queue-context.configuration';

/**
* @ignore
*/
export const HTTP_OFFLINE_QUEUE_METADATA_KEY: string = 'ngx-http-repository:http-offline-queue';

export function HttpOfflineQueue(params: HttpOfflineQueueContext): (target: unknown) => void {
return (target: unknown): void => {
Reflect.defineMetadata(HTTP_OFFLINE_QUEUE_METADATA_KEY, params, target);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function buildHttpRequestDecorator(params: string | HttpRequestParamsContext, re
}

/**
* Generate method to invoke Http Get request. By default HttpQueryFn but can be changed to HttpBodyFn (see withBody option)
* Generate method to invoke Http Get request. By default, HttpQueryFn but can be changed to HttpBodyFn (see withBody option)
* @param params path or full configuration object.
* @param responseType type of the response for deserialization.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export class HttpRepository<T, K> extends AbstractRepository<T> implements FindA
}

protected getResourceConfiguration(resourceType: Type<any>, configuration: ResourceConfiguration): ResourceConfiguration {
const config = mergeDeep(configuration, Reflect.getMetadata(HTTP_RESOURCE_METADATA_KEY, resourceType));
const config: ResourceConfiguration = mergeDeep(configuration, Reflect.getMetadata(HTTP_RESOURCE_METADATA_KEY, resourceType));

return createHttpRepositoryConfiguration(config);
}
Expand Down
2 changes: 2 additions & 0 deletions projects/ngx-http-repository/src/public-api.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
export { HttpHeaderContext } from './lib/configuration/context/http-header-context.configuration';
export { HttpQueryParamContext } from './lib/configuration/context/http-query-param-context.configuration';
export { HttpOfflineQueueContext } from './lib/configuration/context/http-offline-queue-context.configuration';
export * from './lib/configuration/context/http-request-params-context.configuration';

export { HttpHeader } from './lib/decorator/http-header.decorator';
export { HttpLiveResource } from './lib/decorator/http-live-resource.decorator';
export { HttpQueryParam } from './lib/decorator/http-query-param.decorator';
export { HttpResource } from './lib/decorator/http-resource.decorator';
export { OnHttpResourceChange } from './lib/decorator/on-http-resource-change.decorator';
export { HttpOfflineQueue } from './lib/decorator/http-offline-queue.decorator';
export * from './lib/decorator/http-request.decorator';

export { AfterExecuteHttpRequestEvent } from './lib/driver/event/after-execute-http-request.event';
Expand Down

0 comments on commit 81eca0f

Please sign in to comment.