@thadeu/ndb 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +306 -2
- package/dist/index.cjs +639 -0
- package/dist/index.d.cts +247 -0
- package/dist/index.d.ts +247 -0
- package/dist/index.js +597 -0
- package/package.json +66 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { Dispatcher } from 'undici';
|
|
2
|
+
|
|
3
|
+
interface TypeMap {
|
|
4
|
+
string: string;
|
|
5
|
+
number: number;
|
|
6
|
+
boolean: boolean;
|
|
7
|
+
date: Date;
|
|
8
|
+
json: unknown;
|
|
9
|
+
}
|
|
10
|
+
type FieldType = keyof TypeMap;
|
|
11
|
+
interface FieldDef {
|
|
12
|
+
type: FieldType;
|
|
13
|
+
index?: boolean;
|
|
14
|
+
unique?: boolean;
|
|
15
|
+
optional?: boolean;
|
|
16
|
+
}
|
|
17
|
+
type Fields = Record<string, FieldDef>;
|
|
18
|
+
interface Schema<F extends Fields> {
|
|
19
|
+
id?: Extract<keyof F, string>;
|
|
20
|
+
time?: Extract<keyof F, string>;
|
|
21
|
+
expires?: Extract<keyof F, string>;
|
|
22
|
+
fields: F;
|
|
23
|
+
}
|
|
24
|
+
type ValueOf<D extends FieldDef> = TypeMap[D['type']];
|
|
25
|
+
type OptionalKeys<F extends Fields> = {
|
|
26
|
+
[K in keyof F]: F[K] extends {
|
|
27
|
+
optional: true;
|
|
28
|
+
} ? K : never;
|
|
29
|
+
}[keyof F];
|
|
30
|
+
type Doc<F extends Fields> = {
|
|
31
|
+
[K in Exclude<keyof F, OptionalKeys<F>>]: ValueOf<F[K]>;
|
|
32
|
+
} & {
|
|
33
|
+
[K in OptionalKeys<F>]?: ValueOf<F[K]>;
|
|
34
|
+
};
|
|
35
|
+
type Input<F extends Fields> = {
|
|
36
|
+
[K in keyof F]?: ValueOf<F[K]>;
|
|
37
|
+
};
|
|
38
|
+
type Row<F extends Fields> = Doc<F> & {
|
|
39
|
+
_v: number;
|
|
40
|
+
};
|
|
41
|
+
interface Ops<V> {
|
|
42
|
+
$eq?: V;
|
|
43
|
+
$ne?: V;
|
|
44
|
+
$gt?: V;
|
|
45
|
+
$gte?: V;
|
|
46
|
+
$lt?: V;
|
|
47
|
+
$lte?: V;
|
|
48
|
+
$in?: V[];
|
|
49
|
+
$nin?: V[];
|
|
50
|
+
$exists?: boolean;
|
|
51
|
+
$regex?: string | RegExp;
|
|
52
|
+
$options?: string;
|
|
53
|
+
}
|
|
54
|
+
type Operand<V> = V extends Date ? Date | string : V;
|
|
55
|
+
type RegexOperand<V> = V extends string ? RegExp : never;
|
|
56
|
+
type JsonKeys<F extends Fields> = Extract<{
|
|
57
|
+
[K in keyof F]: F[K]['type'] extends 'json' ? K : never;
|
|
58
|
+
}[keyof F], string>;
|
|
59
|
+
type Where<F extends Fields> = {
|
|
60
|
+
[K in keyof F]?: Operand<ValueOf<F[K]>> | Ops<Operand<ValueOf<F[K]>>> | RegexOperand<ValueOf<F[K]>>;
|
|
61
|
+
} & {
|
|
62
|
+
[P in `${JsonKeys<F>}.${string}`]?: unknown;
|
|
63
|
+
};
|
|
64
|
+
type SortSpec<F extends Fields> = Partial<Record<Extract<keyof F, string>, 1 | -1>>;
|
|
65
|
+
interface WriteResult {
|
|
66
|
+
id: string;
|
|
67
|
+
v: number;
|
|
68
|
+
}
|
|
69
|
+
interface WriteOptions {
|
|
70
|
+
ifVersion?: number;
|
|
71
|
+
}
|
|
72
|
+
type Duration = number | string;
|
|
73
|
+
interface UpdateOptions extends WriteOptions {
|
|
74
|
+
unset?: string[];
|
|
75
|
+
expireIn?: Duration;
|
|
76
|
+
}
|
|
77
|
+
interface InsertOptions {
|
|
78
|
+
expireIn?: Duration;
|
|
79
|
+
}
|
|
80
|
+
interface ExpireResult extends WriteResult {
|
|
81
|
+
expiresAt: Date;
|
|
82
|
+
}
|
|
83
|
+
interface AggregateOptions {
|
|
84
|
+
limit?: number;
|
|
85
|
+
skip?: number;
|
|
86
|
+
after?: string;
|
|
87
|
+
count?: boolean;
|
|
88
|
+
}
|
|
89
|
+
interface AggregateResult<R = Record<string, unknown>> {
|
|
90
|
+
rows: R[];
|
|
91
|
+
next: string;
|
|
92
|
+
total: number;
|
|
93
|
+
}
|
|
94
|
+
interface WatchOptions<F extends Fields = Fields> {
|
|
95
|
+
from?: string;
|
|
96
|
+
limit?: number;
|
|
97
|
+
signal?: AbortSignal;
|
|
98
|
+
where?: Where<F>;
|
|
99
|
+
}
|
|
100
|
+
interface WatchEvent<R> {
|
|
101
|
+
consumer: string;
|
|
102
|
+
pos: string;
|
|
103
|
+
op: 'put' | 'del';
|
|
104
|
+
id: string;
|
|
105
|
+
v: number;
|
|
106
|
+
doc: R | undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface State {
|
|
110
|
+
clauses: Record<string, unknown>[];
|
|
111
|
+
fields?: string[];
|
|
112
|
+
sort?: Record<string, 1 | -1>;
|
|
113
|
+
limit?: number;
|
|
114
|
+
skip?: number;
|
|
115
|
+
after?: string;
|
|
116
|
+
}
|
|
117
|
+
declare class Query<F extends Fields, R = Row<F>> implements PromiseLike<R[]> {
|
|
118
|
+
private readonly model;
|
|
119
|
+
private readonly state;
|
|
120
|
+
nextCursor: string;
|
|
121
|
+
constructor(model: Model<F>, state?: State);
|
|
122
|
+
where(w: Where<F>): Query<F, R>;
|
|
123
|
+
not(w: Where<F>): Query<F, R>;
|
|
124
|
+
or(...ws: Where<F>[]): Query<F, R>;
|
|
125
|
+
sort(spec: SortSpec<F>): Query<F, R>;
|
|
126
|
+
limit(n: number): Query<F, R>;
|
|
127
|
+
skip(n: number): Query<F, R>;
|
|
128
|
+
page(n: number, size: number): Query<F, R>;
|
|
129
|
+
after(token: string): Query<F, R>;
|
|
130
|
+
fields(...names: string[]): Query<F, Partial<R>>;
|
|
131
|
+
then<A = R[], B = never>(onfulfilled?: ((value: R[]) => A | PromiseLike<A>) | null, onrejected?: ((reason: unknown) => B | PromiseLike<B>) | null): Promise<A | B>;
|
|
132
|
+
all(): Promise<R[]>;
|
|
133
|
+
first(): Promise<R | null>;
|
|
134
|
+
count(): Promise<number>;
|
|
135
|
+
iterate(): AsyncGenerator<R>;
|
|
136
|
+
private rows;
|
|
137
|
+
private body;
|
|
138
|
+
private whereDoc;
|
|
139
|
+
private with;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
declare class Model<F extends Fields> {
|
|
143
|
+
readonly db: Ndb;
|
|
144
|
+
readonly name: string;
|
|
145
|
+
readonly schema: Schema<F>;
|
|
146
|
+
private ensured?;
|
|
147
|
+
constructor(db: Ndb, name: string, schema: Schema<F>);
|
|
148
|
+
get idField(): string;
|
|
149
|
+
path(op?: string): string;
|
|
150
|
+
ready(): Promise<void>;
|
|
151
|
+
insert(docs: Input<F> | Input<F>[], opts?: InsertOptions): Promise<WriteResult[]>;
|
|
152
|
+
create(docs: Input<F> | Input<F>[], opts?: InsertOptions): Promise<WriteResult[]>;
|
|
153
|
+
update(id: string, set: Input<F>, opts?: UpdateOptions): Promise<WriteResult>;
|
|
154
|
+
delete(id: string, opts?: WriteOptions): Promise<void>;
|
|
155
|
+
expire(id: string, duration: Duration, opts?: WriteOptions): Promise<ExpireResult>;
|
|
156
|
+
expireAt(id: string, at: Date, opts?: WriteOptions): Promise<ExpireResult>;
|
|
157
|
+
persist(id: string): Promise<WriteResult>;
|
|
158
|
+
ttl(id: string): Promise<number | null>;
|
|
159
|
+
private setExpiry;
|
|
160
|
+
find(id: string): Promise<Row<F> | null>;
|
|
161
|
+
query(): Query<F>;
|
|
162
|
+
where(w: Where<F>): Query<F>;
|
|
163
|
+
not(w: Where<F>): Query<F>;
|
|
164
|
+
or(...ws: Where<F>[]): Query<F>;
|
|
165
|
+
sort(spec: SortSpec<F>): Query<F>;
|
|
166
|
+
limit(n: number): Query<F>;
|
|
167
|
+
skip(n: number): Query<F>;
|
|
168
|
+
page(n: number, size: number): Query<F>;
|
|
169
|
+
after(token: string): Query<F>;
|
|
170
|
+
fields(...names: string[]): Query<F, Partial<Row<F>>>;
|
|
171
|
+
all(): Promise<Row<F>[]>;
|
|
172
|
+
count(): Promise<number>;
|
|
173
|
+
first(): Promise<Row<F> | null>;
|
|
174
|
+
iterate(): AsyncGenerator<Row<F>>;
|
|
175
|
+
aggregate<R = Record<string, unknown>>(pipeline: Record<string, unknown>[], opts?: AggregateOptions): Promise<AggregateResult<R>>;
|
|
176
|
+
watch(consumer: string, opts?: WatchOptions<F>): AsyncGenerator<WatchEvent<Row<F>>>;
|
|
177
|
+
ack(event: Pick<WatchEvent<unknown>, 'consumer' | 'pos'>): Promise<void>;
|
|
178
|
+
decode(raw: Record<string, unknown>): Record<string, unknown>;
|
|
179
|
+
private catalog;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
183
|
+
interface Streamed {
|
|
184
|
+
status: number;
|
|
185
|
+
headers: Record<string, string | string[] | undefined>;
|
|
186
|
+
body: Dispatcher.ResponseData["body"];
|
|
187
|
+
rows(): AsyncGenerator<unknown>;
|
|
188
|
+
header(name: string): string | undefined;
|
|
189
|
+
}
|
|
190
|
+
interface ConnectOptions {
|
|
191
|
+
token?: string;
|
|
192
|
+
readyTimeout?: number;
|
|
193
|
+
}
|
|
194
|
+
declare class Transport {
|
|
195
|
+
private readonly client;
|
|
196
|
+
private readonly token;
|
|
197
|
+
private readonly readyTimeout;
|
|
198
|
+
constructor(addr?: string, opts?: ConnectOptions);
|
|
199
|
+
stream(method: Method, path: string, body?: unknown, signal?: AbortSignal): Promise<Streamed>;
|
|
200
|
+
request<T = unknown>(method: Method, path: string, body?: unknown): Promise<T>;
|
|
201
|
+
close(): Promise<void>;
|
|
202
|
+
private withReadyRetry;
|
|
203
|
+
private headers;
|
|
204
|
+
private send;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
declare class Ndb {
|
|
208
|
+
readonly transport: Transport;
|
|
209
|
+
constructor(addr?: string, opts?: ConnectOptions);
|
|
210
|
+
model<const F extends Fields>(name: string, schema: Schema<F>): Model<F>;
|
|
211
|
+
health(): Promise<void>;
|
|
212
|
+
request<T = unknown>(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, body?: unknown): Promise<T>;
|
|
213
|
+
stream(...args: Parameters<Transport['stream']>): ReturnType<Transport['stream']>;
|
|
214
|
+
close(): Promise<void>;
|
|
215
|
+
}
|
|
216
|
+
declare function connect(addr?: string, opts?: ConnectOptions): Ndb;
|
|
217
|
+
|
|
218
|
+
type ErrorCode = 'unauthorized' | 'not_found' | 'version_conflict' | 'duplicate_id' | 'unique_violation' | 'catalog_conflict' | 'catalog_invalid' | 'unknown_collection' | 'direct_collection' | 'invalid_request' | 'invalid_query' | 'invalid_pipeline' | 'group_limit_exceeded' | 'cursor_invalid' | 'cursor_mismatch' | 'cursor_expired' | 'request_too_large' | 'line_too_large' | 'not_ready' | 'closed' | 'watch_lagged' | 'invalid_position' | 'history_truncated' | 'ttl_not_enabled' | 'ttl_derived' | 'http_status' | (string & {});
|
|
219
|
+
declare class NdbError extends Error {
|
|
220
|
+
readonly code: ErrorCode;
|
|
221
|
+
readonly status: number;
|
|
222
|
+
constructor(code: ErrorCode, message: string, status?: number);
|
|
223
|
+
}
|
|
224
|
+
declare class UnauthorizedError extends NdbError {
|
|
225
|
+
}
|
|
226
|
+
declare class NotFoundError extends NdbError {
|
|
227
|
+
}
|
|
228
|
+
declare class VersionConflictError extends NdbError {
|
|
229
|
+
}
|
|
230
|
+
declare class DuplicateIdError extends NdbError {
|
|
231
|
+
}
|
|
232
|
+
declare class UniqueViolationError extends NdbError {
|
|
233
|
+
}
|
|
234
|
+
declare class InvalidQueryError extends NdbError {
|
|
235
|
+
}
|
|
236
|
+
declare class CursorError extends NdbError {
|
|
237
|
+
}
|
|
238
|
+
declare class WatchLaggedError extends NdbError {
|
|
239
|
+
}
|
|
240
|
+
declare class HistoryTruncatedError extends NdbError {
|
|
241
|
+
}
|
|
242
|
+
declare class TtlError extends NdbError {
|
|
243
|
+
}
|
|
244
|
+
declare function makeError(code: ErrorCode, message: string, status?: number): NdbError;
|
|
245
|
+
|
|
246
|
+
export { CursorError, DuplicateIdError, HistoryTruncatedError, InvalidQueryError, Model, Ndb, NdbError, NotFoundError, Query, TtlError, UnauthorizedError, UniqueViolationError, VersionConflictError, WatchLaggedError, connect, makeError };
|
|
247
|
+
export type { AggregateOptions, AggregateResult, ConnectOptions, Doc, Duration, ErrorCode, ExpireResult, FieldDef, FieldType, Fields, Input, InsertOptions, Ops, Row, Schema, SortSpec, TypeMap, UpdateOptions, WatchEvent, WatchOptions, Where, WriteOptions, WriteResult };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { Dispatcher } from 'undici';
|
|
2
|
+
|
|
3
|
+
interface TypeMap {
|
|
4
|
+
string: string;
|
|
5
|
+
number: number;
|
|
6
|
+
boolean: boolean;
|
|
7
|
+
date: Date;
|
|
8
|
+
json: unknown;
|
|
9
|
+
}
|
|
10
|
+
type FieldType = keyof TypeMap;
|
|
11
|
+
interface FieldDef {
|
|
12
|
+
type: FieldType;
|
|
13
|
+
index?: boolean;
|
|
14
|
+
unique?: boolean;
|
|
15
|
+
optional?: boolean;
|
|
16
|
+
}
|
|
17
|
+
type Fields = Record<string, FieldDef>;
|
|
18
|
+
interface Schema<F extends Fields> {
|
|
19
|
+
id?: Extract<keyof F, string>;
|
|
20
|
+
time?: Extract<keyof F, string>;
|
|
21
|
+
expires?: Extract<keyof F, string>;
|
|
22
|
+
fields: F;
|
|
23
|
+
}
|
|
24
|
+
type ValueOf<D extends FieldDef> = TypeMap[D['type']];
|
|
25
|
+
type OptionalKeys<F extends Fields> = {
|
|
26
|
+
[K in keyof F]: F[K] extends {
|
|
27
|
+
optional: true;
|
|
28
|
+
} ? K : never;
|
|
29
|
+
}[keyof F];
|
|
30
|
+
type Doc<F extends Fields> = {
|
|
31
|
+
[K in Exclude<keyof F, OptionalKeys<F>>]: ValueOf<F[K]>;
|
|
32
|
+
} & {
|
|
33
|
+
[K in OptionalKeys<F>]?: ValueOf<F[K]>;
|
|
34
|
+
};
|
|
35
|
+
type Input<F extends Fields> = {
|
|
36
|
+
[K in keyof F]?: ValueOf<F[K]>;
|
|
37
|
+
};
|
|
38
|
+
type Row<F extends Fields> = Doc<F> & {
|
|
39
|
+
_v: number;
|
|
40
|
+
};
|
|
41
|
+
interface Ops<V> {
|
|
42
|
+
$eq?: V;
|
|
43
|
+
$ne?: V;
|
|
44
|
+
$gt?: V;
|
|
45
|
+
$gte?: V;
|
|
46
|
+
$lt?: V;
|
|
47
|
+
$lte?: V;
|
|
48
|
+
$in?: V[];
|
|
49
|
+
$nin?: V[];
|
|
50
|
+
$exists?: boolean;
|
|
51
|
+
$regex?: string | RegExp;
|
|
52
|
+
$options?: string;
|
|
53
|
+
}
|
|
54
|
+
type Operand<V> = V extends Date ? Date | string : V;
|
|
55
|
+
type RegexOperand<V> = V extends string ? RegExp : never;
|
|
56
|
+
type JsonKeys<F extends Fields> = Extract<{
|
|
57
|
+
[K in keyof F]: F[K]['type'] extends 'json' ? K : never;
|
|
58
|
+
}[keyof F], string>;
|
|
59
|
+
type Where<F extends Fields> = {
|
|
60
|
+
[K in keyof F]?: Operand<ValueOf<F[K]>> | Ops<Operand<ValueOf<F[K]>>> | RegexOperand<ValueOf<F[K]>>;
|
|
61
|
+
} & {
|
|
62
|
+
[P in `${JsonKeys<F>}.${string}`]?: unknown;
|
|
63
|
+
};
|
|
64
|
+
type SortSpec<F extends Fields> = Partial<Record<Extract<keyof F, string>, 1 | -1>>;
|
|
65
|
+
interface WriteResult {
|
|
66
|
+
id: string;
|
|
67
|
+
v: number;
|
|
68
|
+
}
|
|
69
|
+
interface WriteOptions {
|
|
70
|
+
ifVersion?: number;
|
|
71
|
+
}
|
|
72
|
+
type Duration = number | string;
|
|
73
|
+
interface UpdateOptions extends WriteOptions {
|
|
74
|
+
unset?: string[];
|
|
75
|
+
expireIn?: Duration;
|
|
76
|
+
}
|
|
77
|
+
interface InsertOptions {
|
|
78
|
+
expireIn?: Duration;
|
|
79
|
+
}
|
|
80
|
+
interface ExpireResult extends WriteResult {
|
|
81
|
+
expiresAt: Date;
|
|
82
|
+
}
|
|
83
|
+
interface AggregateOptions {
|
|
84
|
+
limit?: number;
|
|
85
|
+
skip?: number;
|
|
86
|
+
after?: string;
|
|
87
|
+
count?: boolean;
|
|
88
|
+
}
|
|
89
|
+
interface AggregateResult<R = Record<string, unknown>> {
|
|
90
|
+
rows: R[];
|
|
91
|
+
next: string;
|
|
92
|
+
total: number;
|
|
93
|
+
}
|
|
94
|
+
interface WatchOptions<F extends Fields = Fields> {
|
|
95
|
+
from?: string;
|
|
96
|
+
limit?: number;
|
|
97
|
+
signal?: AbortSignal;
|
|
98
|
+
where?: Where<F>;
|
|
99
|
+
}
|
|
100
|
+
interface WatchEvent<R> {
|
|
101
|
+
consumer: string;
|
|
102
|
+
pos: string;
|
|
103
|
+
op: 'put' | 'del';
|
|
104
|
+
id: string;
|
|
105
|
+
v: number;
|
|
106
|
+
doc: R | undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface State {
|
|
110
|
+
clauses: Record<string, unknown>[];
|
|
111
|
+
fields?: string[];
|
|
112
|
+
sort?: Record<string, 1 | -1>;
|
|
113
|
+
limit?: number;
|
|
114
|
+
skip?: number;
|
|
115
|
+
after?: string;
|
|
116
|
+
}
|
|
117
|
+
declare class Query<F extends Fields, R = Row<F>> implements PromiseLike<R[]> {
|
|
118
|
+
private readonly model;
|
|
119
|
+
private readonly state;
|
|
120
|
+
nextCursor: string;
|
|
121
|
+
constructor(model: Model<F>, state?: State);
|
|
122
|
+
where(w: Where<F>): Query<F, R>;
|
|
123
|
+
not(w: Where<F>): Query<F, R>;
|
|
124
|
+
or(...ws: Where<F>[]): Query<F, R>;
|
|
125
|
+
sort(spec: SortSpec<F>): Query<F, R>;
|
|
126
|
+
limit(n: number): Query<F, R>;
|
|
127
|
+
skip(n: number): Query<F, R>;
|
|
128
|
+
page(n: number, size: number): Query<F, R>;
|
|
129
|
+
after(token: string): Query<F, R>;
|
|
130
|
+
fields(...names: string[]): Query<F, Partial<R>>;
|
|
131
|
+
then<A = R[], B = never>(onfulfilled?: ((value: R[]) => A | PromiseLike<A>) | null, onrejected?: ((reason: unknown) => B | PromiseLike<B>) | null): Promise<A | B>;
|
|
132
|
+
all(): Promise<R[]>;
|
|
133
|
+
first(): Promise<R | null>;
|
|
134
|
+
count(): Promise<number>;
|
|
135
|
+
iterate(): AsyncGenerator<R>;
|
|
136
|
+
private rows;
|
|
137
|
+
private body;
|
|
138
|
+
private whereDoc;
|
|
139
|
+
private with;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
declare class Model<F extends Fields> {
|
|
143
|
+
readonly db: Ndb;
|
|
144
|
+
readonly name: string;
|
|
145
|
+
readonly schema: Schema<F>;
|
|
146
|
+
private ensured?;
|
|
147
|
+
constructor(db: Ndb, name: string, schema: Schema<F>);
|
|
148
|
+
get idField(): string;
|
|
149
|
+
path(op?: string): string;
|
|
150
|
+
ready(): Promise<void>;
|
|
151
|
+
insert(docs: Input<F> | Input<F>[], opts?: InsertOptions): Promise<WriteResult[]>;
|
|
152
|
+
create(docs: Input<F> | Input<F>[], opts?: InsertOptions): Promise<WriteResult[]>;
|
|
153
|
+
update(id: string, set: Input<F>, opts?: UpdateOptions): Promise<WriteResult>;
|
|
154
|
+
delete(id: string, opts?: WriteOptions): Promise<void>;
|
|
155
|
+
expire(id: string, duration: Duration, opts?: WriteOptions): Promise<ExpireResult>;
|
|
156
|
+
expireAt(id: string, at: Date, opts?: WriteOptions): Promise<ExpireResult>;
|
|
157
|
+
persist(id: string): Promise<WriteResult>;
|
|
158
|
+
ttl(id: string): Promise<number | null>;
|
|
159
|
+
private setExpiry;
|
|
160
|
+
find(id: string): Promise<Row<F> | null>;
|
|
161
|
+
query(): Query<F>;
|
|
162
|
+
where(w: Where<F>): Query<F>;
|
|
163
|
+
not(w: Where<F>): Query<F>;
|
|
164
|
+
or(...ws: Where<F>[]): Query<F>;
|
|
165
|
+
sort(spec: SortSpec<F>): Query<F>;
|
|
166
|
+
limit(n: number): Query<F>;
|
|
167
|
+
skip(n: number): Query<F>;
|
|
168
|
+
page(n: number, size: number): Query<F>;
|
|
169
|
+
after(token: string): Query<F>;
|
|
170
|
+
fields(...names: string[]): Query<F, Partial<Row<F>>>;
|
|
171
|
+
all(): Promise<Row<F>[]>;
|
|
172
|
+
count(): Promise<number>;
|
|
173
|
+
first(): Promise<Row<F> | null>;
|
|
174
|
+
iterate(): AsyncGenerator<Row<F>>;
|
|
175
|
+
aggregate<R = Record<string, unknown>>(pipeline: Record<string, unknown>[], opts?: AggregateOptions): Promise<AggregateResult<R>>;
|
|
176
|
+
watch(consumer: string, opts?: WatchOptions<F>): AsyncGenerator<WatchEvent<Row<F>>>;
|
|
177
|
+
ack(event: Pick<WatchEvent<unknown>, 'consumer' | 'pos'>): Promise<void>;
|
|
178
|
+
decode(raw: Record<string, unknown>): Record<string, unknown>;
|
|
179
|
+
private catalog;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
183
|
+
interface Streamed {
|
|
184
|
+
status: number;
|
|
185
|
+
headers: Record<string, string | string[] | undefined>;
|
|
186
|
+
body: Dispatcher.ResponseData["body"];
|
|
187
|
+
rows(): AsyncGenerator<unknown>;
|
|
188
|
+
header(name: string): string | undefined;
|
|
189
|
+
}
|
|
190
|
+
interface ConnectOptions {
|
|
191
|
+
token?: string;
|
|
192
|
+
readyTimeout?: number;
|
|
193
|
+
}
|
|
194
|
+
declare class Transport {
|
|
195
|
+
private readonly client;
|
|
196
|
+
private readonly token;
|
|
197
|
+
private readonly readyTimeout;
|
|
198
|
+
constructor(addr?: string, opts?: ConnectOptions);
|
|
199
|
+
stream(method: Method, path: string, body?: unknown, signal?: AbortSignal): Promise<Streamed>;
|
|
200
|
+
request<T = unknown>(method: Method, path: string, body?: unknown): Promise<T>;
|
|
201
|
+
close(): Promise<void>;
|
|
202
|
+
private withReadyRetry;
|
|
203
|
+
private headers;
|
|
204
|
+
private send;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
declare class Ndb {
|
|
208
|
+
readonly transport: Transport;
|
|
209
|
+
constructor(addr?: string, opts?: ConnectOptions);
|
|
210
|
+
model<const F extends Fields>(name: string, schema: Schema<F>): Model<F>;
|
|
211
|
+
health(): Promise<void>;
|
|
212
|
+
request<T = unknown>(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, body?: unknown): Promise<T>;
|
|
213
|
+
stream(...args: Parameters<Transport['stream']>): ReturnType<Transport['stream']>;
|
|
214
|
+
close(): Promise<void>;
|
|
215
|
+
}
|
|
216
|
+
declare function connect(addr?: string, opts?: ConnectOptions): Ndb;
|
|
217
|
+
|
|
218
|
+
type ErrorCode = 'unauthorized' | 'not_found' | 'version_conflict' | 'duplicate_id' | 'unique_violation' | 'catalog_conflict' | 'catalog_invalid' | 'unknown_collection' | 'direct_collection' | 'invalid_request' | 'invalid_query' | 'invalid_pipeline' | 'group_limit_exceeded' | 'cursor_invalid' | 'cursor_mismatch' | 'cursor_expired' | 'request_too_large' | 'line_too_large' | 'not_ready' | 'closed' | 'watch_lagged' | 'invalid_position' | 'history_truncated' | 'ttl_not_enabled' | 'ttl_derived' | 'http_status' | (string & {});
|
|
219
|
+
declare class NdbError extends Error {
|
|
220
|
+
readonly code: ErrorCode;
|
|
221
|
+
readonly status: number;
|
|
222
|
+
constructor(code: ErrorCode, message: string, status?: number);
|
|
223
|
+
}
|
|
224
|
+
declare class UnauthorizedError extends NdbError {
|
|
225
|
+
}
|
|
226
|
+
declare class NotFoundError extends NdbError {
|
|
227
|
+
}
|
|
228
|
+
declare class VersionConflictError extends NdbError {
|
|
229
|
+
}
|
|
230
|
+
declare class DuplicateIdError extends NdbError {
|
|
231
|
+
}
|
|
232
|
+
declare class UniqueViolationError extends NdbError {
|
|
233
|
+
}
|
|
234
|
+
declare class InvalidQueryError extends NdbError {
|
|
235
|
+
}
|
|
236
|
+
declare class CursorError extends NdbError {
|
|
237
|
+
}
|
|
238
|
+
declare class WatchLaggedError extends NdbError {
|
|
239
|
+
}
|
|
240
|
+
declare class HistoryTruncatedError extends NdbError {
|
|
241
|
+
}
|
|
242
|
+
declare class TtlError extends NdbError {
|
|
243
|
+
}
|
|
244
|
+
declare function makeError(code: ErrorCode, message: string, status?: number): NdbError;
|
|
245
|
+
|
|
246
|
+
export { CursorError, DuplicateIdError, HistoryTruncatedError, InvalidQueryError, Model, Ndb, NdbError, NotFoundError, Query, TtlError, UnauthorizedError, UniqueViolationError, VersionConflictError, WatchLaggedError, connect, makeError };
|
|
247
|
+
export type { AggregateOptions, AggregateResult, ConnectOptions, Doc, Duration, ErrorCode, ExpireResult, FieldDef, FieldType, Fields, Input, InsertOptions, Ops, Row, Schema, SortSpec, TypeMap, UpdateOptions, WatchEvent, WatchOptions, Where, WriteOptions, WriteResult };
|