@litbase/react 4.0.7 → 4.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binary-id/src/base64.d.ts +18 -0
- package/binary-id/src/binary-id-generator.d.ts +20 -0
- package/binary-id/src/binary-id.d.ts +28 -0
- package/binary-id/src/binary-string.d.ts +2 -0
- package/binary-id/src/index.d.ts +4 -0
- package/client/src/config.d.ts +12 -0
- package/client/src/index.d.ts +3 -0
- package/client/src/litbase-client.d.ts +62 -0
- package/client/src/remote-collection.d.ts +16 -0
- package/client/src/upload-file-to-url.d.ts +26 -0
- package/client-react/src/hooks/use-current-user.d.ts +2 -0
- package/client-react/src/hooks/use-query.d.ts +7 -0
- package/client-react/src/index.d.ts +2 -0
- package/core/src/auth/index.d.ts +2 -0
- package/core/src/auth/session-interface.d.ts +33 -0
- package/core/src/auth/user-interface.d.ts +27 -0
- package/core/src/errors/auth-error.d.ts +3 -0
- package/core/src/errors/index.d.ts +1 -0
- package/core/src/index.d.ts +22 -0
- package/core/src/litql/bulk-write-operation.d.ts +31 -0
- package/core/src/litql/database-interface.d.ts +38 -0
- package/core/src/litql/in-memory-database-collection.d.ts +19 -0
- package/core/src/litql/index.d.ts +8 -0
- package/core/src/litql/litql-query.d.ts +4 -0
- package/core/src/litql/litql-types.d.ts +108 -0
- package/core/src/litql/litql.d.ts +163 -0
- package/core/src/litql/query-compiler/compiler-helpers.d.ts +5 -0
- package/core/src/litql/query-compiler/update-compiler.d.ts +2 -0
- package/core/src/logger/console-transport.d.ts +2 -0
- package/core/src/logger/index.d.ts +2 -0
- package/core/src/logger/logger.d.ts +33 -0
- package/core/src/rpc-client-definitions/index.d.ts +1 -0
- package/core/src/rpc-client-definitions/session-definitions.d.ts +3 -0
- package/core/src/rpc-definitions/auth-definitions.d.ts +54 -0
- package/core/src/rpc-definitions/files-definitions.d.ts +14 -0
- package/core/src/rpc-definitions/index.d.ts +4 -0
- package/core/src/rpc-definitions/litql-definitions.d.ts +3 -0
- package/core/src/rpc-definitions/session-definitions.d.ts +2 -0
- package/core/src/rpc-message-logger.d.ts +15 -0
- package/core/src/utils/create-change-observable.d.ts +2 -0
- package/core/src/utils/deep-assign.d.ts +1 -0
- package/core/src/utils/deep-transform.d.ts +1 -0
- package/core/src/utils/exhaust-map-with-trailing.d.ts +1 -0
- package/core/src/utils/get-in.d.ts +1 -0
- package/core/src/utils/get-value-of.d.ts +2 -0
- package/core/src/utils/is-email.d.ts +7 -0
- package/core/src/utils/is-plain-object.d.ts +1 -0
- package/core/src/utils/iterable-utils.d.ts +4 -0
- package/core/src/utils/set.d.ts +1 -0
- package/core/src/utils/simple-object-iterator.d.ts +5 -0
- package/event-emitter/src/index.d.ts +45 -0
- package/package.json +4 -4
- package/rxpc/src/encode-data.d.ts +3 -0
- package/rxpc/src/index.d.ts +5 -0
- package/rxpc/src/loopback-rpc-client.d.ts +7 -0
- package/rxpc/src/rpc-client-interface.d.ts +45 -0
- package/rxpc/src/rpc-message.d.ts +70 -0
- package/rxpc/src/rxpc.d.ts +49 -0
- package/rxpc/src/web-socket-rpc-client.d.ts +14 -0
- package/utils/src/deferred.d.ts +6 -0
- package/utils/src/delay.d.ts +2 -0
- package/utils/src/index.d.ts +3 -0
- package/utils/src/is-promise.d.ts +1 -0
- package/hooks/use-current-user.d.ts +0 -5
- package/hooks/use-query.d.ts +0 -10
- package/index.d.ts +0 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* use this to make a Base64 encoded string URL friendly,
|
|
3
|
+
* i.e. '+' and '/' are replaced with '-' and '_' also any trailing '='
|
|
4
|
+
* characters are removed
|
|
5
|
+
*
|
|
6
|
+
* @param {String} str the encoded string
|
|
7
|
+
* @returns {String} the URL friendly encoded String
|
|
8
|
+
*/
|
|
9
|
+
export declare function toUrlSafeBase64(str: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Use this to recreate a Base64 encoded string that was made URL friendly
|
|
12
|
+
* using Base64EncodeurlFriendly.
|
|
13
|
+
* '-' and '_' are replaced with '+' and '/' and also it is padded with '+'
|
|
14
|
+
*
|
|
15
|
+
* @param {String} str the encoded string
|
|
16
|
+
* @returns {String} the URL friendly encoded String
|
|
17
|
+
*/
|
|
18
|
+
export declare function fromUrlSafeBase64(str: string): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BinaryId } from "./binary-id.js";
|
|
2
|
+
export declare class BinaryIdGenerator {
|
|
3
|
+
counter: number;
|
|
4
|
+
constructor(counter?: number);
|
|
5
|
+
create(): BinaryId;
|
|
6
|
+
createNested(id: BinaryId): BinaryId;
|
|
7
|
+
protected getCurrentTime(): number;
|
|
8
|
+
protected fillRandomValues(buffer: Uint8Array): void;
|
|
9
|
+
}
|
|
10
|
+
export declare class TestBinaryIdGenerator extends BinaryIdGenerator {
|
|
11
|
+
constructor();
|
|
12
|
+
peekNext(): BinaryId;
|
|
13
|
+
createWithCounter(value: number): BinaryId;
|
|
14
|
+
protected getCurrentTime(): number;
|
|
15
|
+
protected fillRandomValues(buffer: Uint8Array): void;
|
|
16
|
+
}
|
|
17
|
+
export declare let defaultBinaryIdGenerator: BinaryIdGenerator;
|
|
18
|
+
export declare function replaceDefaultBinaryIdGenerator(newValue: BinaryIdGenerator): void;
|
|
19
|
+
export declare function createBinaryId(): BinaryId;
|
|
20
|
+
export declare function createNestedBinaryId(nested: BinaryId): BinaryId;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const binaryIdByteLength = 12;
|
|
2
|
+
export declare const nestedBinaryIdByteLength: number;
|
|
3
|
+
export declare const binaryIdStringLength: number;
|
|
4
|
+
export declare const nestedBinaryIdStringLength: number;
|
|
5
|
+
export declare class BinaryId {
|
|
6
|
+
get length(): number;
|
|
7
|
+
get isNested(): boolean;
|
|
8
|
+
get isEmpty(): boolean;
|
|
9
|
+
get isInvalid(): boolean;
|
|
10
|
+
readonly value: string;
|
|
11
|
+
static equals(a: BinaryId | null | undefined, b: BinaryId | null | undefined): boolean;
|
|
12
|
+
static fromBase64String(value: string): BinaryId;
|
|
13
|
+
static fromUrlSafeString(value: string): BinaryId;
|
|
14
|
+
constructor(value: string | ArrayBufferView | BinaryId);
|
|
15
|
+
equals(other: BinaryId): boolean;
|
|
16
|
+
compare(other: BinaryId): number;
|
|
17
|
+
getNested(): BinaryId;
|
|
18
|
+
getDate(): Date;
|
|
19
|
+
toBinary(): Uint8Array;
|
|
20
|
+
toUrlSafeString(): string;
|
|
21
|
+
toBase64String(): string;
|
|
22
|
+
toString(): string;
|
|
23
|
+
toJSON(): string;
|
|
24
|
+
valueOf(): string;
|
|
25
|
+
}
|
|
26
|
+
export declare const EMPTY_ID: BinaryId;
|
|
27
|
+
export declare const EMPTY_NESTED_ID: BinaryId;
|
|
28
|
+
export declare const INVALID_ID: BinaryId;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ProjectionObject, RpcMessageLoggerOptions } from "@litbase/core";
|
|
2
|
+
import { UploadFileOptions } from "./litbase-client.js";
|
|
3
|
+
export declare const config: ClientConfigInterface;
|
|
4
|
+
export interface ClientConfigInterface {
|
|
5
|
+
url: string;
|
|
6
|
+
pingEnabled: boolean;
|
|
7
|
+
currentUserFields: ProjectionObject;
|
|
8
|
+
debug: boolean | RpcMessageLoggerOptions;
|
|
9
|
+
usePreSignedUploads: boolean;
|
|
10
|
+
continueWithSessionTimeoutMs: number;
|
|
11
|
+
defaultUploadOptions: UploadFileOptions;
|
|
12
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { AddUserWithEmailOptions, ChangePasswordOptions, GetUploadUrlOptions, LitQL, LoginResult, LoginWithOAuthOptions, OAuthProvider, UserInterface, WaitForEmailConfirmationOptions } from "@litbase/core";
|
|
2
|
+
import { BehaviorSubject, Observable } from "rxjs";
|
|
3
|
+
import { UploadStatus } from "./upload-file-to-url.js";
|
|
4
|
+
import { ClientConfigInterface } from "./config.js";
|
|
5
|
+
import { WebSocketRpcClient, RpcDefinition } from "@litbase/rxpc";
|
|
6
|
+
export interface UploadFileStatus extends UploadStatus {
|
|
7
|
+
contentUrl?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface UploadFileOptions extends Omit<GetUploadUrlOptions, "filename" | "size" | "contentType"> {
|
|
10
|
+
}
|
|
11
|
+
export declare class LitbaseClient {
|
|
12
|
+
readonly litql: LitQL;
|
|
13
|
+
private readonly config;
|
|
14
|
+
client: WebSocketRpcClient | null;
|
|
15
|
+
currentUser: UserInterface;
|
|
16
|
+
readonly currentUser$: BehaviorSubject<UserInterface>;
|
|
17
|
+
private readonly client$;
|
|
18
|
+
constructor(litql?: LitQL, config?: ClientConfigInterface);
|
|
19
|
+
connect(): Promise<void>;
|
|
20
|
+
private tryConnect;
|
|
21
|
+
callObservable<TArgs extends any[], TResult>(definition: RpcDefinition<TArgs, TResult>, ...args: TArgs): Observable<TResult>;
|
|
22
|
+
call<TArgs extends any[], TResult>(definition: RpcDefinition<TArgs, TResult>, ...args: TArgs): Promise<TResult>;
|
|
23
|
+
callHttp<TArgs extends any[], TResult>(definition: RpcDefinition<TArgs, TResult>, ...args: TArgs): Promise<unknown>;
|
|
24
|
+
changeUserName(username: string): Promise<import("@litbase/core").DocumentInterface | null>;
|
|
25
|
+
confirmEmailLogin(options: {
|
|
26
|
+
emailToken: string;
|
|
27
|
+
loginHere: boolean;
|
|
28
|
+
}): Promise<LoginResult | undefined>;
|
|
29
|
+
loginWithEmail(options: {
|
|
30
|
+
email: string;
|
|
31
|
+
captchaResponse?: string;
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
loginWithEmailAndPassword(options: {
|
|
34
|
+
email: string;
|
|
35
|
+
password: string;
|
|
36
|
+
}): Promise<LoginResult>;
|
|
37
|
+
registerWithEmailAndPassword(options: {
|
|
38
|
+
email: string;
|
|
39
|
+
password: string;
|
|
40
|
+
name: string;
|
|
41
|
+
}): Promise<LoginResult>;
|
|
42
|
+
addUserWithEmail(options: AddUserWithEmailOptions): Promise<UserInterface>;
|
|
43
|
+
addUserWithEmailAndPassword(options: {
|
|
44
|
+
email: string;
|
|
45
|
+
password: string;
|
|
46
|
+
name: string;
|
|
47
|
+
}): Promise<UserInterface>;
|
|
48
|
+
getCurrentUser(): Promise<UserInterface>;
|
|
49
|
+
isSameBrowser(): Promise<boolean>;
|
|
50
|
+
waitForEmailConfirmation(options: WaitForEmailConfirmationOptions): Promise<LoginResult>;
|
|
51
|
+
loginWithOAuth(provider: OAuthProvider, options: LoginWithOAuthOptions): Promise<LoginResult>;
|
|
52
|
+
logout(): Promise<void>;
|
|
53
|
+
changePassword(options: ChangePasswordOptions): Promise<void>;
|
|
54
|
+
uploadFile(file: File, options?: UploadFileOptions): Observable<UploadFileStatus>;
|
|
55
|
+
getSessionVariable<T, TDefault = undefined>(key: string, defaultValue?: TDefault): Promise<T | TDefault>;
|
|
56
|
+
private waitForConnection;
|
|
57
|
+
private ensureSession;
|
|
58
|
+
private processLoginResult;
|
|
59
|
+
private getAbsoluteUrl;
|
|
60
|
+
private getUrl;
|
|
61
|
+
}
|
|
62
|
+
export declare const client: any;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BulkWriteOperation, DatabaseCollectionInterface, FindOptions, Projection } from "@litbase/core";
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
import { LitbaseClient } from "./litbase-client.js";
|
|
4
|
+
export declare class RemoteCollection implements DatabaseCollectionInterface {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly client: LitbaseClient;
|
|
7
|
+
constructor(name: string, client: LitbaseClient);
|
|
8
|
+
bulkWrite(operations: BulkWriteOperation<object>[], ordered?: boolean): Promise<void>;
|
|
9
|
+
find(query?: object, projection?: Projection, options?: FindOptions): Observable<object[]>;
|
|
10
|
+
findSnapshot(query?: object, projection?: Projection, options?: FindOptions): Promise<object[]>;
|
|
11
|
+
insert(docs: object[]): Promise<void>;
|
|
12
|
+
remove(query: object, multi?: boolean): Promise<void>;
|
|
13
|
+
update(query: object, update: object, multi?: boolean): Promise<void>;
|
|
14
|
+
upsert(query: object, update: object, multi?: boolean): Promise<void>;
|
|
15
|
+
private queryRemote;
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AjaxResponse } from "rxjs/ajax";
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
export declare enum UploadStatusStatus {
|
|
4
|
+
Done = "done",
|
|
5
|
+
Working = "working",
|
|
6
|
+
Errored = "errored"
|
|
7
|
+
}
|
|
8
|
+
export interface UploadStatus {
|
|
9
|
+
status: UploadStatusStatus;
|
|
10
|
+
file: File;
|
|
11
|
+
progress: number;
|
|
12
|
+
error?: Error;
|
|
13
|
+
response?: AjaxResponse<UploadResponseBody>;
|
|
14
|
+
}
|
|
15
|
+
interface UploadResponseBody {
|
|
16
|
+
status: string;
|
|
17
|
+
url: string;
|
|
18
|
+
}
|
|
19
|
+
export interface UploadFileToUrlOptions {
|
|
20
|
+
extraFields?: Record<string, string>;
|
|
21
|
+
extraHeaders?: Record<string, string>;
|
|
22
|
+
useFormData?: boolean;
|
|
23
|
+
method?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function uploadFileToUrl(file: File, url: string, { extraHeaders, extraFields, useFormData, method }?: UploadFileToUrlOptions): Observable<UploadStatus>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DocumentInterface, MultiObservableQueryObject, MultiPromiseQueryObject, QueryOptions, QueryTypeBody, SingleObservableQueryObject, SinglePromiseQueryObject } from "@litbase/core";
|
|
2
|
+
export declare function useQueryTypeOne<TDoc extends DocumentInterface>(typeName: string, query: QueryTypeBody | null, options?: QueryOptions): [TDoc | null, boolean, Error | null, boolean];
|
|
3
|
+
export declare function useQueryType<TDoc extends DocumentInterface>(typeName: string, query: QueryTypeBody | null, options?: QueryOptions): [TDoc[], boolean, Error | null, boolean];
|
|
4
|
+
export declare function useQuery<T extends DocumentInterface>(name: string, query: SinglePromiseQueryObject | null): [T | null, boolean, Error | null, boolean];
|
|
5
|
+
export declare function useQuery<T extends DocumentInterface>(name: string, query: MultiPromiseQueryObject | null): [T[], boolean, Error | null, boolean];
|
|
6
|
+
export declare function useQuery<T extends DocumentInterface>(name: string, query: SingleObservableQueryObject | null): [T | null, boolean, Error | null, boolean];
|
|
7
|
+
export declare function useQuery<T extends DocumentInterface>(name: string, query: MultiObservableQueryObject | null): [T[], boolean, Error | null, boolean];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BinaryId } from "@litbase/binary-id";
|
|
2
|
+
import { DocumentInterface } from "../litql/index.js";
|
|
3
|
+
export type SessionId = string;
|
|
4
|
+
export interface SessionInterface extends DocumentInterface {
|
|
5
|
+
sessionId: SessionId;
|
|
6
|
+
createdAt: Date;
|
|
7
|
+
rotateAt: Date;
|
|
8
|
+
expiresAt: Date;
|
|
9
|
+
lastSeen: Date;
|
|
10
|
+
values: SessionValues;
|
|
11
|
+
}
|
|
12
|
+
export declare const userIdSessionKey: "userId";
|
|
13
|
+
export declare const sameBrowserTokenSessionKey: "sameBrowserToken";
|
|
14
|
+
export type SessionValues = {
|
|
15
|
+
[userIdSessionKey]?: {
|
|
16
|
+
value: BinaryId;
|
|
17
|
+
visibility: ClientVisibility.read;
|
|
18
|
+
};
|
|
19
|
+
[sameBrowserTokenSessionKey]?: {
|
|
20
|
+
value: BinaryId;
|
|
21
|
+
visibility: ClientVisibility.read;
|
|
22
|
+
};
|
|
23
|
+
[key: string]: SessionValue | undefined;
|
|
24
|
+
};
|
|
25
|
+
export interface SessionValue {
|
|
26
|
+
value: any;
|
|
27
|
+
visibility: ClientVisibility;
|
|
28
|
+
}
|
|
29
|
+
export declare enum ClientVisibility {
|
|
30
|
+
readWrite = "readWrite",
|
|
31
|
+
read = "read",
|
|
32
|
+
hidden = "hidden"
|
|
33
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DocumentInterface } from "../litql/index.js";
|
|
2
|
+
import { OAuthProvider } from "../rpc-definitions/auth-definitions.js";
|
|
3
|
+
export interface UserInterface extends DocumentInterface {
|
|
4
|
+
name: string;
|
|
5
|
+
providers: {
|
|
6
|
+
[key in OAuthProvider]?: {
|
|
7
|
+
id: string;
|
|
8
|
+
};
|
|
9
|
+
} & {
|
|
10
|
+
email?: {
|
|
11
|
+
id: string;
|
|
12
|
+
hashedPassword?: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use {@link UserInterface} instead
|
|
18
|
+
*/
|
|
19
|
+
export type BaseUserInterface = UserInterface;
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use {@link UserInterface} instead
|
|
22
|
+
*/
|
|
23
|
+
export type RegisteredUser = UserInterface;
|
|
24
|
+
export declare const emptyUser: UserInterface;
|
|
25
|
+
export declare const guestUser: UserInterface;
|
|
26
|
+
export declare function isEmptyUser(user: UserInterface): boolean;
|
|
27
|
+
export declare function isUserGuest(user: UserInterface): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AuthError } from "./auth-error.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * from "./errors/index.js";
|
|
2
|
+
export * from "@litbase/binary-id";
|
|
3
|
+
export * from "@litbase/rxpc";
|
|
4
|
+
export * from "./auth/index.js";
|
|
5
|
+
export * from "./litql/index.js";
|
|
6
|
+
export * from "@litbase/event-emitter";
|
|
7
|
+
export * from "./utils/exhaust-map-with-trailing.js";
|
|
8
|
+
export * from "@litbase/utils";
|
|
9
|
+
export * from "./utils/get-value-of.js";
|
|
10
|
+
export * from "./utils/iterable-utils.js";
|
|
11
|
+
export * from "./utils/create-change-observable.js";
|
|
12
|
+
export * from "./utils/simple-object-iterator.js";
|
|
13
|
+
export * from "./utils/deep-assign.js";
|
|
14
|
+
export * from "./utils/deep-transform.js";
|
|
15
|
+
export * from "./utils/get-in.js";
|
|
16
|
+
export * from "./utils/set.js";
|
|
17
|
+
export * from "./utils/is-plain-object.js";
|
|
18
|
+
export * from "./utils/is-email.js";
|
|
19
|
+
export * from "./logger/index.js";
|
|
20
|
+
export * from "./rpc-definitions/index.js";
|
|
21
|
+
export * from "./rpc-client-definitions/index.js";
|
|
22
|
+
export * from "./rpc-message-logger.js";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DocumentInterface } from "./database-interface.js";
|
|
2
|
+
interface InsertOneOperation<TDoc> {
|
|
3
|
+
insertOne: {
|
|
4
|
+
document: TDoc;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
interface UpdateOneOperation {
|
|
8
|
+
updateOne: {
|
|
9
|
+
filter: object;
|
|
10
|
+
update: object;
|
|
11
|
+
upsert?: boolean;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
interface UpdateManyOperation {
|
|
15
|
+
updateMany: {
|
|
16
|
+
filter: object;
|
|
17
|
+
update: object;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
interface DeleteOneOperation {
|
|
21
|
+
deleteOne: {
|
|
22
|
+
filter: object;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
interface DeleteManyOperation {
|
|
26
|
+
deleteMany: {
|
|
27
|
+
filter: object;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export type BulkWriteOperation<TDoc = DocumentInterface> = InsertOneOperation<TDoc> | UpdateOneOperation | UpdateManyOperation | DeleteOneOperation | DeleteManyOperation;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
import { BulkWriteOperation } from "./bulk-write-operation.js";
|
|
3
|
+
import { BinaryId } from "@litbase/binary-id";
|
|
4
|
+
export type SortOptions = {
|
|
5
|
+
[key: string]: 1 | -1;
|
|
6
|
+
};
|
|
7
|
+
type IncludeProjection<T> = {
|
|
8
|
+
[Prop in keyof T]?: 1 | IncludeProjection<T[Prop]>;
|
|
9
|
+
};
|
|
10
|
+
type ExcludeProjection<T> = {
|
|
11
|
+
[Prop in keyof T]?: 0 | ExcludeProjection<T[Prop]>;
|
|
12
|
+
};
|
|
13
|
+
export type Projection<T = {}> = IncludeProjection<T> | ExcludeProjection<T>;
|
|
14
|
+
export interface FindOptions {
|
|
15
|
+
sort?: SortOptions | null;
|
|
16
|
+
limit?: number | null;
|
|
17
|
+
skip?: number | null;
|
|
18
|
+
allFields?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface DatabaseInterface {
|
|
21
|
+
ready: Promise<void>;
|
|
22
|
+
getCollection(name: string): DatabaseCollectionInterface;
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export interface DatabaseCollectionInterface {
|
|
26
|
+
name: string;
|
|
27
|
+
find(query?: object, projection?: Projection, options?: FindOptions): Observable<object[]>;
|
|
28
|
+
findSnapshot(query?: object, projection?: Projection, options?: FindOptions): Promise<object[]>;
|
|
29
|
+
update(query: object, update: object, multi?: boolean): Promise<void>;
|
|
30
|
+
upsert(query: object, update: object, multi?: boolean): Promise<void>;
|
|
31
|
+
remove(query: object, multi?: boolean): Promise<void>;
|
|
32
|
+
insert(docs: object[]): Promise<void>;
|
|
33
|
+
bulkWrite(operations: BulkWriteOperation<object>[], ordered?: boolean): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
export interface DocumentInterface {
|
|
36
|
+
_id: BinaryId;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BulkWriteOperation } from "./bulk-write-operation.js";
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
import { DatabaseCollectionInterface, DocumentInterface, FindOptions, Projection } from "../index.js";
|
|
4
|
+
export declare class InMemoryDatabaseCollection<T extends DocumentInterface = DocumentInterface> implements DatabaseCollectionInterface {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
items: T[];
|
|
7
|
+
private readonly change;
|
|
8
|
+
constructor(name: string);
|
|
9
|
+
find(query?: object, projection?: Projection, options?: FindOptions): Observable<T[]>;
|
|
10
|
+
findSnapshot(query?: object, projection?: Projection, options?: FindOptions): Promise<T[]>;
|
|
11
|
+
insert(docs: T[]): Promise<void>;
|
|
12
|
+
remove(query: object, multi?: boolean): Promise<void>;
|
|
13
|
+
update(query: object, update: object, multi?: boolean): Promise<void>;
|
|
14
|
+
upsert(query: object, { $setOnInsert, ...update }: {
|
|
15
|
+
$setOnInsert: object;
|
|
16
|
+
}, multi?: boolean): Promise<void>;
|
|
17
|
+
bulkWrite(operations: BulkWriteOperation[], ordered?: boolean): Promise<void>;
|
|
18
|
+
private updateItems;
|
|
19
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./litql.js";
|
|
2
|
+
export * from "./litql-query.js";
|
|
3
|
+
export * from "./litql-types.js";
|
|
4
|
+
export * from "../utils/iterable-utils.js";
|
|
5
|
+
export * from "../utils/get-value-of.js";
|
|
6
|
+
export * from "./database-interface.js";
|
|
7
|
+
export * from "./bulk-write-operation.js";
|
|
8
|
+
export * from "./in-memory-database-collection.js";
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { DatabaseCollectionInterface, SortOptions } from "./database-interface.js";
|
|
2
|
+
import { LitQL } from "./litql.js";
|
|
3
|
+
/**
|
|
4
|
+
* The type of the body of a query
|
|
5
|
+
*/
|
|
6
|
+
export type QueryBody = Record<string, QueryTypeBody>;
|
|
7
|
+
/**
|
|
8
|
+
* The type of the value of a single type in a {@link QueryBody}
|
|
9
|
+
*/
|
|
10
|
+
export type QueryTypeBody = Record<string, QueryFieldBody | QueryOperatorBody>;
|
|
11
|
+
/**
|
|
12
|
+
* The type of the value of a single field in a {@link QueryTypeBody}
|
|
13
|
+
*/
|
|
14
|
+
export type QueryFieldBody = Record<string, unknown> | 1;
|
|
15
|
+
/**
|
|
16
|
+
* The type of the value of a single operator in a {@link QueryTypeBody}
|
|
17
|
+
*/
|
|
18
|
+
export type QueryOperatorBody = unknown;
|
|
19
|
+
/**
|
|
20
|
+
* Additional options that can be passed to a LitQL query
|
|
21
|
+
*/
|
|
22
|
+
export interface QueryOptions {
|
|
23
|
+
/**
|
|
24
|
+
* If true, will only return a one-time snapshot of the query results and will NOT create a live query returning later
|
|
25
|
+
* updates.
|
|
26
|
+
*/
|
|
27
|
+
once?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Additional, custom values passed with the query. Most often used to pass values to hooks or fulfill functions
|
|
30
|
+
* (e.g. the current user).
|
|
31
|
+
*/
|
|
32
|
+
context?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
export type JoinCardinality = "one" | "many";
|
|
35
|
+
/**
|
|
36
|
+
* Describes a join side when specifying a database join using {@link registerJoin}
|
|
37
|
+
*/
|
|
38
|
+
export interface JoinPoint {
|
|
39
|
+
/**
|
|
40
|
+
* The name of the type on this joining side
|
|
41
|
+
*/
|
|
42
|
+
type: string;
|
|
43
|
+
/**
|
|
44
|
+
* The name of the new field, that will contain the joined documents from the other side
|
|
45
|
+
*/
|
|
46
|
+
field: string;
|
|
47
|
+
/**
|
|
48
|
+
* The field in this side of the join that must contain a matching value to the other side's joinField.
|
|
49
|
+
*/
|
|
50
|
+
joinField: string;
|
|
51
|
+
/**
|
|
52
|
+
* Specifies the cardinality of this side, eg. one-to-many, one-to-one, many-to-many, etc.
|
|
53
|
+
*/
|
|
54
|
+
joinType: JoinCardinality;
|
|
55
|
+
}
|
|
56
|
+
export interface JoinPointResolution {
|
|
57
|
+
joinPoint: RegisteredJoinPoint;
|
|
58
|
+
query: QueryResolution;
|
|
59
|
+
}
|
|
60
|
+
export interface RegisteredJoinPoint extends JoinPoint {
|
|
61
|
+
oppositeSide: JoinPoint;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A registered, queryable type
|
|
65
|
+
*/
|
|
66
|
+
export interface RegisteredCollection extends RegisterCollectionOptions {
|
|
67
|
+
joinPoints: Map<string, RegisteredJoinPoint>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A resolved type with details
|
|
71
|
+
*/
|
|
72
|
+
export interface QueryResolution {
|
|
73
|
+
/**
|
|
74
|
+
* The type belonging to the resolution.
|
|
75
|
+
*/
|
|
76
|
+
collection: RegisteredCollection;
|
|
77
|
+
/**
|
|
78
|
+
* A map of operators found in {@link body}. Keys are the operator names, values are the operator values
|
|
79
|
+
*/
|
|
80
|
+
operators: Map<string, unknown>;
|
|
81
|
+
/**
|
|
82
|
+
* A set of projected fields found in {@link body}. Does not contain dynamic fields.
|
|
83
|
+
*/
|
|
84
|
+
projection: Map<string, unknown>;
|
|
85
|
+
joinPoints: Map<string, JoinPointResolution>;
|
|
86
|
+
criteria: Record<string, unknown>;
|
|
87
|
+
isMulti: boolean;
|
|
88
|
+
isLive: boolean;
|
|
89
|
+
sort: SortOptions | null;
|
|
90
|
+
limit: number | null;
|
|
91
|
+
skip: number | null;
|
|
92
|
+
context: Record<string, unknown>;
|
|
93
|
+
litql: LitQL;
|
|
94
|
+
isFullProjection: boolean;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Options given to {@link registerCollection}
|
|
98
|
+
*/
|
|
99
|
+
export interface RegisterCollectionOptions {
|
|
100
|
+
/**
|
|
101
|
+
* @see {@link RegisterTypeOptions#name}
|
|
102
|
+
*/
|
|
103
|
+
name: string;
|
|
104
|
+
/**
|
|
105
|
+
* The backing collection where the data presides
|
|
106
|
+
*/
|
|
107
|
+
collection: DatabaseCollectionInterface;
|
|
108
|
+
}
|