Comparing version 1.3.0 to 1.4.0
@@ -211,6 +211,7 @@ /// <reference path="../types/realm/app.d.ts" /> | ||
declare type ProviderType = "anon-user" | "api-key" | "local-userpass" | "custom-function" | "custom-token" | "oauth2-google" | "oauth2-facebook" | "oauth2-apple"; | ||
declare type SimpleObject = Record<string, unknown>; | ||
/** | ||
* Instances of this class can be passed to the `app.logIn` method to authenticate an end-user. | ||
*/ | ||
declare class Credentials<PayloadType extends object = any> implements Realm.Credentials<PayloadType> { | ||
declare class Credentials<PayloadType extends SimpleObject = SimpleObject> implements Realm.Credentials<PayloadType> { | ||
/** | ||
@@ -221,3 +222,3 @@ * Creates credentials that logs in using the [Anonymous Provider](https://docs.mongodb.com/realm/authentication/anonymous/). | ||
*/ | ||
static anonymous(): Credentials<Realm.Credentials.AnonymousPayload>; | ||
static anonymous(): Credentials<AnonymousPayload>; | ||
/** | ||
@@ -227,7 +228,6 @@ * Creates credentials that logs in using the [API Key Provider](https://docs.mongodb.com/realm/authentication/api-key/). | ||
* @deprecated Use `Credentials.apiKey`. | ||
* | ||
* @param key The secret content of the API key. | ||
* @returns The credentials instance, which can be passed to `app.logIn`. | ||
*/ | ||
static userApiKey(key: string): Credentials<Realm.Credentials.ApiKeyPayload>; | ||
static userApiKey(key: string): Credentials<ApiKeyPayload>; | ||
/** | ||
@@ -237,7 +237,6 @@ * Creates credentials that logs in using the [API Key Provider](https://docs.mongodb.com/realm/authentication/api-key/). | ||
* @deprecated Use `Credentials.apiKey`. | ||
* | ||
* @param key The secret content of the API key. | ||
* @returns The credentials instance, which can be passed to `app.logIn`. | ||
*/ | ||
static serverApiKey(key: string): Credentials<Realm.Credentials.ApiKeyPayload>; | ||
static serverApiKey(key: string): Credentials<ApiKeyPayload>; | ||
/** | ||
@@ -249,3 +248,3 @@ * Creates credentials that logs in using the [API Key Provider](https://docs.mongodb.com/realm/authentication/api-key/). | ||
*/ | ||
static apiKey(key: string): Credentials<Realm.Credentials.ApiKeyPayload>; | ||
static apiKey(key: string): Credentials<ApiKeyPayload>; | ||
/** | ||
@@ -259,3 +258,3 @@ * Creates credentials that logs in using the [Email/Password Provider](https://docs.mongodb.com/realm/authentication/email-password/). | ||
*/ | ||
static emailPassword(email: string, password: string): Credentials<Realm.Credentials.EmailPasswordPayload>; | ||
static emailPassword(email: string, password: string): Credentials<EmailPasswordPayload>; | ||
/** | ||
@@ -274,3 +273,3 @@ * Creates credentials that logs in using the [Custom Function Provider](https://docs.mongodb.com/realm/authentication/custom-function/). | ||
*/ | ||
static jwt(token: string): Credentials<Realm.Credentials.JWTPayload>; | ||
static jwt(token: string): Credentials<JWTPayload>; | ||
/** | ||
@@ -282,3 +281,3 @@ * Creates credentials that logs in using the [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
*/ | ||
static google<P extends object = OAuth2RedirectPayload | GooglePayload>(payload: string | GoogleOptions): Credentials<P>; | ||
static google<P extends OAuth2RedirectPayload | GooglePayload>(payload: string | GoogleOptions): Credentials<P>; | ||
/** | ||
@@ -295,3 +294,3 @@ * @param payload The payload string. | ||
*/ | ||
static facebook<PayloadType extends object = OAuth2RedirectPayload | FacebookPayload>(redirectUrlOrAccessToken: string): Credentials<PayloadType>; | ||
static facebook<PayloadType extends OAuth2RedirectPayload | FacebookPayload>(redirectUrlOrAccessToken: string): Credentials<PayloadType>; | ||
/** | ||
@@ -303,3 +302,3 @@ * Creates credentials that logs in using the [Apple ID Provider](https://docs.mongodb.com/realm/authentication/apple/). | ||
*/ | ||
static apple<PayloadType extends object = OAuth2RedirectPayload | ApplePayload>(redirectUrlOrIdToken: string): Credentials<PayloadType>; | ||
static apple<PayloadType extends OAuth2RedirectPayload | ApplePayload>(redirectUrlOrIdToken: string): Credentials<PayloadType>; | ||
/** | ||
@@ -335,3 +334,3 @@ * The name of the authentication provider used when authenticating. | ||
*/ | ||
currentUser: User<object, object, unknown> | null; | ||
currentUser: User | null; | ||
}; | ||
@@ -367,3 +366,3 @@ /** | ||
*/ | ||
user?: User<object, object, unknown>; | ||
user?: User; | ||
} & (RequestWithUrl<RequestBody> | RequestWithPath<RequestBody>); | ||
@@ -425,4 +424,8 @@ /** | ||
* @param config A configuration of the fetcher. | ||
* @param config.appId The application id. | ||
* @param config.transport The transport used when fetching. | ||
* @param config.userContext An object used to determine the requesting user. | ||
* @param config.locationUrlContext An object used to determine the location / base URL. | ||
*/ | ||
constructor({ appId, transport, userContext, locationUrlContext, }: FetcherConfig); | ||
constructor({ appId, transport, userContext, locationUrlContext }: FetcherConfig); | ||
clone(config: Partial<FetcherConfig>): Fetcher; | ||
@@ -442,3 +445,3 @@ /** | ||
*/ | ||
fetchJSON<RequestBody extends object = any, ResponseBody extends object = any>(request: AuthenticatedRequest<RequestBody>): Promise<ResponseBody>; | ||
fetchJSON<RequestBody = any, ResponseBody = any>(request: AuthenticatedRequest<RequestBody>): Promise<ResponseBody>; | ||
/** | ||
@@ -448,2 +451,3 @@ * Fetch an "event-stream" resource as an authenticated user. | ||
* @param request The request which should be sent to the server. | ||
* @returns An async iterator over the response body. | ||
*/ | ||
@@ -475,2 +479,8 @@ fetchStream<RequestBody = unknown>(request: AuthenticatedRequest<RequestBody>): Promise<AsyncIterable<Uint8Array>>; | ||
}; | ||
/** | ||
* Used when getting the location url of the app. | ||
*/ | ||
confirmCall(): { | ||
path: string; | ||
}; | ||
reset(): { | ||
@@ -491,5 +501,2 @@ path: string; | ||
functionsCall(): { | ||
/** | ||
* The user issuing the request. | ||
*/ | ||
path: string; | ||
@@ -522,2 +529,4 @@ }; | ||
/** @inheritdoc */ | ||
retryCustomConfirmation(email: string): Promise<void>; | ||
/** @inheritdoc */ | ||
resetPassword(token: string, tokenId: string, password: string): Promise<void>; | ||
@@ -557,2 +566,3 @@ /** @inheritdoc */ | ||
declare type SimpleObject$1 = Record<string, unknown>; | ||
interface HydratableUserParameters { | ||
@@ -588,3 +598,3 @@ app: App<any>; | ||
*/ | ||
declare class User<FunctionsFactoryType extends object = Realm.DefaultFunctionsFactory, CustomDataType extends object = any, UserProfileDataType = Realm.DefaultUserProfileData> implements Realm.User<FunctionsFactoryType, CustomDataType, UserProfileDataType> { | ||
declare class User<FunctionsFactoryType = Realm.DefaultFunctionsFactory, CustomDataType = SimpleObject$1, UserProfileDataType = Realm.DefaultUserProfileData> implements Realm.User<FunctionsFactoryType, CustomDataType, UserProfileDataType> { | ||
/** | ||
@@ -772,4 +782,7 @@ * The app that this user is associated with. | ||
* @param params Construct the device information from these parameters. | ||
* @param params.appId | ||
* @param params.appVersion | ||
* @param params.deviceId | ||
*/ | ||
constructor({ appId, appVersion, deviceId, }: DeviceInformationParams); | ||
constructor({ appId, appVersion, deviceId }: DeviceInformationParams); | ||
/** | ||
@@ -782,3 +795,3 @@ * @returns An base64 URI encoded representation of the device information. | ||
*/ | ||
toJSON(): this; | ||
toJSON(): Record<string, unknown>; | ||
} | ||
@@ -825,3 +838,3 @@ | ||
*/ | ||
authenticate(credentials: Realm.Credentials<any>, linkingUser?: User<object, object, unknown>): Promise<AuthResponse>; | ||
authenticate(credentials: Realm.Credentials<any>, linkingUser?: User): Promise<AuthResponse>; | ||
/** | ||
@@ -836,2 +849,3 @@ * @param credentials Credentials to use when logging in. | ||
declare type SimpleObject$2 = Record<string, unknown>; | ||
/** | ||
@@ -862,3 +876,3 @@ * Default base url to prefix all requests if no baseUrl is specified in the configuration. | ||
*/ | ||
declare class App<FunctionsFactoryType extends object = Realm.DefaultFunctionsFactory, CustomDataType extends object = any> implements Realm.App<FunctionsFactoryType, CustomDataType> { | ||
declare class App<FunctionsFactoryType = Realm.DefaultFunctionsFactory & Realm.BaseFunctionsFactory, CustomDataType = SimpleObject$2> implements Realm.App<FunctionsFactoryType, CustomDataType> { | ||
/** | ||
@@ -875,3 +889,3 @@ * A map of app instances returned from calling getApp. | ||
*/ | ||
static getApp(id: string): App<Realm.DefaultFunctionsFactory, any>; | ||
static getApp(id: string): App<Realm.DefaultFunctionsFactory & Realm.BaseFunctionsFactory, SimpleObject$2>; | ||
/** @inheritdoc */ | ||
@@ -1084,3 +1098,5 @@ readonly id: string; | ||
*/ | ||
declare function getApp(id: string): App<Realm.DefaultFunctionsFactory, any>; | ||
declare function getApp(id: string): App<Realm.DefaultFunctionsFactory & Realm.BaseFunctionsFactory, { | ||
[x: string]: unknown; | ||
}>; | ||
@@ -1087,0 +1103,0 @@ /** |
{ | ||
"name": "realm-web", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Authenticate and communicate with the MongoDB Realm platform, from your web-browser", | ||
@@ -68,3 +68,2 @@ "main": "./dist/bundle.cjs.js", | ||
"chai": "^4.2.0", | ||
"eslint": "^6.8.0", | ||
"mocha": "^5.2.0", | ||
@@ -77,4 +76,4 @@ "node-fetch": "^2.6.0", | ||
"ts-node": "^8.8.2", | ||
"typescript": "^4.0.2" | ||
"typescript": "^4.2.4" | ||
} | ||
} |
@@ -16,3 +16,3 @@ # Realm Web | ||
```html | ||
<script src="https://unpkg.com/realm-web@1.3.0/dist/bundle.iife.js"></script> | ||
<script src="https://unpkg.com/realm-web@1.4.0/dist/bundle.iife.js"></script> | ||
``` | ||
@@ -19,0 +19,0 @@ |
{ | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": [ | ||
"@typescript-eslint", | ||
"jsdoc", | ||
"prettier", | ||
"header" | ||
], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:prettier/recommended", | ||
"plugin:jsdoc/recommended" | ||
], | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"ignorePatterns": "index.d.ts", | ||
@@ -37,6 +31,2 @@ "rules": { | ||
} | ||
], | ||
"header/header": [ | ||
2, | ||
"./header.js" | ||
] | ||
@@ -43,0 +33,0 @@ }, |
@@ -25,634 +25,611 @@ //////////////////////////////////////////////////////////////////////////// | ||
type SimpleObject = Record<string, unknown>; | ||
declare namespace Realm { | ||
/** | ||
* Types of an authentication provider. | ||
*/ | ||
type ProviderType = | ||
| "anon-user" | ||
| "api-key" | ||
| "local-userpass" | ||
| "custom-function" | ||
| "custom-token" | ||
| "oauth2-google" | ||
| "oauth2-facebook" | ||
| "oauth2-apple"; | ||
namespace Credentials { | ||
/** | ||
* Types of an authentication provider. | ||
* Payload sent when authenticating using the [Anonymous Provider](https://docs.mongodb.com/realm/authentication/anonymous/). | ||
*/ | ||
type ProviderType = | ||
| "anon-user" | ||
| "api-key" | ||
| "local-userpass" | ||
| "custom-function" | ||
| "custom-token" | ||
| "oauth2-google" | ||
| "oauth2-facebook" | ||
| "oauth2-apple"; | ||
type AnonymousPayload = Record<string, never>; | ||
namespace Credentials { | ||
/** | ||
* Payload sent when authenticating using the [Anonymous Provider](https://docs.mongodb.com/realm/authentication/anonymous/). | ||
*/ | ||
type AnonymousPayload = {}; | ||
/** | ||
* Payload sent when authenticating using the [Email/Password Provider](https://docs.mongodb.com/realm/authentication/email-password/). | ||
*/ | ||
type EmailPasswordPayload = { | ||
/** | ||
* The end-users username. | ||
* Note: This currently has to be an email. | ||
*/ | ||
username: string; | ||
/** | ||
* Payload sent when authenticating using the [Email/Password Provider](https://docs.mongodb.com/realm/authentication/email-password/). | ||
*/ | ||
type EmailPasswordPayload = { | ||
/** | ||
* The end-users username. | ||
* Note: This currently has to be an email. | ||
*/ | ||
username: string; | ||
/** | ||
* The end-users password. | ||
*/ | ||
password: string; | ||
}; | ||
/** | ||
* The end-users password. | ||
*/ | ||
password: string; | ||
}; | ||
/** | ||
* Payload sent when authenticating using the [API Key Provider](https://docs.mongodb.com/realm/authentication/api-key/). | ||
*/ | ||
type ApiKeyPayload = { | ||
/** | ||
* The secret content of the API key. | ||
*/ | ||
key: string; | ||
}; | ||
/** | ||
* Payload sent when authenticating using the [API Key Provider](https://docs.mongodb.com/realm/authentication/api-key/). | ||
*/ | ||
type ApiKeyPayload = { | ||
/** | ||
* The secret content of the API key. | ||
*/ | ||
key: string; | ||
}; | ||
/** | ||
* Payload sent when authenticating using the [Custom Function Provider](https://docs.mongodb.com/realm/authentication/custom-function/). | ||
*/ | ||
type FunctionPayload = SimpleObject; | ||
/** | ||
* Payload sent when authenticating using the [Custom Function Provider](https://docs.mongodb.com/realm/authentication/custom-function/). | ||
*/ | ||
type FunctionPayload = object; | ||
/** | ||
* Payload sent when authenticating using the [Custom JWT Provider](https://docs.mongodb.com/realm/authentication/custom-jwt/). | ||
*/ | ||
type JWTPayload = { | ||
/** | ||
* The JSON Web Token signed by another service. | ||
*/ | ||
token: string; | ||
}; | ||
/** | ||
* Payload sent when authenticating using the [Custom JWT Provider](https://docs.mongodb.com/realm/authentication/custom-jwt/). | ||
*/ | ||
type JWTPayload = { | ||
/** | ||
* The JSON Web Token signed by another service. | ||
*/ | ||
token: string; | ||
}; | ||
/** | ||
* Payload sent when authenticating using an OAuth 2.0 provider: | ||
* - [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
* - [Facebook Provider](https://docs.mongodb.com/realm/authentication/facebook/). | ||
*/ | ||
type OAuth2RedirectPayload = { | ||
/** | ||
* The auth code returned from Google. | ||
*/ | ||
redirectUrl: string; | ||
}; | ||
/** | ||
* Payload sent when authenticating using an OAuth 2.0 provider: | ||
* - [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
* - [Facebook Provider](https://docs.mongodb.com/realm/authentication/facebook/). | ||
*/ | ||
type OAuth2RedirectPayload = { | ||
/** | ||
* The auth code returned from Google. | ||
*/ | ||
redirectUrl: string; | ||
}; | ||
/** | ||
* Payload sent when authenticating using the OAuth 2.0 [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
*/ | ||
type GoogleAuthCodePayload = { | ||
/** | ||
* The auth code from Google. | ||
*/ | ||
authCode: string; | ||
}; | ||
/** | ||
* Payload sent when authenticating using the OAuth 2.0 [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
*/ | ||
type GoogleAuthCodePayload = { | ||
/** | ||
* The auth code from Google. | ||
*/ | ||
authCode: string; | ||
}; | ||
/** | ||
* Payload sent when authenticating using the OpenID Connect [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
*/ | ||
type GoogleIdTokenPayload = { | ||
/** | ||
* The OpenID token from Google. | ||
*/ | ||
id_token: string; | ||
}; | ||
/** | ||
* Payload sent when authenticating using the OpenID Connect [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
*/ | ||
type GoogleIdTokenPayload = { | ||
/** | ||
* The OpenID token from Google. | ||
*/ | ||
id_token: string; | ||
}; | ||
/** | ||
* Payload sent when authenticating using the [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
*/ | ||
type GooglePayload = GoogleAuthCodePayload | GoogleIdTokenPayload; | ||
/** | ||
* Payload sent when authenticating using the [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
*/ | ||
type GooglePayload = GoogleAuthCodePayload | GoogleIdTokenPayload; | ||
/** | ||
* Payload sent when authenticating using the [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
*/ | ||
type FacebookPayload = { | ||
/** | ||
* The auth code returned from Google. | ||
*/ | ||
accessToken: string; | ||
}; | ||
/** | ||
* Payload sent when authenticating using the [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
*/ | ||
type FacebookPayload = { | ||
/** | ||
* The auth code returned from Google. | ||
*/ | ||
accessToken: string; | ||
}; | ||
/** | ||
* Payload sent when authenticating using the [Apple ID Provider](https://docs.mongodb.com/realm/authentication/apple/). | ||
*/ | ||
type ApplePayload = { | ||
/** | ||
* The OpenID token from Apple. | ||
*/ | ||
id_token: string; | ||
}; | ||
} | ||
/** | ||
* Payload sent when authenticating using the [Apple ID Provider](https://docs.mongodb.com/realm/authentication/apple/). | ||
*/ | ||
type ApplePayload = { | ||
/** | ||
* The OpenID token from Apple. | ||
*/ | ||
id_token: string; | ||
}; | ||
} | ||
// TODO: Add providerCapabilities? | ||
// TODO: Add providerCapabilities? | ||
/** | ||
* End-users enter credentials to authenticate toward your MongoDB Realm App. | ||
*/ | ||
class Credentials<PayloadType extends SimpleObject = SimpleObject> { | ||
/** | ||
* Name of the authentication provider. | ||
*/ | ||
readonly providerName: string; | ||
/** | ||
* End-users enter credentials to authenticate toward your MongoDB Realm App. | ||
* Type of the authentication provider. | ||
*/ | ||
class Credentials<PayloadType extends object = object> { | ||
/** | ||
* Name of the authentication provider. | ||
*/ | ||
readonly providerName: string; | ||
readonly providerType: ProviderType; | ||
/** | ||
* Type of the authentication provider. | ||
*/ | ||
readonly providerType: ProviderType; | ||
/** | ||
* A simple object which can be passed to the server as the body of a request to authenticate. | ||
*/ | ||
readonly payload: PayloadType; | ||
/** | ||
* A simple object which can be passed to the server as the body of a request to authenticate. | ||
*/ | ||
readonly payload: PayloadType; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [Anonymous Provider](https://docs.mongodb.com/realm/authentication/anonymous/). | ||
* | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static anonymous(): Credentials<Credentials.AnonymousPayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [Anonymous Provider](https://docs.mongodb.com/realm/authentication/anonymous/). | ||
* | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static anonymous(): Credentials<Credentials.AnonymousPayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [API Key Provider](https://docs.mongodb.com/realm/authentication/api-key/). | ||
* | ||
* @deprecated Use `Credentials.apiKey`. | ||
* @param key The secret content of the API key. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static userApiKey(key: string): Credentials<Credentials.ApiKeyPayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [API Key Provider](https://docs.mongodb.com/realm/authentication/api-key/). | ||
* | ||
* @deprecated Use `Credentials.apiKey`. | ||
* | ||
* @param key The secret content of the API key. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static userApiKey(key: string): Credentials<Credentials.ApiKeyPayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [API Key Provider](https://docs.mongodb.com/realm/authentication/api-key/). | ||
* | ||
* @deprecated Use `Credentials.apiKey`. | ||
* @param key The secret content of the API key. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static serverApiKey(key: string): Credentials<Credentials.ApiKeyPayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [API Key Provider](https://docs.mongodb.com/realm/authentication/api-key/). | ||
* | ||
* @deprecated Use `Credentials.apiKey`. | ||
* | ||
* @param key The secret content of the API key. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static serverApiKey( | ||
key: string, | ||
): Credentials<Credentials.ApiKeyPayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [Email/Password Provider](https://docs.mongodb.com/realm/authentication/email-password/). | ||
* Note: This was formerly known as the "Username/Password" provider. | ||
* | ||
* @param email The end-users email address. | ||
* @param password The end-users password. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static emailPassword(email: string, password: string): Credentials<Credentials.EmailPasswordPayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [Email/Password Provider](https://docs.mongodb.com/realm/authentication/email-password/). | ||
* Note: This was formerly known as the "Username/Password" provider. | ||
* | ||
* @param email The end-users email address. | ||
* @param password The end-users password. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static emailPassword( | ||
email: string, | ||
password: string, | ||
): Credentials<Credentials.EmailPasswordPayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [Custom Function Provider](https://docs.mongodb.com/realm/authentication/custom-function/). | ||
* | ||
* @param payload The custom payload as expected by the server. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static function<PayloadType extends Credentials.FunctionPayload = Credentials.FunctionPayload>( | ||
payload: PayloadType, | ||
): Credentials<PayloadType>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [Custom Function Provider](https://docs.mongodb.com/realm/authentication/custom-function/). | ||
* | ||
* @param payload The custom payload as expected by the server. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static function< | ||
PayloadType extends Credentials.FunctionPayload = Credentials.FunctionPayload | ||
>(payload: PayloadType): Credentials<PayloadType>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [Custom JWT Provider](https://docs.mongodb.com/realm/authentication/custom-jwt/). | ||
* | ||
* @param token The JSON Web Token (JWT). | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static jwt(token: string): Credentials<Credentials.JWTPayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [Custom JWT Provider](https://docs.mongodb.com/realm/authentication/custom-jwt/). | ||
* | ||
* @param token The JSON Web Token (JWT). | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static jwt(token: string): Credentials<Credentials.JWTPayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
* | ||
* @param authCode The auth code returned from Google. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static google(authCodeOrIdToken: string): Credentials<Credentials.GooglePayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
* | ||
* @param authCode The auth code returned from Google. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static google( | ||
authCodeOrIdToken: string, | ||
): Credentials<Credentials.GooglePayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the Auth Token OAuth 2.0 [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
* | ||
* @param payload.authCode The auth code from Google. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static google(payload: { | ||
/** | ||
* The auth code from Google. | ||
*/ | ||
authCode: string; | ||
}): Credentials<Credentials.GoogleAuthCodePayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the Auth Token OAuth 2.0 [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
* | ||
* @param payload.authCode The auth code from Google. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static google(payload: { | ||
/** | ||
* The auth code from Google. | ||
*/ | ||
authCode: string; | ||
}): Credentials<Credentials.GoogleAuthCodePayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the OpenID Connect OAuth 2.0 [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
* | ||
* @param payload.idToken The OpenID Connect token from Google. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static google(payload: { | ||
/** | ||
* | ||
*/ | ||
idToken: string; | ||
}): Credentials<Credentials.GoogleIdTokenPayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the OpenID Connect OAuth 2.0 [Google Provider](https://docs.mongodb.com/realm/authentication/google/). | ||
* | ||
* @param payload.idToken The OpenID Connect token from Google. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static google(payload: { | ||
/** | ||
* | ||
*/ | ||
idToken: string; | ||
}): Credentials<Credentials.GoogleIdTokenPayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [Facebook Provider](https://docs.mongodb.com/realm/authentication/facebook/). | ||
* | ||
* @param accessToken The access token returned from Facebook. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static facebook(accessToken: string): Credentials<Credentials.FacebookPayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [Facebook Provider](https://docs.mongodb.com/realm/authentication/facebook/). | ||
* | ||
* @param accessToken The access token returned from Facebook. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static facebook( | ||
accessToken: string, | ||
): Credentials<Credentials.FacebookPayload>; | ||
/** | ||
* Factory for `Credentials` which authenticate using the [Apple ID Provider](https://docs.mongodb.com/realm/authentication/apple/). | ||
* | ||
* @param idToken The id_token returned from Apple. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static apple(idToken: string): Credentials<Credentials.ApplePayload>; | ||
} | ||
/** | ||
* Factory for `Credentials` which authenticate using the [Apple ID Provider](https://docs.mongodb.com/realm/authentication/apple/). | ||
* | ||
* @param idToken The id_token returned from Apple. | ||
* @returns A `Credentials` object for logging in using `app.logIn`. | ||
*/ | ||
static apple(idToken: string): Credentials<Credentials.ApplePayload>; | ||
} | ||
/** | ||
* A MongoDB Realm App. | ||
*/ | ||
class App<FunctionsFactoryType = DefaultFunctionsFactory, CustomDataType = SimpleObject> { | ||
/** | ||
* Construct a MongoDB Realm App. | ||
* | ||
* @param idOrConfiguration The id string or configuration for the app. | ||
*/ | ||
constructor(idOrConfiguration: string | AppConfiguration); | ||
/** | ||
* A MongoDB Realm App. | ||
* All credentials available for authentication. | ||
*/ | ||
class App< | ||
FunctionsFactoryType extends object = DefaultFunctionsFactory, | ||
CustomDataType extends object = any | ||
> { | ||
/** | ||
* Construct a MongoDB Realm App. | ||
* | ||
* @param idOrConfiguration The id string or configuration for the app. | ||
*/ | ||
constructor(idOrConfiguration: string | AppConfiguration); | ||
static readonly Credentials: typeof Credentials; | ||
/** | ||
* All credentials available for authentication. | ||
*/ | ||
static readonly Credentials: typeof Credentials; | ||
/** | ||
* The id of this Realm app. | ||
*/ | ||
readonly id: string; | ||
/** | ||
* The id of this Realm app. | ||
*/ | ||
readonly id: string; | ||
/** | ||
* Perform operations related to the email/password auth provider. | ||
*/ | ||
emailPasswordAuth: Realm.Auth.EmailPasswordAuth; | ||
/** | ||
* Perform operations related to the email/password auth provider. | ||
*/ | ||
emailPasswordAuth: Realm.Auth.EmailPasswordAuth; | ||
/** | ||
* The last user to log in or being switched to. | ||
*/ | ||
readonly currentUser: User<FunctionsFactoryType, CustomDataType> | null; | ||
/** | ||
* The last user to log in or being switched to. | ||
*/ | ||
readonly currentUser: User<FunctionsFactoryType, CustomDataType> | null; | ||
/** | ||
* All authenticated users. | ||
*/ | ||
readonly allUsers: Readonly<Record<string, User<FunctionsFactoryType, CustomDataType>>>; | ||
/** | ||
* All authenticated users. | ||
*/ | ||
readonly allUsers: Readonly< | ||
Record<string, User<FunctionsFactoryType, CustomDataType>> | ||
>; | ||
/** | ||
* Get or create a singleton Realm App from an id. | ||
* Calling this function multiple times with the same id will return the same instance. | ||
* | ||
* @param id The Realm App id visible from the MongoDB Realm UI or a configuration. | ||
* @returns The Realm App instance. | ||
*/ | ||
static getApp(appId: string): App; | ||
/** | ||
* Get or create a singleton Realm App from an id. | ||
* Calling this function multiple times with the same id will return the same instance. | ||
* | ||
* @param id The Realm App id visible from the MongoDB Realm UI or a configuration. | ||
* @returns The Realm App instance. | ||
*/ | ||
static getApp(appId: string): App; | ||
/** | ||
* Log in a user using a specific credential | ||
* | ||
* @param credentials the credentials to use when logging in | ||
*/ | ||
logIn(credentials: Credentials): Promise<User<FunctionsFactoryType, CustomDataType>>; | ||
/** | ||
* Log in a user using a specific credential | ||
* | ||
* @param credentials the credentials to use when logging in | ||
*/ | ||
logIn( | ||
credentials: Credentials, | ||
): Promise<User<FunctionsFactoryType, CustomDataType>>; | ||
/** | ||
* Switch current user, from an instance of `User` or the string id of the user. | ||
*/ | ||
switchUser(user: User<FunctionsFactoryType, CustomDataType>): void; | ||
/** | ||
* Switch current user, from an instance of `User` or the string id of the user. | ||
*/ | ||
switchUser(user: User<FunctionsFactoryType, CustomDataType>): void; | ||
/** | ||
* Logs out and removes a user from the client. | ||
* | ||
* @returns A promise that resolves once the user has been logged out and removed from the app. | ||
*/ | ||
removeUser(user: User<FunctionsFactoryType, CustomDataType>): Promise<void>; | ||
} | ||
/** | ||
* Logs out and removes a user from the client. | ||
* | ||
* @returns A promise that resolves once the user has been logged out and removed from the app. | ||
*/ | ||
removeUser( | ||
user: User<FunctionsFactoryType, CustomDataType>, | ||
): Promise<void>; | ||
} | ||
/** | ||
* Pass an object implementing this interface to the app constructor. | ||
*/ | ||
interface AppConfiguration { | ||
/** | ||
* The Realm App ID | ||
*/ | ||
id: string; | ||
/** | ||
* Pass an object implementing this interface to the app constructor. | ||
* An optional URL to use as a prefix when requesting the MongoDB Realm services. | ||
*/ | ||
interface AppConfiguration { | ||
/** | ||
* The Realm App ID | ||
*/ | ||
id: string; | ||
baseUrl?: string; | ||
/** | ||
* An optional URL to use as a prefix when requesting the MongoDB Realm services. | ||
*/ | ||
baseUrl?: string; | ||
/** | ||
* This describes the local app, sent to the server when a user authenticates. | ||
* Specifying this will enable the server to respond differently to specific versions of specific apps. | ||
*/ | ||
app?: LocalAppConfiguration; | ||
} | ||
/** | ||
* This describes the local app, sent to the server when a user authenticates. | ||
* Specifying this will enable the server to respond differently to specific versions of specific apps. | ||
*/ | ||
app?: LocalAppConfiguration; | ||
} | ||
/** | ||
* This describes the local app, sent to the server when a user authenticates. | ||
*/ | ||
interface LocalAppConfiguration { | ||
/** | ||
* The name / id of the local app. | ||
* Note: This should be the name or a bundle id of your app, not the MongoDB Realm app. | ||
*/ | ||
name?: string; | ||
/** | ||
* This describes the local app, sent to the server when a user authenticates. | ||
* The version of the local app. | ||
*/ | ||
interface LocalAppConfiguration { | ||
/** | ||
* The name / id of the local app. | ||
* Note: This should be the name or a bundle id of your app, not the MongoDB Realm app. | ||
*/ | ||
name?: string; | ||
version?: string; | ||
} | ||
/** | ||
* The version of the local app. | ||
*/ | ||
version?: string; | ||
} | ||
/** | ||
* Representation of an authenticated user of an app. | ||
*/ | ||
class User< | ||
FunctionsFactoryType = DefaultFunctionsFactory, | ||
CustomDataType = SimpleObject, | ||
UserProfileDataType = DefaultUserProfileData | ||
> { | ||
/** | ||
* The automatically-generated internal ID of the user. | ||
*/ | ||
readonly id: string; | ||
/** | ||
* Representation of an authenticated user of an app. | ||
* The provider type used when authenticating the user. | ||
*/ | ||
class User< | ||
FunctionsFactoryType extends object = DefaultFunctionsFactory, | ||
CustomDataType extends object = any, | ||
UserProfileDataType = DefaultUserProfileData | ||
> { | ||
/** | ||
* The automatically-generated internal ID of the user. | ||
*/ | ||
readonly id: string; | ||
readonly providerType: ProviderType; | ||
/** | ||
* The provider type used when authenticating the user. | ||
*/ | ||
readonly providerType: ProviderType; | ||
/** | ||
* The id of the device. | ||
*/ | ||
readonly deviceId: string | null; | ||
/** | ||
* The id of the device. | ||
*/ | ||
readonly deviceId: string | null; | ||
/** | ||
* The state of the user. | ||
*/ | ||
readonly state: UserState; | ||
/** | ||
* The state of the user. | ||
*/ | ||
readonly state: UserState; | ||
/** | ||
* The logged in state of the user. | ||
*/ | ||
readonly isLoggedIn: boolean; | ||
/** | ||
* The logged in state of the user. | ||
*/ | ||
readonly isLoggedIn: boolean; | ||
/** | ||
* The identities of the user at any of the app's authentication providers. | ||
*/ | ||
readonly identities: UserIdentity[]; | ||
/** | ||
* The identities of the user at any of the app's authentication providers. | ||
*/ | ||
readonly identities: UserIdentity[]; | ||
/** | ||
* The access token used when requesting a new access token. | ||
*/ | ||
readonly accessToken: string | null; | ||
/** | ||
* The access token used when requesting a new access token. | ||
*/ | ||
readonly accessToken: string | null; | ||
/** | ||
* The refresh token used when requesting a new access token. | ||
*/ | ||
readonly refreshToken: string | null; | ||
/** | ||
* The refresh token used when requesting a new access token. | ||
*/ | ||
readonly refreshToken: string | null; | ||
/** | ||
* You can store arbitrary data about your application users in a MongoDB collection and configure MongoDB Realm to automatically expose each user’s data in a field of their user object. | ||
* For example, you might store a user’s preferred language, date of birth, or their local timezone. | ||
* | ||
* If this value has not been configured, it will be empty. | ||
*/ | ||
readonly customData: CustomDataType; | ||
/** | ||
* You can store arbitrary data about your application users in a MongoDB collection and configure MongoDB Realm to automatically expose each user’s data in a field of their user object. | ||
* For example, you might store a user’s preferred language, date of birth, or their local timezone. | ||
* | ||
* If this value has not been configured, it will be empty. | ||
*/ | ||
readonly customData: CustomDataType; | ||
/** | ||
* A profile containing additional information about the user. | ||
*/ | ||
readonly profile: UserProfileDataType; | ||
/** | ||
* A profile containing additional information about the user. | ||
*/ | ||
readonly profile: UserProfileDataType; | ||
/** | ||
* Use this to call functions defined by the MongoDB Realm app, as this user. | ||
*/ | ||
readonly functions: FunctionsFactoryType & BaseFunctionsFactory; | ||
/** | ||
* Use this to call functions defined by the MongoDB Realm app, as this user. | ||
*/ | ||
readonly functions: FunctionsFactoryType & BaseFunctionsFactory; | ||
/** | ||
* Perform operations related to the API-key auth provider. | ||
*/ | ||
readonly apiKeys: Realm.Auth.ApiKeyAuth; | ||
/** | ||
* Perform operations related to the API-key auth provider. | ||
*/ | ||
readonly apiKeys: Realm.Auth.ApiKeyAuth; | ||
/** | ||
* Log out the user. | ||
* | ||
* @returns A promise that resolves once the user has been logged out of the app. | ||
*/ | ||
logOut(): Promise<void>; | ||
/** | ||
* Log out the user. | ||
* | ||
* @returns A promise that resolves once the user has been logged out of the app. | ||
*/ | ||
logOut(): Promise<void>; | ||
/** | ||
* Link the user with an identity represented by another set of credentials. | ||
* | ||
* @param credentials The credentials to use when linking. | ||
*/ | ||
linkCredentials(credentials: Credentials): Promise<void>; | ||
/** | ||
* Link the user with an identity represented by another set of credentials. | ||
* | ||
* @param credentials The credentials to use when linking. | ||
*/ | ||
linkCredentials(credentials: Credentials): Promise<void>; | ||
/** | ||
* Call a remote MongoDB Realm function by its name. | ||
* Note: Consider using `functions[name]()` instead of calling this method. | ||
* | ||
* @example | ||
* // These are all equivalent: | ||
* await user.callFunction("doThing", [a1, a2, a3]); | ||
* await user.functions.doThing(a1, a2, a3); | ||
* await user.functions["doThing"](a1, a2, a3); | ||
* @example | ||
* // The methods returned from the functions object are bound, which is why it's okay to store the function in a variable before calling it: | ||
* const doThing = user.functions.doThing; | ||
* await doThing(a1); | ||
* await doThing(a2); | ||
* @param name Name of the function. | ||
* @param args Arguments passed to the function. | ||
*/ | ||
callFunction(name: string, ...args: unknown[]): Promise<unknown>; | ||
/** | ||
* Call a remote MongoDB Realm function by its name. | ||
* Note: Consider using `functions[name]()` instead of calling this method. | ||
* | ||
* @example | ||
* // These are all equivalent: | ||
* await user.callFunction("doThing", [a1, a2, a3]); | ||
* await user.functions.doThing(a1, a2, a3); | ||
* await user.functions["doThing"](a1, a2, a3); | ||
* | ||
* @example | ||
* // The methods returned from the functions object are bound, which is why it's okay to store the function in a variable before calling it: | ||
* const doThing = user.functions.doThing; | ||
* await doThing(a1); | ||
* await doThing(a2); | ||
* | ||
* @param name Name of the function. | ||
* @param args Arguments passed to the function. | ||
*/ | ||
callFunction(name: string, ...args: any[]): Promise<any>; | ||
/** | ||
* Refresh the access token and derive custom data from it. | ||
* | ||
* @returns The newly fetched custom data. | ||
*/ | ||
refreshCustomData(): Promise<CustomDataType>; | ||
/** | ||
* Refresh the access token and derive custom data from it. | ||
* | ||
* @returns The newly fetched custom data. | ||
*/ | ||
refreshCustomData(): Promise<CustomDataType>; | ||
/** | ||
* Use the Push service to enable sending push messages to this user via Firebase Cloud Messaging (FCM). | ||
* | ||
* @returns An service client with methods to register and deregister the device on the user. | ||
*/ | ||
push(serviceName: string): Realm.Services.Push; | ||
/** | ||
* Use the Push service to enable sending push messages to this user via Firebase Cloud Messaging (FCM). | ||
* | ||
* @returns An service client with methods to register and deregister the device on the user. | ||
*/ | ||
push(serviceName: string): Realm.Services.Push; | ||
/** | ||
* Returns a connection to the MongoDB service. | ||
* | ||
* @example | ||
* let blueWidgets = user.mongoClient('myClusterName') | ||
* .db('myDb') | ||
* .collection('widgets') | ||
* .find({color: 'blue'}); | ||
*/ | ||
mongoClient(serviceName: string): Realm.Services.MongoDB; | ||
} | ||
/** | ||
* Returns a connection to the MongoDB service. | ||
* | ||
* @example | ||
* let blueWidgets = user.mongoClient('myClusterName') | ||
* .db('myDb') | ||
* .collection('widgets') | ||
* .find({color: 'blue'}); | ||
*/ | ||
mongoClient(serviceName: string): Realm.Services.MongoDB; | ||
} | ||
/** | ||
* The state of a user. | ||
*/ | ||
enum UserState { | ||
/** Authenticated and available to communicate with services. */ | ||
Active = "active", | ||
/** Logged out, but ready to be logged in. */ | ||
LoggedOut = "logged-out", | ||
/** Removed from the app entirely. */ | ||
Removed = "removed", | ||
} | ||
/** | ||
* The type of a user. | ||
*/ | ||
enum UserType { | ||
/** A normal end-user created this user */ | ||
Normal = "normal", | ||
/** The user was created by the server */ | ||
Server = "server", | ||
} | ||
// TODO: Implement storing these identities on the user | ||
/** | ||
* A user's identity with a particular authentication provider. | ||
*/ | ||
interface UserIdentity { | ||
/** | ||
* The state of a user. | ||
* The id of the identity. | ||
*/ | ||
enum UserState { | ||
/** Authenticated and available to communicate with services. */ | ||
Active = "active", | ||
/** Logged out, but ready to be logged in. */ | ||
LoggedOut = "logged-out", | ||
/** Removed from the app entirely. */ | ||
Removed = "removed", | ||
} | ||
id: string; | ||
/** | ||
* The type of a user. | ||
* The type of the provider associated with the identity. | ||
*/ | ||
enum UserType { | ||
/** A normal end-user created this user */ | ||
Normal = "normal", | ||
/** The user was created by the server */ | ||
Server = "server", | ||
} | ||
providerType: ProviderType; | ||
} | ||
// TODO: Implement storing these identities on the user | ||
/** | ||
* An extended profile with detailed information about the user. | ||
*/ | ||
type DefaultUserProfileData = { | ||
/** | ||
* The commonly displayed name of the user. | ||
*/ | ||
name?: string; | ||
/** | ||
* A user's identity with a particular authentication provider. | ||
* The users email address. | ||
*/ | ||
interface UserIdentity { | ||
/** | ||
* The id of the identity. | ||
*/ | ||
id: string; | ||
email?: string; | ||
/** | ||
* The type of the provider associated with the identity. | ||
*/ | ||
providerType: ProviderType; | ||
} | ||
/** | ||
* A URL referencing a picture associated with the user. | ||
*/ | ||
pictureUrl?: string; | ||
/** | ||
* An extended profile with detailed information about the user. | ||
* The users first name. | ||
*/ | ||
type DefaultUserProfileData = { | ||
/** | ||
* The commonly displayed name of the user. | ||
*/ | ||
name?: string; | ||
firstName?: string; | ||
/** | ||
* The users email address. | ||
*/ | ||
email?: string; | ||
/** | ||
* The users last name. | ||
*/ | ||
lastName?: string; | ||
/** | ||
* A URL referencing a picture associated with the user. | ||
*/ | ||
pictureUrl?: string; | ||
/** | ||
* The users gender. | ||
*/ | ||
gender?: string; // TODO: Determine if this is free-text or actually an enum type. | ||
/** | ||
* The users first name. | ||
*/ | ||
firstName?: string; | ||
/** | ||
* The users birthday. | ||
*/ | ||
birthday?: string; // TODO: Determine the format. | ||
/** | ||
* The users last name. | ||
*/ | ||
lastName?: string; | ||
/** | ||
* The minimal age of the user. | ||
*/ | ||
minAge?: string; | ||
/** | ||
* The users gender. | ||
*/ | ||
gender?: string; // TODO: Determine if this is free-text or actually an enum type. | ||
/** | ||
* The maximal age of the user. | ||
*/ | ||
maxAge?: string; | ||
} & { | ||
/** | ||
* Authentication providers might store additional data here. | ||
*/ | ||
[key: string]: unknown; | ||
}; | ||
/** | ||
* The users birthday. | ||
*/ | ||
birthday?: string; // TODO: Determine the format. | ||
/** | ||
* A function which executes on the MongoDB Realm platform. | ||
*/ | ||
type RealmFunction<R, A extends any[]> = (...args: A) => Promise<R>; | ||
/** | ||
* The minimal age of the user. | ||
*/ | ||
minAge?: string; | ||
/** | ||
* The maximal age of the user. | ||
*/ | ||
maxAge?: string; | ||
} & { | ||
/** | ||
* Authentication providers might store additional data here. | ||
*/ | ||
[key: string]: unknown; | ||
}; | ||
/** | ||
* A collection of functions as defined on the MongoDB Server. | ||
*/ | ||
interface BaseFunctionsFactory { | ||
/** | ||
* A function which executes on the MongoDB Realm platform. | ||
* Call a remote MongoDB Realm function by its name. | ||
* Consider using `functions[name]()` instead of calling this method. | ||
* | ||
* @param name Name of the function. | ||
* @param args Arguments passed to the function. | ||
*/ | ||
type RealmFunction<R, A extends any[]> = (...args: A) => Promise<R>; | ||
callFunction(name: string, ...args: any[]): Promise<any>; | ||
/** | ||
* A collection of functions as defined on the MongoDB Server. | ||
* Call a remote MongoDB Realm function by its name, in a streaming mode. | ||
* Consider using `functions[name]()` instead of calling this method. | ||
* | ||
* @param name Name of the function. | ||
* @param args Arguments passed to the function. | ||
*/ | ||
interface BaseFunctionsFactory { | ||
/** | ||
* Call a remote MongoDB Realm function by its name. | ||
* Consider using `functions[name]()` instead of calling this method. | ||
* | ||
* @param name Name of the function. | ||
* @param args Arguments passed to the function. | ||
*/ | ||
callFunction(name: string, ...args: any[]): Promise<any>; | ||
callFunctionStreaming(name: string, ...args: any[]): Promise<AsyncIterable<Uint8Array>>; | ||
} | ||
/** | ||
* Call a remote MongoDB Realm function by its name, in a streaming mode. | ||
* Consider using `functions[name]()` instead of calling this method. | ||
* | ||
* @param name Name of the function. | ||
* @param args Arguments passed to the function. | ||
*/ | ||
callFunctionStreaming( | ||
name: string, | ||
...args: any[] | ||
): Promise<AsyncIterable<Uint8Array>>; | ||
} | ||
/** | ||
* A collection of functions as defined on the MongoDB Server. | ||
*/ | ||
interface DefaultFunctionsFactory extends BaseFunctionsFactory { | ||
/** | ||
* A collection of functions as defined on the MongoDB Server. | ||
* All the functions are accessable as members on this instance. | ||
*/ | ||
interface DefaultFunctionsFactory extends BaseFunctionsFactory { | ||
/** | ||
* All the functions are accessable as members on this instance. | ||
*/ | ||
[name: string]: RealmFunction<any, any[]>; | ||
} | ||
[name: string]: RealmFunction<any, any[]>; | ||
} | ||
} |
@@ -20,144 +20,143 @@ //////////////////////////////////////////////////////////////////////////// | ||
declare namespace Realm { | ||
/** | ||
* An object with interfaces to all possible authentication providers the app might have. | ||
*/ | ||
interface AuthProviders { | ||
/** Authentication provider where users identify using email and password. */ | ||
emailPassword: Realm.Auth.EmailPasswordAuth; | ||
/** Authentication provider where users identify using an API-key. */ | ||
apiKey: Realm.Auth.ApiKeyAuth; | ||
} | ||
namespace Auth { | ||
/** | ||
* An object with interfaces to all possible authentication providers the app might have. | ||
* Authentication provider where users identify using email and password. | ||
*/ | ||
interface AuthProviders { | ||
/** Authentication provider where users identify using email and password. */ | ||
emailPassword: Realm.Auth.EmailPasswordAuth; | ||
/** Authentication provider where users identify using an API-key. */ | ||
apiKey: Realm.Auth.ApiKeyAuth; | ||
} | ||
class EmailPasswordAuth { | ||
/** | ||
* Register a new user. | ||
* | ||
* @param email The new users email. | ||
* @param password the new users passsword. | ||
*/ | ||
registerUser(email: string, password: string): Promise<void>; | ||
namespace Auth { | ||
/** | ||
* Authentication provider where users identify using email and password. | ||
*/ | ||
class EmailPasswordAuth { | ||
/** | ||
* Register a new user. | ||
* | ||
* @param email The new users email. | ||
* @param password the new users passsword. | ||
*/ | ||
registerUser(email: string, password: string): Promise<void>; | ||
/** | ||
* Confirm a user by the token received. | ||
* | ||
* @param token the token received. | ||
* @param tokenId the id of the token received. | ||
*/ | ||
confirmUser(token: string, tokenId: string): Promise<void>; | ||
/** | ||
* Confirm a user by the token received. | ||
* | ||
* @param token the token received. | ||
* @param tokenId the id of the token received. | ||
*/ | ||
confirmUser(token: string, tokenId: string): Promise<void>; | ||
/** | ||
* Resend the confirmation email. | ||
* | ||
* @param email the email associated to resend the confirmation to. | ||
*/ | ||
resendConfirmationEmail(email: string): Promise<void>; | ||
/** | ||
* Resend the confirmation email. | ||
* | ||
* @param email the email associated to resend the confirmation to. | ||
*/ | ||
resendConfirmationEmail(email: string): Promise<void>; | ||
/** | ||
* Rerun the custom confirmation function. | ||
* | ||
* @param email the email associated to resend the confirmation to. | ||
*/ | ||
retryCustomConfirmation(email: string): Promise<void>; | ||
/** | ||
* Complete resetting the password | ||
* | ||
* @param token the token received. | ||
* @param tokenId the id of the token received. | ||
* @param password the new password. | ||
*/ | ||
resetPassword( | ||
token: string, | ||
tokenId: string, | ||
password: string, | ||
): Promise<void>; | ||
/** | ||
* Complete resetting the password | ||
* | ||
* @param token the token received. | ||
* @param tokenId the id of the token received. | ||
* @param password the new password. | ||
*/ | ||
resetPassword(token: string, tokenId: string, password: string): Promise<void>; | ||
/** | ||
* Send an email with tokens to reset the password. | ||
* | ||
* @param email the email to send the tokens to. | ||
*/ | ||
sendResetPasswordEmail(email: string): Promise<void>; | ||
/** | ||
* Send an email with tokens to reset the password. | ||
* | ||
* @param email the email to send the tokens to. | ||
*/ | ||
sendResetPasswordEmail(email: string): Promise<void>; | ||
/** | ||
* Call the custom function to reset the password. | ||
* | ||
* @param email the email associated with the user. | ||
* @param password the new password. | ||
* @param args one or more arguments to pass to the function. | ||
*/ | ||
callResetPasswordFunction( | ||
email: string, | ||
password: string, | ||
...args: any[], | ||
): Promise<void>; | ||
} | ||
/** | ||
* Call the custom function to reset the password. | ||
* | ||
* @param email the email associated with the user. | ||
* @param password the new password. | ||
* @param args one or more arguments to pass to the function. | ||
*/ | ||
callResetPasswordFunction(email: string, password: string, ...args: any[]): Promise<void>; | ||
} | ||
/** | ||
* The representation of an API-key stored in the service. | ||
*/ | ||
type ApiKey = { | ||
/** | ||
* The internal identifier of the key. | ||
*/ | ||
_id: string; | ||
/** | ||
* The representation of an API-key stored in the service. | ||
*/ | ||
type ApiKey = { | ||
/** | ||
* The internal identifier of the key. | ||
*/ | ||
_id: string; | ||
/** | ||
* The secret part of the key. | ||
*/ | ||
key: string; | ||
/** | ||
* The secret part of the key. | ||
*/ | ||
key: string; | ||
/** | ||
* A name for the key. | ||
*/ | ||
name: string; | ||
/** | ||
* A name for the key. | ||
*/ | ||
name: string; | ||
/** | ||
* When disabled, the key cannot authenticate. | ||
*/ | ||
disabled: boolean; | ||
}; | ||
/** | ||
* When disabled, the key cannot authenticate. | ||
*/ | ||
disabled: boolean; | ||
}; | ||
/** | ||
* Authentication provider where users identify using an API-key. | ||
*/ | ||
class ApiKeyAuth { | ||
/** | ||
* Creates an API key that can be used to authenticate as the current user. | ||
* | ||
* @param name the name of the API key to be created. | ||
*/ | ||
create(name: string): Promise<ApiKey>; | ||
/** | ||
* Authentication provider where users identify using an API-key. | ||
*/ | ||
class ApiKeyAuth { | ||
/** | ||
* Creates an API key that can be used to authenticate as the current user. | ||
* | ||
* @param name the name of the API key to be created. | ||
*/ | ||
create(name: string): Promise<ApiKey>; | ||
/** | ||
* Fetches an API key associated with the current user. | ||
* | ||
* @param keyId the id of the API key to fetch. | ||
*/ | ||
fetch(keyId: string): Promise<ApiKey>; | ||
/** | ||
* Fetches an API key associated with the current user. | ||
* | ||
* @param keyId the id of the API key to fetch. | ||
*/ | ||
fetch(keyId: string): Promise<ApiKey>; | ||
/** | ||
* Fetches the API keys associated with the current user. | ||
*/ | ||
fetchAll(): Promise<ApiKey[]>; | ||
/** | ||
* Fetches the API keys associated with the current user. | ||
*/ | ||
fetchAll(): Promise<ApiKey[]>; | ||
/** | ||
* Deletes an API key associated with the current user. | ||
* | ||
* @param keyId the id of the API key to delete | ||
*/ | ||
delete(keyId: string): Promise<void>; | ||
/** | ||
* Deletes an API key associated with the current user. | ||
* | ||
* @param keyId the id of the API key to delete | ||
*/ | ||
delete(keyId: string): Promise<void>; | ||
/** | ||
* Enables an API key associated with the current user. | ||
* | ||
* @param keyId the id of the API key to enable | ||
*/ | ||
enable(keyId: string): Promise<void>; | ||
/** | ||
* Enables an API key associated with the current user. | ||
* | ||
* @param keyId the id of the API key to enable | ||
*/ | ||
enable(keyId: string): Promise<void>; | ||
/** | ||
* Disable an API key associated with the current user. | ||
* | ||
* @param keyId the id of the API key to disable | ||
*/ | ||
disable(keyId: string): Promise<void>; | ||
} | ||
/** | ||
* Disable an API key associated with the current user. | ||
* | ||
* @param keyId the id of the API key to disable | ||
*/ | ||
disable(keyId: string): Promise<void>; | ||
} | ||
} | ||
} |
@@ -22,6 +22,5 @@ //////////////////////////////////////////////////////////////////////////// | ||
/// <reference path="./app.d.ts"/> | ||
type ObjectId = import("bson").ObjectId; | ||
declare namespace Realm { | ||
@@ -87,2 +86,4 @@ interface CollectionChangeSet { | ||
type PrimaryKey = number | string | Realm.BSON.ObjectId | Realm.BSON.UUID; | ||
/** | ||
@@ -102,8 +103,24 @@ * ObjectType | ||
interface SSLVerifyObject { | ||
serverAddress: string; | ||
serverPort: number; | ||
pemCertificate: string; | ||
acceptedByOpenSSL: boolean; | ||
depth: number; | ||
} | ||
type SSLVerifyCallback = (sslVerifyObject: SSLVerifyObject) => boolean; | ||
interface SSLConfiguration { | ||
validate?: boolean; | ||
certificatePath?: string; | ||
validateCallback?: SSLVerifyCallback; | ||
} | ||
interface SyncConfiguration { | ||
user: User; | ||
partitionValue: string|number|ObjectId|null; | ||
partitionValue: Realm.App.Sync.PartitionValue; | ||
customHttpHeaders?: { [header: string]: string }; | ||
newRealmFileBehavior?: OpenRealmBehaviorConfiguration; | ||
existingRealmFileBehavior?: OpenRealmBehaviorConfiguration; | ||
ssl?: SSLConfiguration; | ||
_sessionStopPolicy?: SessionStopPolicy; | ||
@@ -113,9 +130,6 @@ error?: ErrorCallback; | ||
/** | ||
* realm configuration | ||
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.html#~Configuration } | ||
*/ | ||
interface Configuration { | ||
interface BaseConfiguration { | ||
encryptionKey?: ArrayBuffer | ArrayBufferView | Int8Array; | ||
migration?: MigrationCallback; | ||
schema?: (ObjectClass | ObjectSchema)[]; | ||
schemaVersion?: number; | ||
shouldCompactOnLaunch?: (totalBytes: number, usedBytes: number) => boolean; | ||
@@ -125,6 +139,16 @@ path?: string; | ||
readOnly?: boolean; | ||
} | ||
interface ConfigurationWithSync extends BaseConfiguration { | ||
sync: SyncConfiguration; | ||
migration?: never; | ||
inMemory?: never; | ||
deleteRealmIfMigrationNeeded?: never; | ||
disableFormatUpgrade?: never; | ||
} | ||
interface ConfigurationWithoutSync extends BaseConfiguration { | ||
sync?: never; | ||
migration?: MigrationCallback; | ||
inMemory?: boolean; | ||
schema?: (ObjectClass | ObjectSchema)[]; | ||
schemaVersion?: number; | ||
sync?: SyncConfiguration; | ||
deleteRealmIfMigrationNeeded?: boolean; | ||
@@ -135,2 +159,8 @@ disableFormatUpgrade?: boolean; | ||
/** | ||
* realm configuration | ||
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.html#~Configuration } | ||
*/ | ||
type Configuration = ConfigurationWithSync | ConfigurationWithoutSync; | ||
/** | ||
* realm configuration used for overriding default configuration values. | ||
@@ -152,5 +182,2 @@ * @see { @link https://realm.io/docs/javascript/latest/api/Realm.html#~Configuration } | ||
interface PartialConfiguration extends Partial<Realm.Configuration> { | ||
} | ||
/** | ||
@@ -206,2 +233,7 @@ * Object | ||
removeAllListeners(): void; | ||
/** | ||
* @returns string | ||
*/ | ||
getPropertyType(propertyName: string) : string; | ||
} | ||
@@ -222,2 +254,45 @@ | ||
/** | ||
* Dictionary | ||
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.Dictionary.html } | ||
*/ | ||
type Dictionary<ValueType = Mixed> = DictionaryBase<ValueType> & { | ||
[key: string]: ValueType; | ||
} | ||
interface DictionaryChangeSet { | ||
deletions: string[], | ||
modifications: string[], | ||
insertions: string[] | ||
} | ||
type DictionaryChangeCallback = (dict: Dictionary, changes: DictionaryChangeSet) => void; | ||
const Dictionary: { | ||
new(): never; // This type isn't supposed to be constructed manually by end users. | ||
readonly prototype: Dictionary; | ||
}; | ||
interface DictionaryBase<ValueType = Mixed> { | ||
/** | ||
* Adds given element to the dictionary | ||
* @returns The dictionary | ||
*/ | ||
set(element:{[key:string]: ValueType}): DictionaryBase<ValueType>; | ||
/** | ||
* Removes given element from the dictionary | ||
* @returns The dictionary | ||
*/ | ||
remove(key:string|string[]): DictionaryBase<ValueType>; | ||
/** | ||
* @returns void | ||
*/ | ||
addListener(callback: DictionaryChangeCallback): void; | ||
removeListener(callback: DictionaryChangeCallback): void; | ||
removeAllListeners(): void; | ||
} | ||
/** | ||
* Collection | ||
@@ -287,2 +362,3 @@ * @see { @link https://realm.io/docs/javascript/latest/api/Realm.Collection.html } | ||
const Collection: { | ||
new(): never; // This type isn't supposed to be constructed manually by end users. | ||
readonly prototype: Collection<any>; | ||
@@ -295,3 +371,3 @@ }; | ||
*/ | ||
interface List<T> extends Collection<T> { | ||
interface List<T> extends Collection<T> { | ||
[n: number]: T; | ||
@@ -324,6 +400,47 @@ | ||
const List: { | ||
new(): never; // This type isn't supposed to be constructed manually by end users. | ||
readonly prototype: List<any>; | ||
}; | ||
/** | ||
* Set | ||
* @see { @link https://realm.io/docs/javascript/latest/api/Realm.Set.html } | ||
*/ | ||
interface Set<T> extends Collection<T> { | ||
/** | ||
* Delete a value from the Set | ||
* @param {T} object Value to delete from the Set | ||
* @returns Boolean: true if the value existed in the Set prior to deletion, false otherwise | ||
*/ | ||
delete(object: T): boolean; | ||
/** | ||
* Add a new value to the Set | ||
* @param {T} object Value to add to the Set | ||
* @returns The Realm.Set<T> itself, after adding the new value | ||
*/ | ||
add(object: T): Realm.Set<T>; | ||
/** | ||
* Clear all values from the Set | ||
*/ | ||
clear(): void; | ||
/** | ||
* Check for existence of a value in the Set | ||
* @param {T} object Value to search for in the Set | ||
* @returns Boolean: true if the value exists in the Set, false otherwise | ||
*/ | ||
has(object: T): boolean; | ||
readonly size: number | ||
} | ||
const Set: { | ||
new(): never; // This type isn't supposed to be constructed manually by end users. | ||
readonly prototype: Set<any>; | ||
}; | ||
/** | ||
* Results | ||
@@ -343,5 +460,11 @@ * @see { @link https://realm.io/docs/javascript/latest/api/Realm.Results.html } | ||
const Results: { | ||
new(): never; // This type isn't supposed to be constructed manually by end users. | ||
readonly prototype: Results<any>; | ||
}; | ||
/** | ||
* A primitive value, a BSON value or an object link. | ||
*/ | ||
type Mixed = unknown; | ||
interface UserMap { | ||
@@ -448,4 +571,6 @@ [identity: string]: User | ||
type PartitionValue = string|number|Realm.BSON.ObjectId|Realm.BSON.UUID|null; | ||
function getAllSyncSessions(user: Realm.User): [Realm.App.Sync.Session]; | ||
function getSyncSession(user: Realm.User, partitionValue: string|number|ObjectId|null) : Realm.App.Sync.Session; | ||
function getSyncSession(user: Realm.User, partitionValue: Realm.App.Sync.PartitionValue) : Realm.App.Sync.Session; | ||
function setLogLevel(app: App, logLevel: LogLevel): void; | ||
@@ -470,2 +595,8 @@ function setLogger(app: App, callback: (level: NumericLogLevel, message: string) => void): void; | ||
namespace BSON { | ||
type Decimal128 = import("bson").Decimal128; | ||
type ObjectId = import("bson").ObjectId; | ||
type UUID = import("bson").UUID; | ||
} | ||
const BSON: typeof import("bson"); | ||
@@ -478,2 +609,3 @@ } | ||
} | ||
/** | ||
@@ -490,13 +622,30 @@ * Extracts an intersection of keys from T, where the value extends the given PropType. | ||
type RealmListsRemappedModelPart<T> = { | ||
[K in keyof T]?: T[K] extends Realm.List<infer GT> ? Array<GT | RealmInsertionModel<GT>> : never | ||
[K in ExtractPropertyNamesOfType<T, Realm.List<any>>]?: T[K] extends Realm.List<infer GT> ? Array<GT | RealmInsertionModel<GT>> : never | ||
} | ||
/** | ||
* Exchanges properties defined as Realm.Dicionary<Model> with an optional key to mixed value object. | ||
*/ | ||
type RealmDictionaryRemappedModelPart<T> = { | ||
[K in ExtractPropertyNamesOfType<T, Realm.Dictionary>]?: T[K] extends Realm.Dictionary<infer ValueType> ? { [key: string]: ValueType } : never | ||
} | ||
/** Omits all properties of a model which are not defined by the schema */ | ||
type OmittedRealmTypes<T> = Omit<T, | ||
keyof Realm.Object | | ||
ExtractPropertyNamesOfType<T, Function> | | ||
ExtractPropertyNamesOfType<T, Realm.Collection<any>> | | ||
ExtractPropertyNamesOfType<T, Realm.Dictionary> | ||
>; | ||
/** Remaps realm types to "simpler" types (arrays and objects) */ | ||
type RemappedRealmTypes<T> = | ||
RealmListsRemappedModelPart<T> & | ||
RealmDictionaryRemappedModelPart<T>; | ||
/** | ||
* Joins T stripped of all keys which value extends Realm.Collection and all inherited from Realm.Object, | ||
* with only the keys which value extends Realm.List, remapped as Arrays. | ||
*/ | ||
type RealmInsertionModel<T> = | ||
Omit<Omit<Omit<T, ExtractPropertyNamesOfType<T, Function>>, keyof Realm.Object>, ExtractPropertyNamesOfType<T, Realm.Collection<any>>> | ||
& RealmListsRemappedModelPart<Pick<T, ExtractPropertyNamesOfType<T, Realm.List<any>>>> | ||
type RealmInsertionModel<T> = OmittedRealmTypes<T> & RemappedRealmTypes<T>; | ||
declare class Realm { | ||
@@ -608,13 +757,13 @@ static defaultPath: string; | ||
* @param {string} type | ||
* @param {number|string|ObjectId} key | ||
* @param {number|string|ObjectId|UUID} key | ||
* @returns {T | undefined} | ||
*/ | ||
objectForPrimaryKey<T>(type: string, key: number | string | ObjectId): (T & Realm.Object) | undefined; | ||
objectForPrimaryKey<T>(type: string, key: Realm.PrimaryKey): (T & Realm.Object) | undefined; | ||
/** | ||
* @param {Class} type | ||
* @param {number|string|ObjectId} key | ||
* @param {number|string|ObjectId|UUID} key | ||
* @returns {T | undefined} | ||
*/ | ||
objectForPrimaryKey<T extends Realm.Object>(type: {new(...arg: any[]): T; }, key: number | string | ObjectId): T | undefined; | ||
objectForPrimaryKey<T extends Realm.Object>(type: {new(...arg: any[]): T; }, key: Realm.PrimaryKey): T | undefined; | ||
@@ -656,6 +805,6 @@ /** | ||
/** | ||
* @param {()=>void} callback | ||
* @returns void | ||
* @param {()=>ReturnValueType} callback | ||
* @returns {ReturnValueType} | ||
*/ | ||
write(callback: () => void): void; | ||
write<ReturnValueType>(callback: () => ReturnValueType): ReturnValueType; | ||
@@ -662,0 +811,0 @@ /** |
@@ -24,728 +24,682 @@ //////////////////////////////////////////////////////////////////////////// | ||
declare namespace Realm { | ||
/** | ||
* The MongoDB Realm Services bound to an app. | ||
*/ | ||
interface Services { | ||
/** Get the interface to the remote MongoDB service */ | ||
mongodb(serviceName?: string): Realm.Services.MongoDB; | ||
/** Get the interface to the HTTP service */ | ||
http(serviceName?: string): Realm.Services.HTTP; | ||
} | ||
namespace Services { | ||
/** | ||
* The MongoDB Realm Services bound to an app. | ||
* The MongoDB service can be used to get database and collection objects for interacting with MongoDB data. | ||
*/ | ||
interface Services { | ||
/** Get the interface to the remote MongoDB service */ | ||
mongodb(serviceName?: string): Realm.Services.MongoDB; | ||
/** Get the interface to the HTTP service */ | ||
http(serviceName?: string): Realm.Services.HTTP; | ||
interface MongoDB { | ||
/** | ||
* Get the interface to a remote MongoDB database. | ||
* | ||
* @param databaseName The name of the database. | ||
* @returns The remote MongoDB database. | ||
*/ | ||
db(databaseName: string): MongoDBDatabase; | ||
} | ||
namespace Services { | ||
/** | ||
* The MongoDB service can be used to get database and collection objects for interacting with MongoDB data. | ||
*/ | ||
interface MongoDBDatabase { | ||
/** | ||
* Get the interface to a remote MongoDB collection. | ||
* | ||
* @param name The name of the collection. | ||
* @returns The remote MongoDB collection. | ||
*/ | ||
collection<T extends Realm.Services.MongoDB.Document = any>(name: string): MongoDB.MongoDBCollection<T>; | ||
} | ||
namespace MongoDB { | ||
/** | ||
* Options passed when finding a signle document | ||
*/ | ||
interface FindOneOptions { | ||
/** | ||
* The MongoDB service can be used to get database and collection objects for interacting with MongoDB data. | ||
* Limits the fields to return for all matching documents. | ||
* See [Tutorial: Project Fields to Return from Query](https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/). | ||
*/ | ||
interface MongoDB { | ||
/** | ||
* Get the interface to a remote MongoDB database. | ||
* | ||
* @param databaseName The name of the database. | ||
* @returns The remote MongoDB database. | ||
*/ | ||
db(databaseName: string): MongoDBDatabase; | ||
} | ||
readonly projection?: Record<string, unknown>; | ||
/** | ||
* The MongoDB service can be used to get database and collection objects for interacting with MongoDB data. | ||
* The order in which to return matching documents. | ||
*/ | ||
interface MongoDBDatabase { | ||
/** | ||
* Get the interface to a remote MongoDB collection. | ||
* | ||
* @param name The name of the collection. | ||
* @returns The remote MongoDB collection. | ||
*/ | ||
collection<T extends Realm.Services.MongoDB.Document = any>( | ||
name: string, | ||
): MongoDB.MongoDBCollection<T>; | ||
} | ||
readonly sort?: Record<string, unknown>; | ||
} | ||
namespace MongoDB { | ||
/** | ||
* Options passed when finding a signle document | ||
*/ | ||
interface FindOneOptions { | ||
/** | ||
* Limits the fields to return for all matching documents. | ||
* See [Tutorial: Project Fields to Return from Query](https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/). | ||
*/ | ||
readonly projection?: object; | ||
/** | ||
* Options passed when finding a multiple documents | ||
*/ | ||
interface FindOptions extends FindOneOptions { | ||
/** | ||
* The maximum number of documents to return. | ||
*/ | ||
readonly limit?: number; | ||
} | ||
/** | ||
* The order in which to return matching documents. | ||
*/ | ||
readonly sort?: object; | ||
} | ||
/** | ||
* Options passed when finding and modifying a signle document | ||
*/ | ||
interface FindOneAndModifyOptions extends FindOneOptions { | ||
/** | ||
* Optional. Default: false. | ||
* A boolean that, if true, indicates that MongoDB should insert a new document that matches the | ||
* query filter when the query does not match any existing documents in the collection. | ||
*/ | ||
readonly upsert?: boolean; | ||
/** | ||
* Options passed when finding a multiple documents | ||
*/ | ||
interface FindOptions extends FindOneOptions { | ||
/** | ||
* The maximum number of documents to return. | ||
*/ | ||
readonly limit?: number; | ||
} | ||
/** | ||
* Optional. Default: false. | ||
* A boolean that, if true, indicates that the action should return | ||
* the document in its updated form instead of its original, pre-update form. | ||
*/ | ||
readonly returnNewDocument?: boolean; | ||
} | ||
/** | ||
* Options passed when finding and modifying a signle document | ||
*/ | ||
interface FindOneAndModifyOptions extends FindOneOptions { | ||
/** | ||
* Optional. Default: false. | ||
* A boolean that, if true, indicates that MongoDB should insert a new document that matches the | ||
* query filter when the query does not match any existing documents in the collection. | ||
*/ | ||
readonly upsert?: boolean; | ||
/** | ||
* Options passed when counting documents | ||
*/ | ||
interface CountOptions { | ||
/** | ||
* The maximum number of documents to count. | ||
*/ | ||
readonly limit?: number; | ||
} | ||
/** | ||
* Optional. Default: false. | ||
* A boolean that, if true, indicates that the action should return | ||
* the document in its updated form instead of its original, pre-update form. | ||
*/ | ||
readonly returnNewDocument?: boolean; | ||
} | ||
/** | ||
* Options passed when updating documents | ||
*/ | ||
interface UpdateOptions { | ||
/** | ||
* When true, creates a new document if no document matches the query. | ||
*/ | ||
readonly upsert?: boolean; | ||
} | ||
/** | ||
* Options passed when counting documents | ||
*/ | ||
interface CountOptions { | ||
/** | ||
* The maximum number of documents to count. | ||
*/ | ||
readonly limit?: number; | ||
} | ||
/** | ||
* A document from a MongoDB collection | ||
*/ | ||
interface Document<IdType = any> { | ||
/** | ||
* The id of the document. | ||
*/ | ||
_id: IdType; | ||
} | ||
/** | ||
* Options passed when updating documents | ||
*/ | ||
interface UpdateOptions { | ||
/** | ||
* When true, creates a new document if no document matches the query. | ||
*/ | ||
readonly upsert?: boolean; | ||
} | ||
/** | ||
* A new document with an optional _id defined. | ||
*/ | ||
type NewDocument<T extends Document> = Omit<T, "_id"> & Partial<Pick<T, "_id">>; | ||
/** | ||
* A document from a MongoDB collection | ||
*/ | ||
interface Document<IdType = any> { | ||
/** | ||
* The id of the document. | ||
*/ | ||
_id: IdType; | ||
} | ||
/** | ||
* Result of inserting one document | ||
*/ | ||
interface InsertOneResult<IdType> { | ||
/** | ||
* The id of the inserted document | ||
*/ | ||
readonly insertedId: IdType; | ||
} | ||
/** | ||
* A new document with an optional _id defined. | ||
*/ | ||
type NewDocument<T extends Document> = Omit<T, "_id"> & | ||
Partial<Pick<T, "_id">>; | ||
/** | ||
* Result of inserting many documents | ||
*/ | ||
interface InsertManyResult<IdType> { | ||
/** | ||
* The ids of the inserted documents | ||
*/ | ||
readonly insertedIds: IdType[]; | ||
} | ||
/** | ||
* Result of inserting one document | ||
*/ | ||
interface InsertOneResult<IdType> { | ||
/** | ||
* The id of the inserted document | ||
*/ | ||
readonly insertedId: IdType; | ||
} | ||
/** | ||
* Result of deleting documents | ||
*/ | ||
interface DeleteResult { | ||
/** | ||
* The number of documents that were deleted. | ||
*/ | ||
readonly deletedCount: number; | ||
} | ||
/** | ||
* Result of inserting many documents | ||
*/ | ||
interface InsertManyResult<IdType> { | ||
/** | ||
* The ids of the inserted documents | ||
*/ | ||
readonly insertedIds: IdType[]; | ||
} | ||
/** | ||
* Result of updating documents | ||
*/ | ||
interface UpdateResult<IdType> { | ||
/** | ||
* The number of documents that matched the filter. | ||
*/ | ||
readonly matchedCount: number; | ||
/** | ||
* Result of deleting documents | ||
*/ | ||
interface DeleteResult { | ||
/** | ||
* The number of documents that were deleted. | ||
*/ | ||
readonly deletedCount: number; | ||
} | ||
/** | ||
* The number of documents matched by the query. | ||
*/ | ||
readonly modifiedCount: number; | ||
/** | ||
* Result of updating documents | ||
*/ | ||
interface UpdateResult<IdType> { | ||
/** | ||
* The number of documents that matched the filter. | ||
*/ | ||
readonly matchedCount: number; | ||
/** | ||
* The identifier of the inserted document if an upsert took place. | ||
* | ||
* See [[RemoteUpdateOptions.upsert]]. | ||
*/ | ||
readonly upsertedId?: IdType; | ||
} | ||
/** | ||
* The number of documents matched by the query. | ||
*/ | ||
readonly modifiedCount: number; | ||
/** | ||
* A filter applied to limit the documents being queried for. | ||
*/ | ||
type Filter = Record<string, unknown>; | ||
/** | ||
* The identifier of the inserted document if an upsert took place. | ||
* | ||
* See [[RemoteUpdateOptions.upsert]]. | ||
*/ | ||
readonly upsertedId?: IdType; | ||
} | ||
/** | ||
* An object specifying the update operations to perform when updating a document. | ||
*/ | ||
type Update = Record<string, unknown>; | ||
/** | ||
* A filter applied to limit the documents being queried for. | ||
*/ | ||
type Filter = object; | ||
/** | ||
* A stage of an aggregation pipeline. | ||
*/ | ||
type AggregatePipelineStage = Record<string, unknown>; | ||
/** | ||
* An object specifying the update operations to perform when updating a document. | ||
*/ | ||
type Update = object; | ||
/** | ||
* An operation performed on a document. | ||
*/ | ||
type OperationType = | ||
/** A document got inserted into the collection. */ | ||
| "insert" | ||
/** A document got deleted from the collection. */ | ||
| "delete" | ||
/** A document got replaced in the collection. */ | ||
| "replace" | ||
/** A document got updated in the collection. */ | ||
| "update" | ||
/** Occurs when a collection is dropped from a database. */ | ||
| "drop" | ||
/** Occurs when a collection is renamed. */ | ||
| "rename" | ||
/** Occurs when a database is dropped. */ | ||
| "dropDatabase" | ||
/** Invalidate events close the change stream cursor. */ | ||
| "invalidate"; | ||
/** | ||
* A stage of an aggregation pipeline. | ||
*/ | ||
type AggregatePipelineStage = object; | ||
/** | ||
* The namespace of a document. | ||
*/ | ||
type DocumentNamespace = { | ||
/** The name of the database. */ | ||
db: string; | ||
// database: string; | ||
/** The name of the collection. */ | ||
coll: string; | ||
// collection: string; | ||
}; | ||
/** | ||
* An operation performed on a document. | ||
*/ | ||
type OperationType = | ||
/** A document got inserted into the collection. */ | ||
| "insert" | ||
/** A document got deleted from the collection. */ | ||
| "delete" | ||
/** A document got replaced in the collection. */ | ||
| "replace" | ||
/** A document got updated in the collection. */ | ||
| "update" | ||
/** Occurs when a collection is dropped from a database. */ | ||
| "drop" | ||
/** Occurs when a collection is renamed. */ | ||
| "rename" | ||
/** Occurs when a database is dropped. */ | ||
| "dropDatabase" | ||
/** Invalidate events close the change stream cursor. */ | ||
| "invalidate"; | ||
/** | ||
* A detailed description of an update performed on a document. | ||
*/ | ||
type UpdateDescription = { | ||
/** Names of fields that got updated. */ | ||
updatedFields: Record<string, any>; | ||
/** Names of fields that got removed. */ | ||
removedFields: string[]; | ||
}; | ||
/** | ||
* The namespace of a document. | ||
*/ | ||
type DocumentNamespace = { | ||
/** The name of the database. */ | ||
db: string; | ||
// database: string; | ||
/** The name of the collection. */ | ||
coll: string; | ||
// collection: string; | ||
}; | ||
/** | ||
* Acts as the `resumeToken` for the `resumeAfter` parameter when resuming a change stream. | ||
*/ | ||
type ChangeEventId = any; | ||
/** | ||
* A detailed description of an update performed on a document. | ||
*/ | ||
type UpdateDescription = { | ||
/** Names of fields that got updated. */ | ||
updatedFields: Record<string, any>; | ||
/** Names of fields that got removed. */ | ||
removedFields: string[]; | ||
}; | ||
/** | ||
* A document that contains the _id of the document created or modified by the insert, replace, delete, update operations (i.e. CRUD operations). For sharded collections, also displays the full shard key for the document. The _id field is not repeated if it is already a part of the shard key. | ||
*/ | ||
type DocumentKey<IdType> = { | ||
/** The id of the document. */ | ||
_id: IdType; | ||
} & Record<string, any>; | ||
/** | ||
* Acts as the `resumeToken` for the `resumeAfter` parameter when resuming a change stream. | ||
*/ | ||
type ChangeEventId = any; | ||
/** | ||
* A base change event containing the properties which apply across operation types. | ||
*/ | ||
type BaseChangeEvent<T extends OperationType> = { | ||
/** The id of the change event. */ | ||
_id: ChangeEventId; | ||
/** The type of operation which was performed on the document. */ | ||
operationType: T; | ||
/** The timestamp from the oplog entry associated with the event. */ | ||
clusterTime: Timestamp; | ||
/** | ||
* The transaction number. | ||
* Only present if the operation is part of a multi-document transaction. | ||
*/ | ||
txnNumber?: Long; | ||
/** | ||
* The identifier for the session associated with the transaction. | ||
* Only present if the operation is part of a multi-document transaction. | ||
*/ | ||
lsid?: Record<string, unknown>; | ||
}; | ||
/** | ||
* A document that contains the _id of the document created or modified by the insert, replace, delete, update operations (i.e. CRUD operations). For sharded collections, also displays the full shard key for the document. The _id field is not repeated if it is already a part of the shard key. | ||
*/ | ||
type DocumentKey<IdType> = { | ||
/** The id of the document. */ | ||
_id: IdType; | ||
} & Record<string, any>; | ||
/** | ||
* A document got inserted into the collection. | ||
*/ | ||
type InsertEvent<T extends Document> = { | ||
/** The namespace (database and collection) of the document got inserted into. */ | ||
ns: DocumentNamespace; | ||
/** A document that contains the _id of the inserted document. */ | ||
documentKey: DocumentKey<T["_id"]>; | ||
/** The new document created by the operation */ | ||
fullDocument: T; | ||
} & BaseChangeEvent<"insert">; | ||
/** | ||
* A base change event containing the properties which apply across operation types. | ||
*/ | ||
type BaseChangeEvent<T extends OperationType> = { | ||
/** The id of the change event. */ | ||
_id: ChangeEventId; | ||
/** The type of operation which was performed on the document. */ | ||
operationType: T; | ||
/** The timestamp from the oplog entry associated with the event. */ | ||
clusterTime: Timestamp; | ||
/** | ||
* The transaction number. | ||
* Only present if the operation is part of a multi-document transaction. | ||
*/ | ||
txnNumber?: Long; | ||
/** | ||
* The identifier for the session associated with the transaction. | ||
* Only present if the operation is part of a multi-document transaction. | ||
*/ | ||
lsid?: object; | ||
}; | ||
/** | ||
* A document got updated in the collection. | ||
*/ | ||
type UpdateEvent<T extends Document> = { | ||
/** The namespace (database and collection) of the updated document. */ | ||
ns: DocumentNamespace; | ||
/** A document that contains the _id of the updated document. */ | ||
documentKey: DocumentKey<T["_id"]>; | ||
/** A document describing the fields that were updated or removed. */ | ||
updateDescription: UpdateDescription; | ||
/** | ||
* For change streams opened with the `fullDocument: updateLookup` option, this will represents the most current majority-committed version of the document modified by the update operation. | ||
*/ | ||
fullDocument?: T; | ||
} & BaseChangeEvent<"update">; | ||
/** | ||
* A document got inserted into the collection. | ||
*/ | ||
type InsertEvent<T extends Document> = { | ||
/** The namespace (database and collection) of the document got inserted into. */ | ||
ns: DocumentNamespace; | ||
/** A document that contains the _id of the inserted document. */ | ||
documentKey: DocumentKey<T["_id"]>; | ||
/** The new document created by the operation */ | ||
fullDocument: T; | ||
} & BaseChangeEvent<"insert">; | ||
/** | ||
* A document got replaced in the collection. | ||
*/ | ||
type ReplaceEvent<T extends Document> = { | ||
/** The namespace (database and collection) of the document got replaced within. */ | ||
ns: DocumentNamespace; | ||
/** A document that contains the _id of the replaced document. */ | ||
documentKey: DocumentKey<T["_id"]>; | ||
/** The document after the insert of the replacement document. */ | ||
fullDocument: T; | ||
} & BaseChangeEvent<"replace">; | ||
/** | ||
* A document got updated in the collection. | ||
*/ | ||
type UpdateEvent<T extends Document> = { | ||
/** The namespace (database and collection) of the updated document. */ | ||
ns: DocumentNamespace; | ||
/** A document that contains the _id of the updated document. */ | ||
documentKey: DocumentKey<T["_id"]>; | ||
/** A document describing the fields that were updated or removed. */ | ||
updateDescription: UpdateDescription; | ||
/** | ||
* For change streams opened with the `fullDocument: updateLookup` option, this will represents the most current majority-committed version of the document modified by the update operation. | ||
*/ | ||
fullDocument?: T; | ||
} & BaseChangeEvent<"update">; | ||
/** | ||
* A document got deleted from the collection. | ||
*/ | ||
type DeleteEvent<T extends Document> = { | ||
/** The namespace (database and collection) which the document got deleted from. */ | ||
ns: DocumentNamespace; | ||
/** A document that contains the _id of the deleted document. */ | ||
documentKey: DocumentKey<T["_id"]>; | ||
} & BaseChangeEvent<"delete">; | ||
/** | ||
* A document got replaced in the collection. | ||
*/ | ||
type ReplaceEvent<T extends Document> = { | ||
/** The namespace (database and collection) of the document got replaced within. */ | ||
ns: DocumentNamespace; | ||
/** A document that contains the _id of the replaced document. */ | ||
documentKey: DocumentKey<T["_id"]>; | ||
/** The document after the insert of the replacement document. */ | ||
fullDocument: T; | ||
} & BaseChangeEvent<"replace">; | ||
/** | ||
* Occurs when a collection is dropped from a database. | ||
*/ | ||
type DropEvent = { | ||
/** The namespace (database and collection) of the collection that got dropped. */ | ||
ns: DocumentNamespace; | ||
} & BaseChangeEvent<"drop">; | ||
/** | ||
* A document got deleted from the collection. | ||
*/ | ||
type DeleteEvent<T extends Document> = { | ||
/** The namespace (database and collection) which the document got deleted from. */ | ||
ns: DocumentNamespace; | ||
/** A document that contains the _id of the deleted document. */ | ||
documentKey: DocumentKey<T["_id"]>; | ||
} & BaseChangeEvent<"delete">; | ||
/** | ||
* Occurs when a collection is renamed. | ||
*/ | ||
type RenameEvent = { | ||
/** The original namespace (database and collection) that got renamed. */ | ||
ns: DocumentNamespace; | ||
/** The namespace (database and collection) going forward. */ | ||
to: DocumentNamespace; | ||
} & BaseChangeEvent<"rename">; | ||
/** | ||
* Occurs when a collection is dropped from a database. | ||
*/ | ||
type DropEvent = { | ||
/** The namespace (database and collection) of the collection that got dropped. */ | ||
ns: DocumentNamespace; | ||
} & BaseChangeEvent<"drop">; | ||
/** | ||
* Occurs when a database is dropped. | ||
*/ | ||
type DropDatabaseEvent = { | ||
/** The namespace (specifying only the database name) of the database that got dropped. */ | ||
ns: Omit<DocumentNamespace, "coll">; | ||
} & BaseChangeEvent<"dropDatabase">; | ||
/** | ||
* Occurs when a collection is renamed. | ||
*/ | ||
type RenameEvent = { | ||
/** The original namespace (database and collection) that got renamed. */ | ||
ns: DocumentNamespace; | ||
/** The namespace (database and collection) going forward. */ | ||
to: DocumentNamespace; | ||
} & BaseChangeEvent<"rename">; | ||
/** | ||
* Invalidate events close the change stream cursor. | ||
*/ | ||
type InvalidateEvent = BaseChangeEvent<"invalidate">; | ||
/** | ||
* Occurs when a database is dropped. | ||
*/ | ||
type DropDatabaseEvent = { | ||
/** The namespace (specifying only the database name) of the database that got dropped. */ | ||
ns: Omit<DocumentNamespace, "coll">; | ||
} & BaseChangeEvent<"dropDatabase">; | ||
/** | ||
* Represents a change event communicated via a MongoDB change stream. | ||
* | ||
* @see https://docs.mongodb.com/manual/reference/change-events/ | ||
*/ | ||
type ChangeEvent<T extends Document> = | ||
| InsertEvent<T> | ||
| UpdateEvent<T> | ||
| ReplaceEvent<T> | ||
| DeleteEvent<T> | ||
| DropEvent | ||
| RenameEvent | ||
| DropDatabaseEvent | ||
| InvalidateEvent; | ||
/** | ||
* Invalidate events close the change stream cursor. | ||
*/ | ||
type InvalidateEvent = BaseChangeEvent<"invalidate">; | ||
/** | ||
* A remote collection of documents in a MongoDB database. | ||
*/ | ||
interface MongoDBCollection<T extends Document> { | ||
/** | ||
* Finds the documents which match the provided query. | ||
* | ||
* @param filter An optional filter applied to narrow down the results. | ||
* @param options Additional options to apply. | ||
* @returns The documents. | ||
*/ | ||
find(filter?: Filter, options?: FindOptions): Promise<T[]>; | ||
/** | ||
* Represents a change event communicated via a MongoDB change stream. | ||
* | ||
* @see https://docs.mongodb.com/manual/reference/change-events/ | ||
*/ | ||
type ChangeEvent<T extends Document> = | ||
| InsertEvent<T> | ||
| UpdateEvent<T> | ||
| ReplaceEvent<T> | ||
| DeleteEvent<T> | ||
| DropEvent | ||
| RenameEvent | ||
| DropDatabaseEvent | ||
| InvalidateEvent; | ||
/** | ||
* Finds a document which matches the provided filter. | ||
* | ||
* @param filter A filter applied to narrow down the result. | ||
* @param options Additional options to apply. | ||
* @returns The document. | ||
*/ | ||
findOne(filter?: Filter, options?: FindOneOptions): Promise<T | null>; | ||
/** | ||
* A remote collection of documents in a MongoDB database. | ||
*/ | ||
interface MongoDBCollection<T extends Document> { | ||
/** | ||
* Finds the documents which match the provided query. | ||
* | ||
* @param filter An optional filter applied to narrow down the results. | ||
* @param options Additional options to apply. | ||
* @returns The documents. | ||
*/ | ||
find(filter?: Filter, options?: FindOptions): Promise<T[]>; | ||
/** | ||
* Finds a document which matches the provided query and performs the desired update to individual fields. | ||
* | ||
* @param filter A filter applied to narrow down the result. | ||
* @param update The new values for the document. | ||
* @param options Additional options to apply. | ||
* @returns The document found before updating it. | ||
*/ | ||
findOneAndUpdate(filter: Filter, update: Update, options?: FindOneAndModifyOptions): Promise<T | null>; | ||
/** | ||
* Finds a document which matches the provided filter. | ||
* | ||
* @param filter A filter applied to narrow down the result. | ||
* @param options Additional options to apply. | ||
* @returns The document. | ||
*/ | ||
findOne( | ||
filter?: Filter, | ||
options?: FindOneOptions, | ||
): Promise<T | null>; | ||
/** | ||
* Finds a document which matches the provided filter and replaces it with a new document. | ||
* | ||
* @param filter A filter applied to narrow down the result. | ||
* @param replacement The new replacing document. | ||
* @param options Additional options to apply. | ||
* @returns The document found before replacing it. | ||
*/ | ||
findOneAndReplace( | ||
filter: Filter, | ||
replacement: NewDocument<T>, | ||
options?: FindOneAndModifyOptions, | ||
): Promise<T | null>; | ||
/** | ||
* Finds a document which matches the provided query and performs the desired update to individual fields. | ||
* | ||
* @param filter A filter applied to narrow down the result. | ||
* @param update The new values for the document. | ||
* @param options Additional options to apply. | ||
* @returns The document found before updating it. | ||
*/ | ||
findOneAndUpdate( | ||
filter: Filter, | ||
update: Update, | ||
options?: FindOneAndModifyOptions, | ||
): Promise<T | null>; | ||
/** | ||
* Finds a document which matches the provided filter and deletes it | ||
* | ||
* @param filter A filter applied to narrow down the result. | ||
* @param options Additional options to apply. | ||
* @returns The document found before deleting it. | ||
*/ | ||
findOneAndDelete(filter: Filter, options?: FindOneOptions): Promise<T | null>; | ||
/** | ||
* Finds a document which matches the provided filter and replaces it with a new document. | ||
* | ||
* @param filter A filter applied to narrow down the result. | ||
* @param replacement The new replacing document. | ||
* @param options Additional options to apply. | ||
* @returns The document found before replacing it. | ||
*/ | ||
findOneAndReplace( | ||
filter: Filter, | ||
replacement: NewDocument<T>, | ||
options?: FindOneAndModifyOptions, | ||
): Promise<T | null>; | ||
// TODO: Verify pipeline and return type | ||
/** | ||
* Finds a document which matches the provided filter and deletes it | ||
* | ||
* @param filter A filter applied to narrow down the result. | ||
* @param options Additional options to apply. | ||
* @returns The document found before deleting it. | ||
*/ | ||
findOneAndDelete( | ||
filter: Filter, | ||
options?: FindOneOptions, | ||
): Promise<T | null>; | ||
/** | ||
* Runs an aggregation framework pipeline against this collection. | ||
* | ||
* @param pipeline An array of aggregation pipeline stages. | ||
* @returns The result. | ||
*/ | ||
aggregate(pipeline: AggregatePipelineStage[]): Promise<any>; | ||
// TODO: Verify pipeline and return type | ||
/** | ||
* Counts the number of documents in this collection matching the provided filter. | ||
*/ | ||
count(filter?: Filter, options?: CountOptions): Promise<number>; | ||
/** | ||
* Runs an aggregation framework pipeline against this collection. | ||
* | ||
* @param pipeline An array of aggregation pipeline stages. | ||
* @returns The result. | ||
*/ | ||
aggregate(pipeline: AggregatePipelineStage[]): Promise<any>; | ||
/** | ||
* Inserts a single document into the collection. | ||
* Note: If the document is missing an _id, one will be generated for it by the server. | ||
* | ||
* @param document The document. | ||
* @returns The result. | ||
*/ | ||
insertOne(document: NewDocument<T>): Promise<InsertOneResult<T["_id"]>>; | ||
/** | ||
* Counts the number of documents in this collection matching the provided filter. | ||
*/ | ||
count(filter?: Filter, options?: CountOptions): Promise<number>; | ||
/** | ||
* Inserts an array of documents into the collection. | ||
* If any values are missing identifiers, they will be generated by the server. | ||
* | ||
* @param document The array of documents. | ||
* @returns The result. | ||
*/ | ||
insertMany(documents: NewDocument<T>[]): Promise<InsertManyResult<T["_id"]>>; | ||
/** | ||
* Inserts a single document into the collection. | ||
* Note: If the document is missing an _id, one will be generated for it by the server. | ||
* | ||
* @param document The document. | ||
* @returns The result. | ||
*/ | ||
insertOne( | ||
document: NewDocument<T>, | ||
): Promise<InsertOneResult<T["_id"]>>; | ||
/** | ||
* Deletes a single matching document from the collection. | ||
* | ||
* @param filter A filter applied to narrow down the result. | ||
* @returns The result. | ||
*/ | ||
deleteOne(filter: Filter): Promise<DeleteResult>; | ||
/** | ||
* Inserts an array of documents into the collection. | ||
* If any values are missing identifiers, they will be generated by the server. | ||
* | ||
* @param document The array of documents. | ||
* @returns The result. | ||
*/ | ||
insertMany( | ||
documents: NewDocument<T>[], | ||
): Promise<InsertManyResult<T["_id"]>>; | ||
/** | ||
* Deletes multiple documents. | ||
* | ||
* @param filter A filter applied to narrow down the result. | ||
* @returns The result. | ||
*/ | ||
deleteMany(filter: Filter): Promise<DeleteResult>; | ||
/** | ||
* Deletes a single matching document from the collection. | ||
* | ||
* @param filter A filter applied to narrow down the result. | ||
* @returns The result. | ||
*/ | ||
deleteOne(filter: Filter): Promise<DeleteResult>; | ||
/** | ||
* Updates a single document matching the provided filter in this collection. | ||
* | ||
* @param filter A filter applied to narrow down the result. | ||
* @param update The new values for the document. | ||
* @param options Additional options to apply. | ||
* @returns The result. | ||
*/ | ||
updateOne(filter: Filter, update: Update, options?: UpdateOptions): Promise<UpdateResult<T["_id"]>>; | ||
/** | ||
* Deletes multiple documents. | ||
* | ||
* @param filter A filter applied to narrow down the result. | ||
* @returns The result. | ||
*/ | ||
deleteMany(filter: Filter): Promise<DeleteResult>; | ||
/** | ||
* Updates multiple documents matching the provided filter in this collection. | ||
* | ||
* @param filter A filter applied to narrow down the result. | ||
* @param update The new values for the documents. | ||
* @param options Additional options to apply. | ||
* @returns The result. | ||
*/ | ||
updateMany(filter: Filter, update: Update, options?: UpdateOptions): Promise<UpdateResult<T["_id"]>>; | ||
/** | ||
* Updates a single document matching the provided filter in this collection. | ||
* | ||
* @param filter A filter applied to narrow down the result. | ||
* @param update The new values for the document. | ||
* @param options Additional options to apply. | ||
* @returns The result. | ||
*/ | ||
updateOne( | ||
filter: Filter, | ||
update: Update, | ||
options?: UpdateOptions, | ||
): Promise<UpdateResult<T["_id"]>>; | ||
/** | ||
* Creates an asynchronous change stream to monitor this collection for changes. | ||
* | ||
* By default, yields all change events for this collection. You may specify at most one of | ||
* the `filter` or `ids` options. | ||
* | ||
* @param options.filter A filter for which change events you are interested in. | ||
* @param options.ids A list of ids that you are interested in watching. | ||
* @see https://docs.mongodb.com/manual/reference/change-events/ | ||
*/ | ||
watch(options?: unknown): AsyncGenerator<ChangeEvent<T>>; | ||
/** | ||
* Updates multiple documents matching the provided filter in this collection. | ||
* | ||
* @param filter A filter applied to narrow down the result. | ||
* @param update The new values for the documents. | ||
* @param options Additional options to apply. | ||
* @returns The result. | ||
*/ | ||
updateMany( | ||
filter: Filter, | ||
update: Update, | ||
options?: UpdateOptions, | ||
): Promise<UpdateResult<T["_id"]>>; | ||
/** | ||
* Creates an asynchronous change stream to monitor this collection for changes. | ||
* | ||
* By default, yields all change events for this collection. You may specify at most one of | ||
* the `filter` or `ids` options. | ||
* | ||
* @param options.filter A filter for which change events you are interested in. | ||
* @param options.ids A list of ids that you are interested in watching. | ||
* @see https://docs.mongodb.com/manual/reference/change-events/ | ||
*/ | ||
watch(options: { | ||
/** List of ids to watch */ | ||
ids: T["_id"][]; | ||
}): AsyncGenerator<ChangeEvent<T>>; | ||
/** | ||
* Creates an asynchronous change stream to monitor this collection for changes. | ||
* | ||
* By default, yields all change events for this collection. You may specify at most one of | ||
* the `filter` or `ids` options. | ||
* | ||
* @param options.filter A filter for which change events you are interested in. | ||
* @param options.ids A list of ids that you are interested in watching. | ||
* | ||
* @see https://docs.mongodb.com/manual/reference/change-events/ | ||
*/ | ||
watch(options?: {}): AsyncGenerator<ChangeEvent<T>>; | ||
/** | ||
* Creates an asynchronous change stream to monitor this collection for changes. | ||
* | ||
* By default, yields all change events for this collection. You may specify at most one of | ||
* the `filter` or `ids` options. | ||
* | ||
* @param options.filter A filter for which change events you are interested in. | ||
* @param options.ids A list of ids that you are interested in watching. | ||
* | ||
* @see https://docs.mongodb.com/manual/reference/change-events/ | ||
*/ | ||
watch(options: { | ||
/** List of ids to watch */ | ||
ids: T["_id"][]; | ||
}): AsyncGenerator<ChangeEvent<T>>; | ||
/** | ||
* Creates an asynchronous change stream to monitor this collection for changes. | ||
* | ||
* By default, yields all change events for this collection. | ||
* You may specify at most one of the `filter` or `ids` options. | ||
* | ||
* @param options.filter A filter for which change events you are interested in. | ||
* @param options.ids A list of ids that you are interested in watching. | ||
* | ||
* @see https://docs.mongodb.com/manual/reference/change-events/ | ||
*/ | ||
watch(options: { | ||
/** A filter document */ | ||
filter: Filter; | ||
}): AsyncGenerator<ChangeEvent<T>>; | ||
} | ||
} | ||
/** | ||
* The Stitch HTTP Service is a generic interface that enables you to communicate with any service that is available over HTTP. | ||
* Creates an asynchronous change stream to monitor this collection for changes. | ||
* | ||
* @see https://docs.mongodb.com/stitch/services/http/ | ||
* By default, yields all change events for this collection. | ||
* You may specify at most one of the `filter` or `ids` options. | ||
* | ||
* @param options.filter A filter for which change events you are interested in. | ||
* @param options.ids A list of ids that you are interested in watching. | ||
* @see https://docs.mongodb.com/manual/reference/change-events/ | ||
*/ | ||
interface HTTP { | ||
/** | ||
* Sends an HTTP GET request to the specified URL. | ||
* | ||
* @param url The URL to send the request to. | ||
* @param options Options related to the request. | ||
* @returns The response. | ||
*/ | ||
get( | ||
url: string, | ||
options?: HTTP.RequestOptions, | ||
): Promise<HTTP.Response>; | ||
watch(options: { | ||
/** A filter document */ | ||
filter: Filter; | ||
}): AsyncGenerator<ChangeEvent<T>>; | ||
} | ||
} | ||
/** | ||
* Sends an HTTP POST request to the specified URL. | ||
* | ||
* @param url The URL to send the request to. | ||
* @param options Options related to the request. | ||
* @returns The response. | ||
*/ | ||
post( | ||
url: string, | ||
options?: HTTP.RequestOptions, | ||
): Promise<HTTP.Response>; | ||
/** | ||
* The Stitch HTTP Service is a generic interface that enables you to communicate with any service that is available over HTTP. | ||
* | ||
* @see https://docs.mongodb.com/stitch/services/http/ | ||
*/ | ||
interface HTTP { | ||
/** | ||
* Sends an HTTP GET request to the specified URL. | ||
* | ||
* @param url The URL to send the request to. | ||
* @param options Options related to the request. | ||
* @returns The response. | ||
*/ | ||
get(url: string, options?: HTTP.RequestOptions): Promise<HTTP.Response>; | ||
/** | ||
* Sends an HTTP PUT request to the specified URL. | ||
* | ||
* @param url The URL to send the request to. | ||
* @param options Options related to the request. | ||
* @returns The response. | ||
*/ | ||
put( | ||
url: string, | ||
options?: HTTP.RequestOptions, | ||
): Promise<HTTP.Response>; | ||
/** | ||
* Sends an HTTP POST request to the specified URL. | ||
* | ||
* @param url The URL to send the request to. | ||
* @param options Options related to the request. | ||
* @returns The response. | ||
*/ | ||
post(url: string, options?: HTTP.RequestOptions): Promise<HTTP.Response>; | ||
/** | ||
* Sends an HTTP DELETE request to the specified URL. | ||
* | ||
* @param url The URL to send the request to. | ||
* @param options Options related to the request. | ||
* @returns The response. | ||
*/ | ||
delete( | ||
url: string, | ||
options?: HTTP.RequestOptions, | ||
): Promise<HTTP.Response>; | ||
/** | ||
* Sends an HTTP PUT request to the specified URL. | ||
* | ||
* @param url The URL to send the request to. | ||
* @param options Options related to the request. | ||
* @returns The response. | ||
*/ | ||
put(url: string, options?: HTTP.RequestOptions): Promise<HTTP.Response>; | ||
/** | ||
* Sends an HTTP HEAD request to the specified URL. | ||
* | ||
* @param url The URL to send the request to. | ||
* @param options Options related to the request. | ||
* @returns The response. | ||
*/ | ||
head( | ||
url: string, | ||
options?: HTTP.RequestOptions, | ||
): Promise<HTTP.Response>; | ||
/** | ||
* Sends an HTTP DELETE request to the specified URL. | ||
* | ||
* @param url The URL to send the request to. | ||
* @param options Options related to the request. | ||
* @returns The response. | ||
*/ | ||
delete(url: string, options?: HTTP.RequestOptions): Promise<HTTP.Response>; | ||
/** | ||
* Sends an HTTP PATCH request to the specified URL. | ||
* | ||
* @param url The URL to send the request to. | ||
* @param options Options related to the request. | ||
* @returns The response. | ||
*/ | ||
patch( | ||
url: string, | ||
options?: HTTP.RequestOptions, | ||
): Promise<HTTP.Response>; | ||
} | ||
/** | ||
* Sends an HTTP HEAD request to the specified URL. | ||
* | ||
* @param url The URL to send the request to. | ||
* @param options Options related to the request. | ||
* @returns The response. | ||
*/ | ||
head(url: string, options?: HTTP.RequestOptions): Promise<HTTP.Response>; | ||
namespace HTTP { | ||
/** | ||
* Options to use when sending a request. | ||
*/ | ||
interface RequestOptions { | ||
// TODO: Add a link to its documentation. | ||
/** | ||
* Sends an HTTP PATCH request to the specified URL. | ||
* | ||
* @param url The URL to send the request to. | ||
* @param options Options related to the request. | ||
* @returns The response. | ||
*/ | ||
patch(url: string, options?: HTTP.RequestOptions): Promise<HTTP.Response>; | ||
} | ||
/** | ||
* A url to request from the service to retrieve the authorization header. | ||
*/ | ||
authUrl?: string; | ||
namespace HTTP { | ||
/** | ||
* Options to use when sending a request. | ||
*/ | ||
interface RequestOptions { | ||
// TODO: Add a link to its documentation. | ||
// TODO: Determine if headers could map to a single string too | ||
/** | ||
* Headers used when sending the request. | ||
*/ | ||
headers?: { [name: string]: string[] }; | ||
/** | ||
* A url to request from the service to retrieve the authorization header. | ||
*/ | ||
authUrl?: string; | ||
/** | ||
* Cookies used when sending the request. | ||
*/ | ||
cookies?: { [name: string]: string }; | ||
// TODO: Determine if headers could map to a single string too | ||
/** | ||
* Headers used when sending the request. | ||
*/ | ||
headers?: { [name: string]: string[] }; | ||
/** | ||
* String encoded body sent in the request. | ||
*/ | ||
body?: string; | ||
/** | ||
* Cookies used when sending the request. | ||
*/ | ||
cookies?: { [name: string]: string }; | ||
/** | ||
* Is the body a stringified JSON object? (application/json) | ||
*/ | ||
encodeBodyAsJSON?: boolean; | ||
/** | ||
* String encoded body sent in the request. | ||
*/ | ||
body?: string; | ||
/** | ||
* Is the body stringified form? (multipart/form-data) | ||
*/ | ||
form?: boolean; | ||
/** | ||
* Is the body a stringified JSON object? (application/json) | ||
*/ | ||
encodeBodyAsJSON?: boolean; | ||
/** | ||
* Should redirects be followed? | ||
*/ | ||
followRedirects?: boolean; | ||
} | ||
/** | ||
* Is the body stringified form? (multipart/form-data) | ||
*/ | ||
form?: boolean; | ||
/** | ||
* | ||
*/ | ||
interface Response { | ||
/** | ||
* A text representation of the status. | ||
*/ | ||
status: string; | ||
/** | ||
* Should redirects be followed? | ||
*/ | ||
followRedirects?: boolean; | ||
} | ||
/** | ||
* The nummeric status code. | ||
*/ | ||
statusCode: number; | ||
/** | ||
* | ||
*/ | ||
interface Response { | ||
/** | ||
* A text representation of the status. | ||
*/ | ||
status: string; | ||
/** | ||
* The length of the content. | ||
*/ | ||
contentLength: number; | ||
/** | ||
* The nummeric status code. | ||
*/ | ||
statusCode: number; | ||
/** | ||
* The headers of the response. | ||
*/ | ||
headers: { [name: string]: string[] }; | ||
/** | ||
* The length of the content. | ||
*/ | ||
contentLength: number; | ||
/** | ||
* A BSON binary representation of the body. | ||
*/ | ||
body: Binary; | ||
} | ||
} | ||
/** | ||
* The headers of the response. | ||
*/ | ||
headers: { [name: string]: string[] }; | ||
/** | ||
* Use the Push service to enable sending push messages to this user via Firebase Cloud Messaging (FCM). | ||
* A BSON binary representation of the body. | ||
*/ | ||
interface Push { | ||
/** | ||
* Register this device with the user. | ||
* | ||
* @param token A Firebase Cloud Messaging (FCM) token, retrieved via the firebase SDK. | ||
*/ | ||
register(token: string): Promise<void>; | ||
body: Binary; | ||
} | ||
} | ||
/** | ||
* Deregister this device with the user, to disable sending messages to this device. | ||
*/ | ||
deregister(): Promise<void>; | ||
} | ||
/** | ||
* Use the Push service to enable sending push messages to this user via Firebase Cloud Messaging (FCM). | ||
*/ | ||
interface Push { | ||
/** | ||
* Register this device with the user. | ||
* | ||
* @param token A Firebase Cloud Messaging (FCM) token, retrieved via the firebase SDK. | ||
*/ | ||
register(token: string): Promise<void>; | ||
/** | ||
* Deregister this device with the user, to disable sending messages to this device. | ||
*/ | ||
deregister(): Promise<void>; | ||
} | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19
1034555
13
26442