Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@equinor/fusion-framework-module-services

Package Overview
Dependencies
Maintainers
0
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@equinor/fusion-framework-module-services - npm Package Compare versions

Comparing version 5.0.0-next-663bed8344cc2ca0111705b05045173328b3104d to 5.0.0

dist/esm/bookmarks/api-version.js

195

dist/esm/bookmarks/client.js

@@ -1,10 +0,59 @@

import deleteBookmark from './delete/client';
import getBookmark from './get/client';
import postBookmark from './post/client';
import patchBookmark from './patch';
import getAllBookmarks from './getAll';
import addBookmarkFavorite from './favorites/post';
import deleteBookmarkFavorite from './favorites/delete';
import verifyBookmarkFavorite from './favorites/head';
import { getBookmarks, } from './endpoints/user-bookmarks.get';
import { getBookmark, } from './endpoints/bookmark.get';
import { createBookmark, } from './endpoints/bookmark.post';
import { patchBookmark, } from './endpoints/bookmark.patch';
import { getBookmarkApply, } from './endpoints/bookmark-apply.get';
import { addBookmarkAsFavourite, } from './endpoints/user-bookmark-favourite.post';
import { deleteBookmark, } from './endpoints/bookmark.delete';
import { isFavoriteBookmark, } from './endpoints/user-bookmark-favourite.head';
import { removeFavoriteBookmark, } from './endpoints/user-bookmark-favourite.delete';
/**
* Provides a client interface for interacting with the bookmarks API.
* This class abstracts the details of making API requests and handling responses.
* It provides methods for fetching, creating, updating, and deleting bookmarks,
* as well as managing bookmark favorites.
*
* @example
* ```typescript
* import { BookmarksApiClient } from '@equinor/fusion';
* import { HttpClient } from '@equinor/fusion-framework-module-http';
*
* const httpClient = new HttpClient({ baseUri: 'https://my-bookmarks-api.com/' });
*
* // create a bookmarks API client using a custom HTTP client
* const client = new BookmarksApiClient(httpClient, 'json');
*
* // fetch a bookmark by its ID
* const bookmark = await client.getBookmark('my-bookmark-id');
*
* // fetch all bookmarks for the current user
* const bookmarks = await client.query();
*
* // update a bookmark by its ID
* await client.patch({
* bookmarkId: 'my-bookmark-id',
* data: {
* name: 'new-name'
* payload: { foo: 'bar' }
* }
* });
*
* // delete a bookmark by its ID
* await client.deleteBookmark('my-bookmark-id');
*
* // add or remove a bookmark to the current user's favorites
* await client.addFavorite({ bookmarkId:'my-bookmark-id' });
* await client.removeFavorite({ bookmarkId:'my-bookmark-id' });
* ```
*
* @template TMethod - The client method to use for the request, defaults to 'json'.
* @template TClient - The HTTP client to use for executing the request.
*/
export class BookmarksApiClient {
/**
* Constructs a new instance of the BookmarksClient class.
*
* @param _client - The client instance to use for making API requests.
* @param _method - The client method to use for API requests.
*/
constructor(_client, _method) {

@@ -15,69 +64,121 @@ this._client = _client;

/**
* Fetch bookmark by id
* @see {@link get/client}
* Fetch a single bookmark
*
* @template TVersion - The version of the API to call
* @template TResponse - The type of the result of the `getBookmark` function
* @param version - The API version to use
* @param args - Additional parameters to pass to the `getBookmark` function
* @returns The result of the `getBookmark` function
*/
get(version, ...args) {
const fn = getBookmark(this._client, version, this._method);
return fn(...args);
get(version, args, init) {
const fn = getBookmark(version, this._client, this._method);
return fn(args, init);
}
/**
* Fetch all bookmarks
* @see {@link get/client}
* Retrieves the payload for a bookmark using the specified API version.
*
* @template TVersion - The version of the API to call.
* @template TResult - The type of the result of the `getBookmarkPayload` function.
* @param version - The API version to use for the bookmark payload.
* @param args - The arguments to pass to the `getBookmarkPayload` function.
* @returns The result of the `getBookmarkPayload` function.
*/
getAll(version) {
const fn = getAllBookmarks(this._client, version, this._method);
return fn();
getPayload(version, args, init) {
const fn = getBookmarkApply(version, this._client, this._method);
return fn(args, init);
}
/**
* Create a new bookmark
* @see {@link get/client}
* Query a person's bookmarks.
*
* @template TVersion - The version of the API to call.
* @template TResponse - The type of the result of the `getBookmarks` function.
* @param version - The API version to use.
* @param args - Additional arguments to pass to the `getBookmarks` function.
* @param init - Optional request initialization options.
* @returns The result of calling the `getBookmarks` function.
*/
post(version, ...args) {
const fn = postBookmark(this._client, version, this._method);
return fn(...args);
query(version, args, init) {
const fn = getBookmarks(version, this._client, this._method);
return fn(args, init);
}
/**
* Update a bookmark
* @see {@link get/client}
*
* @template TVersion - The version of the API to call
* @template TResponse - The type of the result of the `patchBookmark` function
* @param version - The API version to use
* @param args - The parameters to pass to the `patchBookmark` function
* @returns The result of the `patchBookmark` function
*/
patch(version, ...args) {
const fn = patchBookmark(this._client, version, this._method);
return fn(...args);
patch(version, args, init) {
const fn = patchBookmark(version, this._client, this._method);
return fn(args, init);
}
/**
* Delete a bookmark
* @see {@link delete/client}
* Create a new bookmark
*
* @template TVersion - The version of the API to call
* @template TResult - The type of the result of the `postBookmark` function
* @param version - The API version to use
* @param request - The parameters to pass to the `postBookmark` function
* @returns The result of creating the bookmark
*/
delete(version, ...args) {
const fn = deleteBookmark(this._client, version, this._method);
return fn(...args);
create(version, request, init) {
const fn = createBookmark(version, this._client, this._method);
return fn(request, init);
}
/**
* Add bookmark to favorites by bookmark id
* @see {@link addFavorite/client}
* Deletes a bookmark.
*
* @template TVersion - The version of the API to call.
* @template TResponse - The type of the result of the `deleteBookmark` function.
* @param version - The version of the delete bookmark API to use.
* @param args - The arguments to pass to the `deleteBookmark` function.
* @returns The result of the delete bookmark operation.
*/
addFavorite(version, ...args) {
const fn = addBookmarkFavorite(this._client, version, this._method);
return fn(...args);
delete(version, args, init) {
const fn = deleteBookmark(version, this._client, this._method);
return fn(args, init);
}
/**
* Check if a bookmark is a favorite.
*
* Remove bookmark from favorites by bookmark id
* @see {@link removeFavorite/client}
* @template TVersion - The version of the API to call.
* @template TResult - The type of the result of the `verifyBookmarkFavorite` function.
* @param version - The API version to use.
* @param args - The arguments to pass to the `HeadBookmarkFavoriteFn` function.
* @returns The result of the `HeadBookmarksFavoriteResult` function.
*/
removeFavorite(version, ...args) {
const fn = deleteBookmarkFavorite(this._client, version, this._method);
return fn(...args);
isFavorite(version, args, init) {
const fn = isFavoriteBookmark(version, this._client, this._method);
return fn(args, init);
}
/**
* Add the provided bookmark to the user's favorites.
*
* Verify that the current bookmark is present in the users collection of bookmarks.
* @see {@link verifyFavorite/client}
* @template TVersion - The version of the API to call.
* @template TResponse - The type of the result of the `addBookmarkFavorite` function.
* @param version - The API version to use.
* @param args - The parameters to pass to the `PostBookmarkFavoriteFn` function.
* @returns The result of adding the bookmark to the user's favorites.
*/
verifyFavorite(version, ...args) {
const fn = verifyBookmarkFavorite(this._client, version, this._method);
return fn(...args);
addFavourite(version, args, init) {
const fn = addBookmarkAsFavourite(version, this._client, this._method);
return fn(args, init);
}
/**
* Removes the provided bookmark from the user's collection of bookmarks.
*
* @template TVersion - The version of the API to call.
* @template TResult - The type of the result of the `deleteBookmarkFavorite` function.
* @param version - The API version to use for the request.
* @param request - The parameters to pass to the `deleteBookmarkFavorite` function.
* @returns The result of the `deleteBookmarkFavorite` function.
*/
removeFavourite(version, request, init) {
const fn = removeFavoriteBookmark(version, this._client, this._method);
return fn(request, init);
}
}
export default BookmarksApiClient;
//# sourceMappingURL=client.js.map
export { BookmarksApiClient, default } from './client';
export * from './api-models';
export * from './types';
export { ApiVersion } from './api-version';
//# sourceMappingURL=index.js.map
// Generated by genversion.
export const version = '4.1.5';
export const version = '5.0.0';
//# sourceMappingURL=version.js.map

@@ -1,58 +0,156 @@

import { IHttpClient } from '@equinor/fusion-framework-module-http';
import { ClientMethod } from '..';
import { DeleteBookmarkResult, DeleteBookmarksFn, DeleteBookmarksResult } from './delete/types';
import { ApiVersions, GetBookmarkResult, GetBookmarksFn, GetBookmarksResult } from './get/types';
import { PostBookmarkResult, PostBookmarkFn, PostBookmarksResult } from './post/types';
import { PatchBookmarkFn, PatchBookmarkResult, PatchBookmarksResult } from './patch';
import { GetAllBookmarkResult, GetAllBookmarksResult } from './getAll';
import { PostBookmarkFavoriteFn, PostBookmarksFavoriteResult } from './favorites/post';
import { DeleteBookmarksFavoriteFn, DeleteBookmarksFavoriteResult } from './favorites/delete';
import { HeadBookmarkFavoriteFn, HeadBookmarksFavoriteResult } from './favorites/head';
export declare class BookmarksApiClient<TMethod extends keyof ClientMethod<unknown> = keyof ClientMethod<unknown>, TClient extends IHttpClient = IHttpClient, TPayload = unknown> {
import type { ClientRequestInit, IHttpClient } from '@equinor/fusion-framework-module-http/client';
import type { ClientMethod } from '../types';
import { GetBookmarksArgs, GetBookmarksResponse, GetBookmarksResult, GetBookmarksVersion } from './endpoints/user-bookmarks.get';
import { GetBookmarkArg, GetBookmarkResponse, GetBookmarkResult, GetBookmarkVersion } from './endpoints/bookmark.get';
import { CreateBookmarkArg, CreateBookmarkResponse, CreateBookmarkVersion, CreateBookmarksResult } from './endpoints/bookmark.post';
import { type PatchBookmarkArg, type PatchBookmarkResponse, type PatchBookmarkVersion, type PatchBookmarksResult } from './endpoints/bookmark.patch';
import { BookmarkApplyArgs, BookmarkApplyResponse, BookmarkApplyResult, BookmarkApplyVersion } from './endpoints/bookmark-apply.get';
import { AddBookmarkFavouriteArgs, AddBookmarkFavouriteResponse, AddBookmarkFavouriteResult, AddBookmarkFavouriteVersion } from './endpoints/user-bookmark-favourite.post';
import { DeleteBookmarkArg, DeleteBookmarkResponse, DeleteBookmarkVersion } from './endpoints/bookmark.delete';
import { IsFavoriteBookmarkArgs, IsFavoriteBookmarkResponse, IsFavoriteBookmarkResult, IsFavoriteBookmarkVersion } from './endpoints/user-bookmark-favourite.head';
import { RemoveBookmarkFavouriteArgs, RemoveBookmarkFavouriteResponse, RemoveBookmarkFavouriteResult, RemoveBookmarkFavouriteVersion } from './endpoints/user-bookmark-favourite.delete';
/**
* Provides a client interface for interacting with the bookmarks API.
* This class abstracts the details of making API requests and handling responses.
* It provides methods for fetching, creating, updating, and deleting bookmarks,
* as well as managing bookmark favorites.
*
* @example
* ```typescript
* import { BookmarksApiClient } from '@equinor/fusion';
* import { HttpClient } from '@equinor/fusion-framework-module-http';
*
* const httpClient = new HttpClient({ baseUri: 'https://my-bookmarks-api.com/' });
*
* // create a bookmarks API client using a custom HTTP client
* const client = new BookmarksApiClient(httpClient, 'json');
*
* // fetch a bookmark by its ID
* const bookmark = await client.getBookmark('my-bookmark-id');
*
* // fetch all bookmarks for the current user
* const bookmarks = await client.query();
*
* // update a bookmark by its ID
* await client.patch({
* bookmarkId: 'my-bookmark-id',
* data: {
* name: 'new-name'
* payload: { foo: 'bar' }
* }
* });
*
* // delete a bookmark by its ID
* await client.deleteBookmark('my-bookmark-id');
*
* // add or remove a bookmark to the current user's favorites
* await client.addFavorite({ bookmarkId:'my-bookmark-id' });
* await client.removeFavorite({ bookmarkId:'my-bookmark-id' });
* ```
*
* @template TMethod - The client method to use for the request, defaults to 'json'.
* @template TClient - The HTTP client to use for executing the request.
*/
export declare class BookmarksApiClient<TMethod extends keyof ClientMethod<unknown> = keyof ClientMethod<unknown>, TClient extends IHttpClient = IHttpClient> {
protected _client: TClient;
protected _method: TMethod;
/**
* Constructs a new instance of the BookmarksClient class.
*
* @param _client - The client instance to use for making API requests.
* @param _method - The client method to use for API requests.
*/
constructor(_client: TClient, _method: TMethod);
/**
* Fetch bookmark by id
* @see {@link get/client}
* Fetch a single bookmark
*
* @template TVersion - The version of the API to call
* @template TResponse - The type of the result of the `getBookmark` function
* @param version - The API version to use
* @param args - Additional parameters to pass to the `getBookmark` function
* @returns The result of the `getBookmark` function
*/
get<TVersion extends ApiVersions, TResult = GetBookmarkResult<TVersion, TPayload>>(version: TVersion, ...args: Parameters<GetBookmarksFn<TVersion, TMethod, TClient, TPayload, TResult>>): GetBookmarksResult<TVersion, TMethod, TPayload, TResult>;
get<TVersion extends GetBookmarkVersion, TResponse = GetBookmarkResponse<TVersion>>(version: TVersion, args: GetBookmarkArg<TVersion>, init?: ClientRequestInit<TClient, TResponse>): GetBookmarkResult<TVersion, TMethod, TResponse>;
/**
* Fetch all bookmarks
* @see {@link get/client}
* Retrieves the payload for a bookmark using the specified API version.
*
* @template TVersion - The version of the API to call.
* @template TResult - The type of the result of the `getBookmarkPayload` function.
* @param version - The API version to use for the bookmark payload.
* @param args - The arguments to pass to the `getBookmarkPayload` function.
* @returns The result of the `getBookmarkPayload` function.
*/
getAll<TVersion extends ApiVersions, TResult = GetAllBookmarkResult<TVersion, TPayload>>(version: TVersion): GetAllBookmarksResult<TVersion, TMethod, TPayload, TResult>;
getPayload<TVersion extends BookmarkApplyVersion, TResponse = BookmarkApplyResponse<TVersion>>(version: TVersion, args: BookmarkApplyArgs<TVersion>, init?: ClientRequestInit<TClient, TResponse>): BookmarkApplyResult<TVersion, TMethod, TResponse>;
/**
* Create a new bookmark
* @see {@link get/client}
* Query a person's bookmarks.
*
* @template TVersion - The version of the API to call.
* @template TResponse - The type of the result of the `getBookmarks` function.
* @param version - The API version to use.
* @param args - Additional arguments to pass to the `getBookmarks` function.
* @param init - Optional request initialization options.
* @returns The result of calling the `getBookmarks` function.
*/
post<TVersion extends ApiVersions, TResult = PostBookmarkResult<TVersion, TPayload>>(version: TVersion, ...args: Parameters<PostBookmarkFn<TVersion, TMethod, TClient, TPayload, TResult>>): PostBookmarksResult<TVersion, TMethod, TPayload, TResult>;
query<TVersion extends GetBookmarksVersion, TResponse = GetBookmarksResponse<TVersion>>(version: TVersion, args?: GetBookmarksArgs<TVersion>, init?: ClientRequestInit<TClient, TResponse>): GetBookmarksResult<TVersion, TMethod, TResponse>;
/**
* Update a bookmark
* @see {@link get/client}
*
* @template TVersion - The version of the API to call
* @template TResponse - The type of the result of the `patchBookmark` function
* @param version - The API version to use
* @param args - The parameters to pass to the `patchBookmark` function
* @returns The result of the `patchBookmark` function
*/
patch<TVersion extends ApiVersions, TResult = PatchBookmarkResult<TVersion, TPayload>>(version: TVersion, ...args: Parameters<PatchBookmarkFn<TVersion, TMethod, TClient, TPayload, TResult>>): PatchBookmarksResult<TVersion, TMethod, TPayload, TResult>;
patch<TVersion extends PatchBookmarkVersion, TResponse = PatchBookmarkResponse<TVersion>>(version: TVersion, args: PatchBookmarkArg<TVersion>, init?: ClientRequestInit<TClient, TResponse>): PatchBookmarksResult<TVersion, TMethod, TResponse>;
/**
* Delete a bookmark
* @see {@link delete/client}
* Create a new bookmark
*
* @template TVersion - The version of the API to call
* @template TResult - The type of the result of the `postBookmark` function
* @param version - The API version to use
* @param request - The parameters to pass to the `postBookmark` function
* @returns The result of creating the bookmark
*/
delete<TVersion extends ApiVersions, TResult = DeleteBookmarkResult<TVersion>>(version: TVersion, ...args: Parameters<DeleteBookmarksFn<TVersion, TMethod, TClient, TResult>>): DeleteBookmarksResult<TVersion, TMethod, TResult>;
create<TVersion extends CreateBookmarkVersion, TResponse = CreateBookmarkResponse<TVersion>>(version: TVersion, request: CreateBookmarkArg<TVersion>, init?: ClientRequestInit<TClient, TResponse>): CreateBookmarksResult<TVersion, TMethod, TResponse>;
/**
* Add bookmark to favorites by bookmark id
* @see {@link addFavorite/client}
* Deletes a bookmark.
*
* @template TVersion - The version of the API to call.
* @template TResponse - The type of the result of the `deleteBookmark` function.
* @param version - The version of the delete bookmark API to use.
* @param args - The arguments to pass to the `deleteBookmark` function.
* @returns The result of the delete bookmark operation.
*/
addFavorite<TVersion extends ApiVersions, TResult = DeleteBookmarkResult<TVersion>>(version: TVersion, ...args: Parameters<PostBookmarkFavoriteFn<TVersion, TMethod, TClient, TResult>>): PostBookmarksFavoriteResult<TVersion, TMethod, TResult>;
delete<TVersion extends DeleteBookmarkVersion, TResponse = DeleteBookmarkResponse<TVersion>>(version: TVersion, args: DeleteBookmarkArg<TVersion>, init?: ClientRequestInit<TClient, TResponse>): GetBookmarkResult<TVersion, TMethod, TResponse>;
/**
* Check if a bookmark is a favorite.
*
* Remove bookmark from favorites by bookmark id
* @see {@link removeFavorite/client}
* @template TVersion - The version of the API to call.
* @template TResult - The type of the result of the `verifyBookmarkFavorite` function.
* @param version - The API version to use.
* @param args - The arguments to pass to the `HeadBookmarkFavoriteFn` function.
* @returns The result of the `HeadBookmarksFavoriteResult` function.
*/
removeFavorite<TVersion extends ApiVersions, TResult = DeleteBookmarkResult<TVersion>>(version: TVersion, ...args: Parameters<DeleteBookmarksFavoriteFn<TVersion, TMethod, TClient, TResult>>): DeleteBookmarksFavoriteResult<TVersion, TMethod, TResult>;
isFavorite<TVersion extends IsFavoriteBookmarkVersion, TResponse = IsFavoriteBookmarkResponse<TVersion>>(version: TVersion, args: IsFavoriteBookmarkArgs<TVersion>, init?: ClientRequestInit<TClient, TResponse>): IsFavoriteBookmarkResult<TVersion, TMethod, TResponse>;
/**
* Add the provided bookmark to the user's favorites.
*
* Verify that the current bookmark is present in the users collection of bookmarks.
* @see {@link verifyFavorite/client}
* @template TVersion - The version of the API to call.
* @template TResponse - The type of the result of the `addBookmarkFavorite` function.
* @param version - The API version to use.
* @param args - The parameters to pass to the `PostBookmarkFavoriteFn` function.
* @returns The result of adding the bookmark to the user's favorites.
*/
verifyFavorite<TVersion extends ApiVersions, TResult = DeleteBookmarkResult<TVersion>>(version: TVersion, ...args: Parameters<HeadBookmarkFavoriteFn<TVersion, TMethod, TClient, TResult>>): HeadBookmarksFavoriteResult<TVersion, TMethod, TResult>;
addFavourite<TVersion extends AddBookmarkFavouriteVersion, TResponse = AddBookmarkFavouriteResponse<TVersion>>(version: TVersion, args: AddBookmarkFavouriteArgs<TVersion>, init?: ClientRequestInit<TClient, TResponse>): AddBookmarkFavouriteResult<TVersion, TMethod, TResponse>;
/**
* Removes the provided bookmark from the user's collection of bookmarks.
*
* @template TVersion - The version of the API to call.
* @template TResult - The type of the result of the `deleteBookmarkFavorite` function.
* @param version - The API version to use for the request.
* @param request - The parameters to pass to the `deleteBookmarkFavorite` function.
* @returns The result of the `deleteBookmarkFavorite` function.
*/
removeFavourite<TVersion extends RemoveBookmarkFavouriteVersion, TResponse = RemoveBookmarkFavouriteResponse<TVersion>>(version: TVersion, request: RemoveBookmarkFavouriteArgs<TVersion>, init?: ClientRequestInit<TClient, TResponse>): RemoveBookmarkFavouriteResult<TVersion, TMethod, TResponse>;
}
export default BookmarksApiClient;
export { BookmarksApiClient, default } from './client';
export * from './api-models';
export * from './types';
export { ApiVersion } from './api-version';
export type * from './schemas';
export type * from './types';

@@ -1,1 +0,5 @@

export { ClientMethodType, ClientMethod, ApiClientArguments } from '..';
import type { FilterAllowedApiVersions as FilterAllowApiVersionsBase, ExtractApiVersion as ExtractApiVersionBase } from '../types';
import { ApiVersion } from './api-version';
export { ClientMethodType, ClientMethod, ApiClientArguments } from '../types';
export type FilterAllowedApiVersions<TAllowed extends string = keyof typeof ApiVersion> = FilterAllowApiVersionsBase<typeof ApiVersion, TAllowed>;
export type ExtractApiVersion<TVersion extends string, TAllowed extends string = FilterAllowedApiVersions> = ExtractApiVersionBase<typeof ApiVersion, TVersion, TAllowed>;

@@ -12,3 +12,3 @@ import { IHttpClient } from '@equinor/fusion-framework-module-http';

*/
createBookmarksClient<TMethod extends keyof ClientMethod, TPayload = unknown>(method: TMethod): Promise<BookmarksApiClient<TMethod, TClient, TPayload>>;
createBookmarksClient<TMethod extends keyof ClientMethod>(method: TMethod): Promise<BookmarksApiClient<TMethod, TClient>>;
/**

@@ -47,3 +47,3 @@ * @param method - Version of the service to use

createNotificationClient<TMethod extends keyof ClientMethod>(method: TMethod): Promise<NotificationApiClient<TMethod, TClient>>;
createBookmarksClient<TMethod extends keyof ClientMethod, TPayload = unknown>(method: TMethod): Promise<BookmarksApiClient<TMethod, TClient, TPayload>>;
createBookmarksClient<TMethod extends keyof ClientMethod>(method: TMethod): Promise<BookmarksApiClient<TMethod, TClient>>;
createContextClient<TMethod extends keyof ClientMethod>(method: TMethod): Promise<ContextApiClient<TMethod, TClient>>;

@@ -50,0 +50,0 @@ createPeopleClient(): Promise<PeopleApiClient<TClient>>;

@@ -1,3 +0,17 @@

import { ClientRequestInit, IHttpClient, StreamResponse, BlobResult, FetchResponse } from '@equinor/fusion-framework-module-http/client';
import { ClientRequestInit, IHttpClient, StreamResponse, BlobResult } from '@equinor/fusion-framework-module-http/client';
/**
* A factory function that creates an instance of an HTTP client.
*
* @param name - The name of the HTTP client to create.
* @returns A Promise that resolves to an instance of the HTTP client.
*/
export type ApiClientFactory<TClient extends IHttpClient = IHttpClient> = (name: string) => Promise<TClient>;
/**
* Represents the arguments for an API client function.
*
* @template TClient - The type of the HTTP client used by the API client.
* @template TResult - The type of the result returned by the API client.
* @param path - The path of the API endpoint.
* @param init - Optional initialization options for the API client request.
*/
export type ApiClientArguments<TClient extends IHttpClient, TResult = unknown> = [

@@ -12,7 +26,2 @@ path: string,

/**
* Fetch data async
* NOTE: data needs to be extracted from the response
*/
fetch: Promise<FetchResponse<T>>;
/**
* Fetch JSON data from a service

@@ -22,7 +31,2 @@ */

/**
* Fetch data as an observable
* NOTE: data needs to be extracted from the response
*/
fetch$: StreamResponse<FetchResponse<T>>;
/**
* Fetch JSON data from a service as observable

@@ -37,1 +41,60 @@ */

export type ClientMethodType = keyof ClientMethod;
/**
* Utility type that filters the keys of an `AvailableTypes` object to only those
* whose values are a subset of the `AllowedTypes` string.
*
* This can be useful for creating a type that represents a subset of an API's
* available versions, where the allowed versions are a subset of the total
* available versions.
*
* @example
* ```typescript
* enum ApiVersions = {
* v1: '1.0'
* v2: '2.0'
* v3: '3.0'
* }
*
* type Services = {
* [ApiVersions.v1]: { request: ApiRequestModel_v1, response: ApiResponseModel_v1 }
* [ApiVersions.v2]: { request: ApiRequestModel_v2, response: ApiResponseModel_v2 }
* }
*
* type ApiServiceVersions = keyof Services; // '1.0' | '2.0'
* type AllowedApiVersions = FilterAllowApiVersions<ApiVersions, ApiServiceVersions> // ApiVersions.v1 | 'v1' | ApiVersions.v2 | v2'
*
* const execute<TVersion extends AllowedApiVersions>(
* version: TVersion,
* args: Services[TVersion]['request']
* ): Services[TVersion]['response'] {
* const apiVersion = version in ApiVersion ? ApiVersion[version] : version;
* switch (apiVersion) {
* case ApiVersion.v1:
* case ApiVersion.v2:
* return fetch(args);
* }
* throw new Error('Invalid version');
* }
*
* execute('v1', { id: '123' }); // OK
* execute('v3', { id: '123' }); // Error
* ```
*
* @template TAvailableTypes - An object type that maps string keys to string values,
* representing the available API versions.
* @template TAllowedTypes - A string union type representing the allowed API versions.
* @returns A string union type containing the keys from `AvailableTypes` whose
* values are a subset of `AllowedTypes`.
*/
export type FilterAllowedApiVersions<TAvailableTypes extends Record<string, string>, TAllowedTypes extends string | number | symbol = keyof TAvailableTypes> = {
[K in keyof TAvailableTypes]: TAvailableTypes extends Record<K, infer V> ? K extends TAllowedTypes ? K | V : V extends TAllowedTypes ? V | K : never : never;
}[keyof TAvailableTypes];
/**
* Extracts the API version from a set of available types, based on a list of allowed types.
*
* @template TAvailableTypes - An object mapping API version strings to their corresponding types.
* @template TAllowedTypes - A list of allowed API version strings.
* @template TVersion - The API version to extract.
* @returns The API version type if it is available and allowed, otherwise `never`.
*/
export type ExtractApiVersion<TAvailableTypes extends Record<string, string>, TVersion extends string, TAllowedTypes extends string | number | symbol = FilterAllowedApiVersions<TAvailableTypes>> = TVersion extends keyof TAvailableTypes ? TAvailableTypes[TVersion] : TVersion extends TAllowedTypes ? TVersion : never;

@@ -1,1 +0,1 @@

export declare const version = "4.1.5";
export declare const version = "5.0.0";
{
"name": "@equinor/fusion-framework-module-services",
"version": "5.0.0-next-663bed8344cc2ca0111705b05045173328b3104d",
"version": "5.0.0",
"description": "",
"sideEffects": false,
"type": "module",
"main": "dist/esm/index.js",

@@ -54,2 +53,6 @@ "types": "index.d.ts",

},
"./bookmarks": {
"import": "./dist/esm/bookmarks/index.js",
"types": "./dist/types/bookmarks/index.d.ts"
},
"./context": {

@@ -71,6 +74,2 @@ "import": "./dist/esm/context/index.js",

},
"./bookmarks": {
"import": "./dist/esm/bookmarks/index.js",
"types": "./dist/types/bookmarks/index.d.ts"
},
"./notification": {

@@ -118,13 +117,14 @@ "import": "./dist/esm/notification/index.js",

"dependencies": {
"odata-query": "^7.0.4"
"odata-query": "^7.0.4",
"zod": "^3.23.8"
},
"devDependencies": {
"typescript": "^5.5.4",
"@equinor/fusion-framework-module-http": "^7.0.0-next-663bed8344cc2ca0111705b05045173328b3104d",
"@equinor/fusion-framework-module": "^5.0.0-next-663bed8344cc2ca0111705b05045173328b3104d",
"@equinor/fusion-framework-module-service-discovery": "^9.0.0-next-663bed8344cc2ca0111705b05045173328b3104d"
"@equinor/fusion-framework-module": "^4.3.5",
"@equinor/fusion-framework-module-http": "^6.2.0",
"@equinor/fusion-framework-module-service-discovery": "^8.0.2"
},
"peerDependencies": {
"odata-query": "^7.0.4",
"@equinor/fusion-framework-module": "^5.0.0-next-663bed8344cc2ca0111705b05045173328b3104d"
"@equinor/fusion-framework-module": "^4.3.5"
},

@@ -131,0 +131,0 @@ "scripts": {

@@ -1,30 +0,122 @@

import { IHttpClient } from '@equinor/fusion-framework-module-http';
import type { ClientRequestInit, IHttpClient } from '@equinor/fusion-framework-module-http/client';
import type { ClientMethod } from '../types';
import { ClientMethod } from '..';
import deleteBookmark from './delete/client';
import { DeleteBookmarkResult, DeleteBookmarksFn, DeleteBookmarksResult } from './delete/types';
import getBookmark from './get/client';
import { ApiVersions, GetBookmarkResult, GetBookmarksFn, GetBookmarksResult } from './get/types';
import { PostBookmarkResult, PostBookmarkFn, PostBookmarksResult } from './post/types';
import postBookmark from './post/client';
import patchBookmark, { PatchBookmarkFn, PatchBookmarkResult, PatchBookmarksResult } from './patch';
import getAllBookmarks, { GetAllBookmarkResult, GetAllBookmarksResult } from './getAll';
import addBookmarkFavorite, {
PostBookmarkFavoriteFn,
PostBookmarksFavoriteResult,
} from './favorites/post';
import deleteBookmarkFavorite, {
DeleteBookmarksFavoriteFn,
DeleteBookmarksFavoriteResult,
} from './favorites/delete';
import verifyBookmarkFavorite, {
HeadBookmarkFavoriteFn,
HeadBookmarksFavoriteResult,
} from './favorites/head';
import {
GetBookmarksArgs,
GetBookmarksResponse,
GetBookmarksResult,
GetBookmarksVersion,
getBookmarks,
} from './endpoints/user-bookmarks.get';
import {
GetBookmarkArg,
GetBookmarkResponse,
GetBookmarkResult,
GetBookmarkVersion,
getBookmark,
} from './endpoints/bookmark.get';
import {
CreateBookmarkArg,
CreateBookmarkResponse,
CreateBookmarkVersion,
CreateBookmarksResult,
createBookmark,
} from './endpoints/bookmark.post';
import {
type PatchBookmarkArg,
type PatchBookmarkResponse,
type PatchBookmarkVersion,
type PatchBookmarksResult,
patchBookmark,
} from './endpoints/bookmark.patch';
import {
BookmarkApplyArgs,
BookmarkApplyResponse,
BookmarkApplyResult,
BookmarkApplyVersion,
getBookmarkApply,
} from './endpoints/bookmark-apply.get';
import {
AddBookmarkFavouriteArgs,
AddBookmarkFavouriteResponse,
AddBookmarkFavouriteResult,
AddBookmarkFavouriteVersion,
addBookmarkAsFavourite,
} from './endpoints/user-bookmark-favourite.post';
import {
DeleteBookmarkArg,
DeleteBookmarkResponse,
DeleteBookmarkVersion,
deleteBookmark,
} from './endpoints/bookmark.delete';
import {
IsFavoriteBookmarkArgs,
IsFavoriteBookmarkResponse,
IsFavoriteBookmarkResult,
IsFavoriteBookmarkVersion,
isFavoriteBookmark,
} from './endpoints/user-bookmark-favourite.head';
import {
RemoveBookmarkFavouriteArgs,
RemoveBookmarkFavouriteResponse,
RemoveBookmarkFavouriteResult,
RemoveBookmarkFavouriteVersion,
removeFavoriteBookmark,
} from './endpoints/user-bookmark-favourite.delete';
/**
* Provides a client interface for interacting with the bookmarks API.
* This class abstracts the details of making API requests and handling responses.
* It provides methods for fetching, creating, updating, and deleting bookmarks,
* as well as managing bookmark favorites.
*
* @example
* ```typescript
* import { BookmarksApiClient } from '@equinor/fusion';
* import { HttpClient } from '@equinor/fusion-framework-module-http';
*
* const httpClient = new HttpClient({ baseUri: 'https://my-bookmarks-api.com/' });
*
* // create a bookmarks API client using a custom HTTP client
* const client = new BookmarksApiClient(httpClient, 'json');
*
* // fetch a bookmark by its ID
* const bookmark = await client.getBookmark('my-bookmark-id');
*
* // fetch all bookmarks for the current user
* const bookmarks = await client.query();
*
* // update a bookmark by its ID
* await client.patch({
* bookmarkId: 'my-bookmark-id',
* data: {
* name: 'new-name'
* payload: { foo: 'bar' }
* }
* });
*
* // delete a bookmark by its ID
* await client.deleteBookmark('my-bookmark-id');
*
* // add or remove a bookmark to the current user's favorites
* await client.addFavorite({ bookmarkId:'my-bookmark-id' });
* await client.removeFavorite({ bookmarkId:'my-bookmark-id' });
* ```
*
* @template TMethod - The client method to use for the request, defaults to 'json'.
* @template TClient - The HTTP client to use for executing the request.
*/
export class BookmarksApiClient<
TMethod extends keyof ClientMethod<unknown> = keyof ClientMethod<unknown>,
TClient extends IHttpClient = IHttpClient,
TPayload = unknown,
> {
/**
* Constructs a new instance of the BookmarksClient class.
*
* @param _client - The client instance to use for making API requests.
* @param _method - The client method to use for API requests.
*/
constructor(

@@ -36,33 +128,57 @@ protected _client: TClient,

/**
* Fetch bookmark by id
* @see {@link get/client}
* Fetch a single bookmark
*
* @template TVersion - The version of the API to call
* @template TResponse - The type of the result of the `getBookmark` function
* @param version - The API version to use
* @param args - Additional parameters to pass to the `getBookmark` function
* @returns The result of the `getBookmark` function
*/
public get<TVersion extends ApiVersions, TResult = GetBookmarkResult<TVersion, TPayload>>(
public get<TVersion extends GetBookmarkVersion, TResponse = GetBookmarkResponse<TVersion>>(
version: TVersion,
...args: Parameters<GetBookmarksFn<TVersion, TMethod, TClient, TPayload, TResult>>
): GetBookmarksResult<TVersion, TMethod, TPayload, TResult> {
const fn = getBookmark(this._client, version, this._method);
return fn<TResult>(...args);
args: GetBookmarkArg<TVersion>,
init?: ClientRequestInit<TClient, TResponse>,
): GetBookmarkResult<TVersion, TMethod, TResponse> {
const fn = getBookmark(version, this._client, this._method);
return fn(args, init);
}
/**
* Fetch all bookmarks
* @see {@link get/client}
* Retrieves the payload for a bookmark using the specified API version.
*
* @template TVersion - The version of the API to call.
* @template TResult - The type of the result of the `getBookmarkPayload` function.
* @param version - The API version to use for the bookmark payload.
* @param args - The arguments to pass to the `getBookmarkPayload` function.
* @returns The result of the `getBookmarkPayload` function.
*/
public getAll<TVersion extends ApiVersions, TResult = GetAllBookmarkResult<TVersion, TPayload>>(
public getPayload<
TVersion extends BookmarkApplyVersion,
TResponse = BookmarkApplyResponse<TVersion>,
>(
version: TVersion,
): GetAllBookmarksResult<TVersion, TMethod, TPayload, TResult> {
const fn = getAllBookmarks(this._client, version, this._method);
return fn<TResult>();
args: BookmarkApplyArgs<TVersion>,
init?: ClientRequestInit<TClient, TResponse>,
): BookmarkApplyResult<TVersion, TMethod, TResponse> {
const fn = getBookmarkApply(version, this._client, this._method);
return fn(args, init);
}
/**
* Create a new bookmark
* @see {@link get/client}
* Query a person's bookmarks.
*
* @template TVersion - The version of the API to call.
* @template TResponse - The type of the result of the `getBookmarks` function.
* @param version - The API version to use.
* @param args - Additional arguments to pass to the `getBookmarks` function.
* @param init - Optional request initialization options.
* @returns The result of calling the `getBookmarks` function.
*/
public post<TVersion extends ApiVersions, TResult = PostBookmarkResult<TVersion, TPayload>>(
public query<TVersion extends GetBookmarksVersion, TResponse = GetBookmarksResponse<TVersion>>(
version: TVersion,
...args: Parameters<PostBookmarkFn<TVersion, TMethod, TClient, TPayload, TResult>>
): PostBookmarksResult<TVersion, TMethod, TPayload, TResult> {
const fn = postBookmark(this._client, version, this._method);
return fn<TResult>(...args);
args?: GetBookmarksArgs<TVersion>,
init?: ClientRequestInit<TClient, TResponse>,
): GetBookmarksResult<TVersion, TMethod, TResponse> {
const fn = getBookmarks(version, this._client, this._method);
return fn(args, init);
}

@@ -72,63 +188,127 @@

* Update a bookmark
* @see {@link get/client}
*
* @template TVersion - The version of the API to call
* @template TResponse - The type of the result of the `patchBookmark` function
* @param version - The API version to use
* @param args - The parameters to pass to the `patchBookmark` function
* @returns The result of the `patchBookmark` function
*/
public patch<TVersion extends ApiVersions, TResult = PatchBookmarkResult<TVersion, TPayload>>(
public patch<
TVersion extends PatchBookmarkVersion,
TResponse = PatchBookmarkResponse<TVersion>,
>(
version: TVersion,
...args: Parameters<PatchBookmarkFn<TVersion, TMethod, TClient, TPayload, TResult>>
): PatchBookmarksResult<TVersion, TMethod, TPayload, TResult> {
const fn = patchBookmark(this._client, version, this._method);
return fn<TResult>(...args);
args: PatchBookmarkArg<TVersion>,
init?: ClientRequestInit<TClient, TResponse>,
): PatchBookmarksResult<TVersion, TMethod, TResponse> {
const fn = patchBookmark(version, this._client, this._method);
return fn(args, init);
}
/**
* Delete a bookmark
* @see {@link delete/client}
* Create a new bookmark
*
* @template TVersion - The version of the API to call
* @template TResult - The type of the result of the `postBookmark` function
* @param version - The API version to use
* @param request - The parameters to pass to the `postBookmark` function
* @returns The result of creating the bookmark
*/
public delete<TVersion extends ApiVersions, TResult = DeleteBookmarkResult<TVersion>>(
public create<
TVersion extends CreateBookmarkVersion,
TResponse = CreateBookmarkResponse<TVersion>,
>(
version: TVersion,
...args: Parameters<DeleteBookmarksFn<TVersion, TMethod, TClient, TResult>>
): DeleteBookmarksResult<TVersion, TMethod, TResult> {
const fn = deleteBookmark(this._client, version, this._method);
return fn<TResult>(...args);
request: CreateBookmarkArg<TVersion>,
init?: ClientRequestInit<TClient, TResponse>,
): CreateBookmarksResult<TVersion, TMethod, TResponse> {
const fn = createBookmark(version, this._client, this._method);
return fn(request, init);
}
/**
* Add bookmark to favorites by bookmark id
* @see {@link addFavorite/client}
* Deletes a bookmark.
*
* @template TVersion - The version of the API to call.
* @template TResponse - The type of the result of the `deleteBookmark` function.
* @param version - The version of the delete bookmark API to use.
* @param args - The arguments to pass to the `deleteBookmark` function.
* @returns The result of the delete bookmark operation.
*/
public addFavorite<TVersion extends ApiVersions, TResult = DeleteBookmarkResult<TVersion>>(
public delete<
TVersion extends DeleteBookmarkVersion,
TResponse = DeleteBookmarkResponse<TVersion>,
>(
version: TVersion,
...args: Parameters<PostBookmarkFavoriteFn<TVersion, TMethod, TClient, TResult>>
): PostBookmarksFavoriteResult<TVersion, TMethod, TResult> {
const fn = addBookmarkFavorite(this._client, version, this._method);
return fn<TResult>(...args);
args: DeleteBookmarkArg<TVersion>,
init?: ClientRequestInit<TClient, TResponse>,
): GetBookmarkResult<TVersion, TMethod, TResponse> {
const fn = deleteBookmark(version, this._client, this._method);
return fn(args, init);
}
/**
* Check if a bookmark is a favorite.
*
* Remove bookmark from favorites by bookmark id
* @see {@link removeFavorite/client}
* @template TVersion - The version of the API to call.
* @template TResult - The type of the result of the `verifyBookmarkFavorite` function.
* @param version - The API version to use.
* @param args - The arguments to pass to the `HeadBookmarkFavoriteFn` function.
* @returns The result of the `HeadBookmarksFavoriteResult` function.
*/
public removeFavorite<TVersion extends ApiVersions, TResult = DeleteBookmarkResult<TVersion>>(
public isFavorite<
TVersion extends IsFavoriteBookmarkVersion,
TResponse = IsFavoriteBookmarkResponse<TVersion>,
>(
version: TVersion,
...args: Parameters<DeleteBookmarksFavoriteFn<TVersion, TMethod, TClient, TResult>>
): DeleteBookmarksFavoriteResult<TVersion, TMethod, TResult> {
const fn = deleteBookmarkFavorite(this._client, version, this._method);
return fn<TResult>(...args);
args: IsFavoriteBookmarkArgs<TVersion>,
init?: ClientRequestInit<TClient, TResponse>,
): IsFavoriteBookmarkResult<TVersion, TMethod, TResponse> {
const fn = isFavoriteBookmark(version, this._client, this._method);
return fn(args, init);
}
/**
* Add the provided bookmark to the user's favorites.
*
* Verify that the current bookmark is present in the users collection of bookmarks.
* @see {@link verifyFavorite/client}
* @template TVersion - The version of the API to call.
* @template TResponse - The type of the result of the `addBookmarkFavorite` function.
* @param version - The API version to use.
* @param args - The parameters to pass to the `PostBookmarkFavoriteFn` function.
* @returns The result of adding the bookmark to the user's favorites.
*/
public verifyFavorite<TVersion extends ApiVersions, TResult = DeleteBookmarkResult<TVersion>>(
public addFavourite<
TVersion extends AddBookmarkFavouriteVersion,
TResponse = AddBookmarkFavouriteResponse<TVersion>,
>(
version: TVersion,
...args: Parameters<HeadBookmarkFavoriteFn<TVersion, TMethod, TClient, TResult>>
): HeadBookmarksFavoriteResult<TVersion, TMethod, TResult> {
const fn = verifyBookmarkFavorite(this._client, version, this._method);
return fn<TResult>(...args);
args: AddBookmarkFavouriteArgs<TVersion>,
init?: ClientRequestInit<TClient, TResponse>,
): AddBookmarkFavouriteResult<TVersion, TMethod, TResponse> {
const fn = addBookmarkAsFavourite(version, this._client, this._method);
return fn(args, init);
}
/**
* Removes the provided bookmark from the user's collection of bookmarks.
*
* @template TVersion - The version of the API to call.
* @template TResult - The type of the result of the `deleteBookmarkFavorite` function.
* @param version - The API version to use for the request.
* @param request - The parameters to pass to the `deleteBookmarkFavorite` function.
* @returns The result of the `deleteBookmarkFavorite` function.
*/
public removeFavourite<
TVersion extends RemoveBookmarkFavouriteVersion,
TResponse = RemoveBookmarkFavouriteResponse<TVersion>,
>(
version: TVersion,
request: RemoveBookmarkFavouriteArgs<TVersion>,
init?: ClientRequestInit<TClient, TResponse>,
): RemoveBookmarkFavouriteResult<TVersion, TMethod, TResponse> {
const fn = removeFavoriteBookmark(version, this._client, this._method);
return fn(request, init);
}
}
export default BookmarksApiClient;
export { BookmarksApiClient, default } from './client';
export * from './api-models';
export * from './types';
export { ApiVersion } from './api-version';
export type * from './schemas';
export type * from './types';

@@ -1,1 +0,16 @@

export { ClientMethodType, ClientMethod, ApiClientArguments } from '..';
import type {
FilterAllowedApiVersions as FilterAllowApiVersionsBase,
ExtractApiVersion as ExtractApiVersionBase,
} from '../types';
import { ApiVersion } from './api-version';
export { ClientMethodType, ClientMethod, ApiClientArguments } from '../types';
export type FilterAllowedApiVersions<TAllowed extends string = keyof typeof ApiVersion> =
FilterAllowApiVersionsBase<typeof ApiVersion, TAllowed>;
export type ExtractApiVersion<
TVersion extends string,
TAllowed extends string = FilterAllowedApiVersions,
> = ExtractApiVersionBase<typeof ApiVersion, TVersion, TAllowed>;

@@ -14,5 +14,5 @@ import { IHttpClient } from '@equinor/fusion-framework-module-http';

*/
createBookmarksClient<TMethod extends keyof ClientMethod, TPayload = unknown>(
createBookmarksClient<TMethod extends keyof ClientMethod>(
method: TMethod,
): Promise<BookmarksApiClient<TMethod, TClient, TPayload>>;
): Promise<BookmarksApiClient<TMethod, TClient>>;

@@ -96,5 +96,5 @@ /**

public async createBookmarksClient<TMethod extends keyof ClientMethod, TPayload = unknown>(
public async createBookmarksClient<TMethod extends keyof ClientMethod>(
method: TMethod,
): Promise<BookmarksApiClient<TMethod, TClient, TPayload>> {
): Promise<BookmarksApiClient<TMethod, TClient>> {
const httpClient = await this._createClientFn('bookmarks');

@@ -101,0 +101,0 @@ httpClient.responseHandler.add('validate_api_request', validateResponse);

@@ -6,5 +6,10 @@ import {

BlobResult,
FetchResponse,
} from '@equinor/fusion-framework-module-http/client';
/**
* A factory function that creates an instance of an HTTP client.
*
* @param name - The name of the HTTP client to create.
* @returns A Promise that resolves to an instance of the HTTP client.
*/
export type ApiClientFactory<TClient extends IHttpClient = IHttpClient> = (

@@ -14,2 +19,10 @@ name: string,

/**
* Represents the arguments for an API client function.
*
* @template TClient - The type of the HTTP client used by the API client.
* @template TResult - The type of the result returned by the API client.
* @param path - The path of the API endpoint.
* @param init - Optional initialization options for the API client request.
*/
export type ApiClientArguments<TClient extends IHttpClient, TResult = unknown> = [

@@ -25,7 +38,2 @@ path: string,

/**
* Fetch data async
* NOTE: data needs to be extracted from the response
*/
fetch: Promise<FetchResponse<T>>;
/**
* Fetch JSON data from a service

@@ -35,7 +43,2 @@ */

/**
* Fetch data as an observable
* NOTE: data needs to be extracted from the response
*/
fetch$: StreamResponse<FetchResponse<T>>;
/**
* Fetch JSON data from a service as observable

@@ -52,1 +55,79 @@ */

export type ClientMethodType = keyof ClientMethod;
/**
* Utility type that filters the keys of an `AvailableTypes` object to only those
* whose values are a subset of the `AllowedTypes` string.
*
* This can be useful for creating a type that represents a subset of an API's
* available versions, where the allowed versions are a subset of the total
* available versions.
*
* @example
* ```typescript
* enum ApiVersions = {
* v1: '1.0'
* v2: '2.0'
* v3: '3.0'
* }
*
* type Services = {
* [ApiVersions.v1]: { request: ApiRequestModel_v1, response: ApiResponseModel_v1 }
* [ApiVersions.v2]: { request: ApiRequestModel_v2, response: ApiResponseModel_v2 }
* }
*
* type ApiServiceVersions = keyof Services; // '1.0' | '2.0'
* type AllowedApiVersions = FilterAllowApiVersions<ApiVersions, ApiServiceVersions> // ApiVersions.v1 | 'v1' | ApiVersions.v2 | v2'
*
* const execute<TVersion extends AllowedApiVersions>(
* version: TVersion,
* args: Services[TVersion]['request']
* ): Services[TVersion]['response'] {
* const apiVersion = version in ApiVersion ? ApiVersion[version] : version;
* switch (apiVersion) {
* case ApiVersion.v1:
* case ApiVersion.v2:
* return fetch(args);
* }
* throw new Error('Invalid version');
* }
*
* execute('v1', { id: '123' }); // OK
* execute('v3', { id: '123' }); // Error
* ```
*
* @template TAvailableTypes - An object type that maps string keys to string values,
* representing the available API versions.
* @template TAllowedTypes - A string union type representing the allowed API versions.
* @returns A string union type containing the keys from `AvailableTypes` whose
* values are a subset of `AllowedTypes`.
*/
export type FilterAllowedApiVersions<
TAvailableTypes extends Record<string, string>,
TAllowedTypes extends string | number | symbol = keyof TAvailableTypes,
> = {
[K in keyof TAvailableTypes]: TAvailableTypes extends Record<K, infer V>
? K extends TAllowedTypes
? K | V
: V extends TAllowedTypes
? V | K
: never
: never;
}[keyof TAvailableTypes];
/**
* Extracts the API version from a set of available types, based on a list of allowed types.
*
* @template TAvailableTypes - An object mapping API version strings to their corresponding types.
* @template TAllowedTypes - A list of allowed API version strings.
* @template TVersion - The API version to extract.
* @returns The API version type if it is available and allowed, otherwise `never`.
*/
export type ExtractApiVersion<
TAvailableTypes extends Record<string, string>,
TVersion extends string,
TAllowedTypes extends string | number | symbol = FilterAllowedApiVersions<TAvailableTypes>,
> = TVersion extends keyof TAvailableTypes
? TAvailableTypes[TVersion]
: TVersion extends TAllowedTypes
? TVersion
: never;
// Generated by genversion.
export const version = '4.1.5';
export const version = '5.0.0';

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 not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc