@thadeu/ndb 0.3.2 → 1.0.0
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/README.md +111 -47
- package/dist/index.cjs +231 -131
- package/dist/index.d.cts +72 -25
- package/dist/index.d.ts +72 -25
- package/dist/index.js +230 -130
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -39,6 +39,7 @@ type Input<F extends Fields> = {
|
|
|
39
39
|
type Row<F extends Fields> = Doc<F> & {
|
|
40
40
|
_id: string;
|
|
41
41
|
_v: number;
|
|
42
|
+
_coll?: string;
|
|
42
43
|
};
|
|
43
44
|
interface Ops<V> {
|
|
44
45
|
$eq?: V;
|
|
@@ -52,6 +53,7 @@ interface Ops<V> {
|
|
|
52
53
|
$exists?: boolean;
|
|
53
54
|
$regex?: string | RegExp;
|
|
54
55
|
$options?: string;
|
|
56
|
+
$elemMatch?: Record<string, unknown>;
|
|
55
57
|
}
|
|
56
58
|
type Operand<V> = V extends Date ? Date | string : V;
|
|
57
59
|
type RegexOperand<V> = V extends string ? RegExp : never;
|
|
@@ -66,9 +68,14 @@ type Where<F extends Fields> = {
|
|
|
66
68
|
[P in `${JsonKeys<F>}.${string}`]?: unknown;
|
|
67
69
|
};
|
|
68
70
|
type SortSpec<F extends Fields> = Partial<Record<Extract<keyof F, string> | '_id', 1 | -1>>;
|
|
71
|
+
interface Blob {
|
|
72
|
+
$blob: string;
|
|
73
|
+
size: number;
|
|
74
|
+
type?: string;
|
|
75
|
+
}
|
|
69
76
|
interface WriteResult {
|
|
70
77
|
_id: string;
|
|
71
|
-
|
|
78
|
+
_v: number;
|
|
72
79
|
}
|
|
73
80
|
type Duration = number | string;
|
|
74
81
|
type Filter<F extends Fields> = Where<F> & {
|
|
@@ -87,7 +94,12 @@ interface UpdateOps<F extends Fields = Fields> {
|
|
|
87
94
|
$min?: Record<string, number | string>;
|
|
88
95
|
$max?: Record<string, number | string>;
|
|
89
96
|
}
|
|
90
|
-
interface UpdateOptions {
|
|
97
|
+
interface UpdateOptions<F extends Fields = Fields> {
|
|
98
|
+
guard?: Filter<F>;
|
|
99
|
+
upsert?: boolean;
|
|
100
|
+
expireIn?: Duration;
|
|
101
|
+
}
|
|
102
|
+
interface UpdateByOptions {
|
|
91
103
|
many?: boolean;
|
|
92
104
|
upsert?: boolean;
|
|
93
105
|
expireIn?: Duration;
|
|
@@ -115,6 +127,20 @@ interface AggregateOptions {
|
|
|
115
127
|
after?: string;
|
|
116
128
|
count?: boolean;
|
|
117
129
|
}
|
|
130
|
+
interface SearchBody {
|
|
131
|
+
query?: Record<string, unknown>;
|
|
132
|
+
fields?: string[];
|
|
133
|
+
sort?: Record<string, 1 | -1>;
|
|
134
|
+
limit?: number;
|
|
135
|
+
skip?: number;
|
|
136
|
+
after?: string;
|
|
137
|
+
count?: boolean;
|
|
138
|
+
}
|
|
139
|
+
interface SearchResult<R> {
|
|
140
|
+
rows: R[];
|
|
141
|
+
next: string;
|
|
142
|
+
total: number;
|
|
143
|
+
}
|
|
118
144
|
interface AggregateResult<R = Record<string, unknown>> {
|
|
119
145
|
rows: R[];
|
|
120
146
|
next: string;
|
|
@@ -124,14 +150,14 @@ interface WatchOptions<F extends Fields = Fields> {
|
|
|
124
150
|
from?: string;
|
|
125
151
|
limit?: number;
|
|
126
152
|
signal?: AbortSignal;
|
|
127
|
-
|
|
153
|
+
query?: Where<F>;
|
|
128
154
|
}
|
|
129
155
|
interface WatchEvent<R> {
|
|
130
156
|
consumer: string;
|
|
131
157
|
pos: string;
|
|
132
|
-
op: 'put' | 'del';
|
|
158
|
+
op: 'put' | 'del' | 'truncate';
|
|
133
159
|
_id: string;
|
|
134
|
-
|
|
160
|
+
_v: number;
|
|
135
161
|
doc: R | undefined;
|
|
136
162
|
}
|
|
137
163
|
|
|
@@ -144,11 +170,12 @@ interface State {
|
|
|
144
170
|
after?: string;
|
|
145
171
|
}
|
|
146
172
|
declare class Query<F extends Fields, R = Row<F>> implements PromiseLike<R[]> {
|
|
147
|
-
private readonly
|
|
173
|
+
private readonly coll;
|
|
148
174
|
private readonly state;
|
|
149
175
|
nextCursor: string;
|
|
150
|
-
constructor(
|
|
151
|
-
|
|
176
|
+
constructor(coll: Collection<F>, state?: State);
|
|
177
|
+
query(w: Where<F>): Query<F, R>;
|
|
178
|
+
rawQuery(w: Record<string, unknown>): Query<F, R>;
|
|
152
179
|
not(w: Where<F>): Query<F, R>;
|
|
153
180
|
or(...ws: Where<F>[]): Query<F, R>;
|
|
154
181
|
sort(spec: SortSpec<F>): Query<F, R>;
|
|
@@ -161,33 +188,41 @@ declare class Query<F extends Fields, R = Row<F>> implements PromiseLike<R[]> {
|
|
|
161
188
|
all(): Promise<R[]>;
|
|
162
189
|
first(): Promise<R | null>;
|
|
163
190
|
count(): Promise<number>;
|
|
164
|
-
|
|
191
|
+
each(): AsyncGenerator<R>;
|
|
165
192
|
private rows;
|
|
166
193
|
private body;
|
|
167
194
|
private whereDoc;
|
|
168
195
|
private with;
|
|
169
196
|
}
|
|
170
197
|
|
|
171
|
-
declare class
|
|
198
|
+
declare class Collection<F extends Fields> {
|
|
172
199
|
readonly db: Ndb;
|
|
173
200
|
readonly name: string;
|
|
174
201
|
readonly schema: Schema<F>;
|
|
175
202
|
private ensured?;
|
|
176
203
|
constructor(db: Ndb, name: string, schema: Schema<F>);
|
|
177
|
-
path(
|
|
204
|
+
path(action?: string): string;
|
|
205
|
+
get isPattern(): boolean;
|
|
178
206
|
ready(): Promise<void>;
|
|
179
|
-
insert(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
207
|
+
insert(doc: Input<F>, opts?: InsertOptions): Promise<WriteResult>;
|
|
208
|
+
insert(docs: Input<F>[], opts?: InsertOptions): Promise<WriteResult[]>;
|
|
209
|
+
upsert(doc: Input<F>, opts?: InsertOptions): Promise<WriteResult>;
|
|
210
|
+
upsertAll(docs: Input<F>[], opts?: InsertOptions): Promise<WriteResult[]>;
|
|
211
|
+
update(id: string, ops: UpdateOps<F>, opts?: UpdateOptions<F>): Promise<UpdateResult<F>>;
|
|
212
|
+
updateBy(query: Filter<F>, ops: UpdateOps<F>, opts?: UpdateByOptions): Promise<UpdateResult<F>>;
|
|
213
|
+
delete(id: string): Promise<DeleteResult>;
|
|
214
|
+
deleteBy(query: Filter<F>, opts?: DeleteOptions): Promise<DeleteResult>;
|
|
215
|
+
truncate(): Promise<void>;
|
|
216
|
+
drop(): Promise<void>;
|
|
217
|
+
private confirm;
|
|
183
218
|
expire(id: string, duration: Duration): Promise<ExpireResult>;
|
|
184
219
|
expireAt(id: string, at: Date): Promise<ExpireResult>;
|
|
185
220
|
persist(id: string): Promise<WriteResult>;
|
|
186
221
|
ttl(id: string): Promise<number | null>;
|
|
187
222
|
private setExpiry;
|
|
188
223
|
get(id: string): Promise<Row<F> | null>;
|
|
189
|
-
query(): Query<F>;
|
|
190
|
-
|
|
224
|
+
query(w?: Where<F>): Query<F>;
|
|
225
|
+
rawQuery(w: Record<string, unknown>): Query<F>;
|
|
191
226
|
not(w: Where<F>): Query<F>;
|
|
192
227
|
or(...ws: Where<F>[]): Query<F>;
|
|
193
228
|
sort(spec: SortSpec<F>): Query<F>;
|
|
@@ -197,13 +232,20 @@ declare class Model<F extends Fields> {
|
|
|
197
232
|
after(token: string): Query<F>;
|
|
198
233
|
fields(...names: string[]): Query<F, Partial<Row<F>>>;
|
|
199
234
|
all(): Promise<Row<F>[]>;
|
|
200
|
-
count(): Promise<number>;
|
|
235
|
+
count(w?: Where<F>): Promise<number>;
|
|
201
236
|
first(): Promise<Row<F> | null>;
|
|
202
|
-
|
|
237
|
+
each(): AsyncGenerator<Row<F>>;
|
|
238
|
+
search(body: SearchBody): Promise<SearchResult<Row<F>>>;
|
|
203
239
|
aggregate<R = Record<string, unknown>>(pipeline: Record<string, unknown>[], opts?: AggregateOptions): Promise<AggregateResult<R>>;
|
|
204
240
|
watch(consumer: string, opts?: WatchOptions<F>): AsyncGenerator<WatchEvent<Row<F>>>;
|
|
205
241
|
ack(event: Pick<WatchEvent<unknown>, 'consumer' | 'pos'>): Promise<void>;
|
|
242
|
+
stats(): Promise<Record<string, unknown>>;
|
|
243
|
+
compact(): Promise<Record<string, unknown>>;
|
|
244
|
+
ensureIndex(field: string): Promise<string[]>;
|
|
245
|
+
dropIndex(field: string): Promise<string[]>;
|
|
206
246
|
decode(raw: Record<string, unknown>): Record<string, unknown>;
|
|
247
|
+
private send;
|
|
248
|
+
private updated;
|
|
207
249
|
private catalog;
|
|
208
250
|
}
|
|
209
251
|
|
|
@@ -224,8 +266,8 @@ declare class Transport {
|
|
|
224
266
|
private readonly token;
|
|
225
267
|
private readonly readyTimeout;
|
|
226
268
|
constructor(addr?: string, opts?: ConnectOptions);
|
|
227
|
-
stream(method: Method, path: string, body?: unknown, signal?: AbortSignal): Promise<Streamed>;
|
|
228
|
-
request<T = unknown>(method: Method, path: string, body?: unknown): Promise<T>;
|
|
269
|
+
stream(method: Method, path: string, body?: unknown, signal?: AbortSignal, contentType?: string): Promise<Streamed>;
|
|
270
|
+
request<T = unknown>(method: Method, path: string, body?: unknown, contentType?: string): Promise<T>;
|
|
229
271
|
close(): Promise<void>;
|
|
230
272
|
private withReadyRetry;
|
|
231
273
|
private headers;
|
|
@@ -235,8 +277,13 @@ declare class Transport {
|
|
|
235
277
|
declare class Ndb {
|
|
236
278
|
readonly transport: Transport;
|
|
237
279
|
constructor(addr?: string, opts?: ConnectOptions);
|
|
238
|
-
|
|
280
|
+
collection<const F extends Fields>(name: string, schema: Schema<F>): Collection<F>;
|
|
239
281
|
health(): Promise<void>;
|
|
282
|
+
collections(): Promise<Record<string, unknown>[]>;
|
|
283
|
+
stats(): Promise<Record<string, unknown>>;
|
|
284
|
+
size(): Promise<Record<string, unknown>>;
|
|
285
|
+
putBlob(data: Uint8Array | string, contentType?: string): Promise<Blob>;
|
|
286
|
+
getBlob(blob: Blob | string): Promise<Uint8Array>;
|
|
240
287
|
request<T = unknown>(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, body?: unknown): Promise<T>;
|
|
241
288
|
stream(...args: Parameters<Transport['stream']>): ReturnType<Transport['stream']>;
|
|
242
289
|
close(): Promise<void>;
|
|
@@ -245,7 +292,7 @@ declare function connect(addr?: string, opts?: ConnectOptions): Ndb;
|
|
|
245
292
|
|
|
246
293
|
declare function newId(): string;
|
|
247
294
|
|
|
248
|
-
type ErrorCode = 'unauthorized' | 'not_found' | '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' | 'unknown_operator' | 'no_update' | 'conflicting_update' | 'invalid_field' | 'unindexed_many' | 'empty_filter' | 'invalid_update' | 'http_status' | (string & {});
|
|
295
|
+
type ErrorCode = 'unauthorized' | 'not_found' | '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' | 'unknown_operator' | 'no_update' | 'conflicting_update' | 'invalid_field' | 'unindexed_many' | 'empty_filter' | 'confirm_required' | 'invalid_update' | 'http_status' | (string & {});
|
|
249
296
|
declare class NdbError extends Error {
|
|
250
297
|
readonly code: ErrorCode;
|
|
251
298
|
readonly status: number;
|
|
@@ -273,5 +320,5 @@ declare class TtlError extends NdbError {
|
|
|
273
320
|
}
|
|
274
321
|
declare function makeError(code: ErrorCode, message: string, status?: number): NdbError;
|
|
275
322
|
|
|
276
|
-
export { CursorError, DuplicateIdError, HistoryTruncatedError, InvalidQueryError, InvalidUpdateError,
|
|
277
|
-
export type { AggregateOptions, AggregateResult, ConnectOptions, DeleteOptions, DeleteResult, Doc, Duration, ErrorCode, ExpireResult, FieldDef, FieldType, Fields, Filter, Input, InsertOptions, Ops, Row, Schema, SortSpec, TypeMap, UpdateOps, UpdateOptions, UpdateResult, WatchEvent, WatchOptions, Where, WriteResult };
|
|
323
|
+
export { Collection, CursorError, DuplicateIdError, HistoryTruncatedError, InvalidQueryError, InvalidUpdateError, Ndb, NdbError, NotFoundError, Query, TtlError, UnauthorizedError, UniqueViolationError, WatchLaggedError, connect, makeError, newId };
|
|
324
|
+
export type { AggregateOptions, AggregateResult, Blob, ConnectOptions, DeleteOptions, DeleteResult, Doc, Duration, ErrorCode, ExpireResult, FieldDef, FieldType, Fields, Filter, Input, InsertOptions, Ops, Row, Schema, SearchBody, SearchResult, SortSpec, TypeMap, UpdateByOptions, UpdateOps, UpdateOptions, UpdateResult, WatchEvent, WatchOptions, Where, WriteResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ type Input<F extends Fields> = {
|
|
|
39
39
|
type Row<F extends Fields> = Doc<F> & {
|
|
40
40
|
_id: string;
|
|
41
41
|
_v: number;
|
|
42
|
+
_coll?: string;
|
|
42
43
|
};
|
|
43
44
|
interface Ops<V> {
|
|
44
45
|
$eq?: V;
|
|
@@ -52,6 +53,7 @@ interface Ops<V> {
|
|
|
52
53
|
$exists?: boolean;
|
|
53
54
|
$regex?: string | RegExp;
|
|
54
55
|
$options?: string;
|
|
56
|
+
$elemMatch?: Record<string, unknown>;
|
|
55
57
|
}
|
|
56
58
|
type Operand<V> = V extends Date ? Date | string : V;
|
|
57
59
|
type RegexOperand<V> = V extends string ? RegExp : never;
|
|
@@ -66,9 +68,14 @@ type Where<F extends Fields> = {
|
|
|
66
68
|
[P in `${JsonKeys<F>}.${string}`]?: unknown;
|
|
67
69
|
};
|
|
68
70
|
type SortSpec<F extends Fields> = Partial<Record<Extract<keyof F, string> | '_id', 1 | -1>>;
|
|
71
|
+
interface Blob {
|
|
72
|
+
$blob: string;
|
|
73
|
+
size: number;
|
|
74
|
+
type?: string;
|
|
75
|
+
}
|
|
69
76
|
interface WriteResult {
|
|
70
77
|
_id: string;
|
|
71
|
-
|
|
78
|
+
_v: number;
|
|
72
79
|
}
|
|
73
80
|
type Duration = number | string;
|
|
74
81
|
type Filter<F extends Fields> = Where<F> & {
|
|
@@ -87,7 +94,12 @@ interface UpdateOps<F extends Fields = Fields> {
|
|
|
87
94
|
$min?: Record<string, number | string>;
|
|
88
95
|
$max?: Record<string, number | string>;
|
|
89
96
|
}
|
|
90
|
-
interface UpdateOptions {
|
|
97
|
+
interface UpdateOptions<F extends Fields = Fields> {
|
|
98
|
+
guard?: Filter<F>;
|
|
99
|
+
upsert?: boolean;
|
|
100
|
+
expireIn?: Duration;
|
|
101
|
+
}
|
|
102
|
+
interface UpdateByOptions {
|
|
91
103
|
many?: boolean;
|
|
92
104
|
upsert?: boolean;
|
|
93
105
|
expireIn?: Duration;
|
|
@@ -115,6 +127,20 @@ interface AggregateOptions {
|
|
|
115
127
|
after?: string;
|
|
116
128
|
count?: boolean;
|
|
117
129
|
}
|
|
130
|
+
interface SearchBody {
|
|
131
|
+
query?: Record<string, unknown>;
|
|
132
|
+
fields?: string[];
|
|
133
|
+
sort?: Record<string, 1 | -1>;
|
|
134
|
+
limit?: number;
|
|
135
|
+
skip?: number;
|
|
136
|
+
after?: string;
|
|
137
|
+
count?: boolean;
|
|
138
|
+
}
|
|
139
|
+
interface SearchResult<R> {
|
|
140
|
+
rows: R[];
|
|
141
|
+
next: string;
|
|
142
|
+
total: number;
|
|
143
|
+
}
|
|
118
144
|
interface AggregateResult<R = Record<string, unknown>> {
|
|
119
145
|
rows: R[];
|
|
120
146
|
next: string;
|
|
@@ -124,14 +150,14 @@ interface WatchOptions<F extends Fields = Fields> {
|
|
|
124
150
|
from?: string;
|
|
125
151
|
limit?: number;
|
|
126
152
|
signal?: AbortSignal;
|
|
127
|
-
|
|
153
|
+
query?: Where<F>;
|
|
128
154
|
}
|
|
129
155
|
interface WatchEvent<R> {
|
|
130
156
|
consumer: string;
|
|
131
157
|
pos: string;
|
|
132
|
-
op: 'put' | 'del';
|
|
158
|
+
op: 'put' | 'del' | 'truncate';
|
|
133
159
|
_id: string;
|
|
134
|
-
|
|
160
|
+
_v: number;
|
|
135
161
|
doc: R | undefined;
|
|
136
162
|
}
|
|
137
163
|
|
|
@@ -144,11 +170,12 @@ interface State {
|
|
|
144
170
|
after?: string;
|
|
145
171
|
}
|
|
146
172
|
declare class Query<F extends Fields, R = Row<F>> implements PromiseLike<R[]> {
|
|
147
|
-
private readonly
|
|
173
|
+
private readonly coll;
|
|
148
174
|
private readonly state;
|
|
149
175
|
nextCursor: string;
|
|
150
|
-
constructor(
|
|
151
|
-
|
|
176
|
+
constructor(coll: Collection<F>, state?: State);
|
|
177
|
+
query(w: Where<F>): Query<F, R>;
|
|
178
|
+
rawQuery(w: Record<string, unknown>): Query<F, R>;
|
|
152
179
|
not(w: Where<F>): Query<F, R>;
|
|
153
180
|
or(...ws: Where<F>[]): Query<F, R>;
|
|
154
181
|
sort(spec: SortSpec<F>): Query<F, R>;
|
|
@@ -161,33 +188,41 @@ declare class Query<F extends Fields, R = Row<F>> implements PromiseLike<R[]> {
|
|
|
161
188
|
all(): Promise<R[]>;
|
|
162
189
|
first(): Promise<R | null>;
|
|
163
190
|
count(): Promise<number>;
|
|
164
|
-
|
|
191
|
+
each(): AsyncGenerator<R>;
|
|
165
192
|
private rows;
|
|
166
193
|
private body;
|
|
167
194
|
private whereDoc;
|
|
168
195
|
private with;
|
|
169
196
|
}
|
|
170
197
|
|
|
171
|
-
declare class
|
|
198
|
+
declare class Collection<F extends Fields> {
|
|
172
199
|
readonly db: Ndb;
|
|
173
200
|
readonly name: string;
|
|
174
201
|
readonly schema: Schema<F>;
|
|
175
202
|
private ensured?;
|
|
176
203
|
constructor(db: Ndb, name: string, schema: Schema<F>);
|
|
177
|
-
path(
|
|
204
|
+
path(action?: string): string;
|
|
205
|
+
get isPattern(): boolean;
|
|
178
206
|
ready(): Promise<void>;
|
|
179
|
-
insert(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
207
|
+
insert(doc: Input<F>, opts?: InsertOptions): Promise<WriteResult>;
|
|
208
|
+
insert(docs: Input<F>[], opts?: InsertOptions): Promise<WriteResult[]>;
|
|
209
|
+
upsert(doc: Input<F>, opts?: InsertOptions): Promise<WriteResult>;
|
|
210
|
+
upsertAll(docs: Input<F>[], opts?: InsertOptions): Promise<WriteResult[]>;
|
|
211
|
+
update(id: string, ops: UpdateOps<F>, opts?: UpdateOptions<F>): Promise<UpdateResult<F>>;
|
|
212
|
+
updateBy(query: Filter<F>, ops: UpdateOps<F>, opts?: UpdateByOptions): Promise<UpdateResult<F>>;
|
|
213
|
+
delete(id: string): Promise<DeleteResult>;
|
|
214
|
+
deleteBy(query: Filter<F>, opts?: DeleteOptions): Promise<DeleteResult>;
|
|
215
|
+
truncate(): Promise<void>;
|
|
216
|
+
drop(): Promise<void>;
|
|
217
|
+
private confirm;
|
|
183
218
|
expire(id: string, duration: Duration): Promise<ExpireResult>;
|
|
184
219
|
expireAt(id: string, at: Date): Promise<ExpireResult>;
|
|
185
220
|
persist(id: string): Promise<WriteResult>;
|
|
186
221
|
ttl(id: string): Promise<number | null>;
|
|
187
222
|
private setExpiry;
|
|
188
223
|
get(id: string): Promise<Row<F> | null>;
|
|
189
|
-
query(): Query<F>;
|
|
190
|
-
|
|
224
|
+
query(w?: Where<F>): Query<F>;
|
|
225
|
+
rawQuery(w: Record<string, unknown>): Query<F>;
|
|
191
226
|
not(w: Where<F>): Query<F>;
|
|
192
227
|
or(...ws: Where<F>[]): Query<F>;
|
|
193
228
|
sort(spec: SortSpec<F>): Query<F>;
|
|
@@ -197,13 +232,20 @@ declare class Model<F extends Fields> {
|
|
|
197
232
|
after(token: string): Query<F>;
|
|
198
233
|
fields(...names: string[]): Query<F, Partial<Row<F>>>;
|
|
199
234
|
all(): Promise<Row<F>[]>;
|
|
200
|
-
count(): Promise<number>;
|
|
235
|
+
count(w?: Where<F>): Promise<number>;
|
|
201
236
|
first(): Promise<Row<F> | null>;
|
|
202
|
-
|
|
237
|
+
each(): AsyncGenerator<Row<F>>;
|
|
238
|
+
search(body: SearchBody): Promise<SearchResult<Row<F>>>;
|
|
203
239
|
aggregate<R = Record<string, unknown>>(pipeline: Record<string, unknown>[], opts?: AggregateOptions): Promise<AggregateResult<R>>;
|
|
204
240
|
watch(consumer: string, opts?: WatchOptions<F>): AsyncGenerator<WatchEvent<Row<F>>>;
|
|
205
241
|
ack(event: Pick<WatchEvent<unknown>, 'consumer' | 'pos'>): Promise<void>;
|
|
242
|
+
stats(): Promise<Record<string, unknown>>;
|
|
243
|
+
compact(): Promise<Record<string, unknown>>;
|
|
244
|
+
ensureIndex(field: string): Promise<string[]>;
|
|
245
|
+
dropIndex(field: string): Promise<string[]>;
|
|
206
246
|
decode(raw: Record<string, unknown>): Record<string, unknown>;
|
|
247
|
+
private send;
|
|
248
|
+
private updated;
|
|
207
249
|
private catalog;
|
|
208
250
|
}
|
|
209
251
|
|
|
@@ -224,8 +266,8 @@ declare class Transport {
|
|
|
224
266
|
private readonly token;
|
|
225
267
|
private readonly readyTimeout;
|
|
226
268
|
constructor(addr?: string, opts?: ConnectOptions);
|
|
227
|
-
stream(method: Method, path: string, body?: unknown, signal?: AbortSignal): Promise<Streamed>;
|
|
228
|
-
request<T = unknown>(method: Method, path: string, body?: unknown): Promise<T>;
|
|
269
|
+
stream(method: Method, path: string, body?: unknown, signal?: AbortSignal, contentType?: string): Promise<Streamed>;
|
|
270
|
+
request<T = unknown>(method: Method, path: string, body?: unknown, contentType?: string): Promise<T>;
|
|
229
271
|
close(): Promise<void>;
|
|
230
272
|
private withReadyRetry;
|
|
231
273
|
private headers;
|
|
@@ -235,8 +277,13 @@ declare class Transport {
|
|
|
235
277
|
declare class Ndb {
|
|
236
278
|
readonly transport: Transport;
|
|
237
279
|
constructor(addr?: string, opts?: ConnectOptions);
|
|
238
|
-
|
|
280
|
+
collection<const F extends Fields>(name: string, schema: Schema<F>): Collection<F>;
|
|
239
281
|
health(): Promise<void>;
|
|
282
|
+
collections(): Promise<Record<string, unknown>[]>;
|
|
283
|
+
stats(): Promise<Record<string, unknown>>;
|
|
284
|
+
size(): Promise<Record<string, unknown>>;
|
|
285
|
+
putBlob(data: Uint8Array | string, contentType?: string): Promise<Blob>;
|
|
286
|
+
getBlob(blob: Blob | string): Promise<Uint8Array>;
|
|
240
287
|
request<T = unknown>(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, body?: unknown): Promise<T>;
|
|
241
288
|
stream(...args: Parameters<Transport['stream']>): ReturnType<Transport['stream']>;
|
|
242
289
|
close(): Promise<void>;
|
|
@@ -245,7 +292,7 @@ declare function connect(addr?: string, opts?: ConnectOptions): Ndb;
|
|
|
245
292
|
|
|
246
293
|
declare function newId(): string;
|
|
247
294
|
|
|
248
|
-
type ErrorCode = 'unauthorized' | 'not_found' | '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' | 'unknown_operator' | 'no_update' | 'conflicting_update' | 'invalid_field' | 'unindexed_many' | 'empty_filter' | 'invalid_update' | 'http_status' | (string & {});
|
|
295
|
+
type ErrorCode = 'unauthorized' | 'not_found' | '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' | 'unknown_operator' | 'no_update' | 'conflicting_update' | 'invalid_field' | 'unindexed_many' | 'empty_filter' | 'confirm_required' | 'invalid_update' | 'http_status' | (string & {});
|
|
249
296
|
declare class NdbError extends Error {
|
|
250
297
|
readonly code: ErrorCode;
|
|
251
298
|
readonly status: number;
|
|
@@ -273,5 +320,5 @@ declare class TtlError extends NdbError {
|
|
|
273
320
|
}
|
|
274
321
|
declare function makeError(code: ErrorCode, message: string, status?: number): NdbError;
|
|
275
322
|
|
|
276
|
-
export { CursorError, DuplicateIdError, HistoryTruncatedError, InvalidQueryError, InvalidUpdateError,
|
|
277
|
-
export type { AggregateOptions, AggregateResult, ConnectOptions, DeleteOptions, DeleteResult, Doc, Duration, ErrorCode, ExpireResult, FieldDef, FieldType, Fields, Filter, Input, InsertOptions, Ops, Row, Schema, SortSpec, TypeMap, UpdateOps, UpdateOptions, UpdateResult, WatchEvent, WatchOptions, Where, WriteResult };
|
|
323
|
+
export { Collection, CursorError, DuplicateIdError, HistoryTruncatedError, InvalidQueryError, InvalidUpdateError, Ndb, NdbError, NotFoundError, Query, TtlError, UnauthorizedError, UniqueViolationError, WatchLaggedError, connect, makeError, newId };
|
|
324
|
+
export type { AggregateOptions, AggregateResult, Blob, ConnectOptions, DeleteOptions, DeleteResult, Doc, Duration, ErrorCode, ExpireResult, FieldDef, FieldType, Fields, Filter, Input, InsertOptions, Ops, Row, Schema, SearchBody, SearchResult, SortSpec, TypeMap, UpdateByOptions, UpdateOps, UpdateOptions, UpdateResult, WatchEvent, WatchOptions, Where, WriteResult };
|