@thadeu/ndb 0.4.0 → 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/dist/index.d.cts CHANGED
@@ -68,9 +68,14 @@ type Where<F extends Fields> = {
68
68
  [P in `${JsonKeys<F>}.${string}`]?: unknown;
69
69
  };
70
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
+ }
71
76
  interface WriteResult {
72
77
  _id: string;
73
- v: number;
78
+ _v: number;
74
79
  }
75
80
  type Duration = number | string;
76
81
  type Filter<F extends Fields> = Where<F> & {
@@ -89,7 +94,12 @@ interface UpdateOps<F extends Fields = Fields> {
89
94
  $min?: Record<string, number | string>;
90
95
  $max?: Record<string, number | string>;
91
96
  }
92
- interface UpdateOptions {
97
+ interface UpdateOptions<F extends Fields = Fields> {
98
+ guard?: Filter<F>;
99
+ upsert?: boolean;
100
+ expireIn?: Duration;
101
+ }
102
+ interface UpdateByOptions {
93
103
  many?: boolean;
94
104
  upsert?: boolean;
95
105
  expireIn?: Duration;
@@ -117,8 +127,8 @@ interface AggregateOptions {
117
127
  after?: string;
118
128
  count?: boolean;
119
129
  }
120
- interface FindBody {
121
- where?: Record<string, unknown>;
130
+ interface SearchBody {
131
+ query?: Record<string, unknown>;
122
132
  fields?: string[];
123
133
  sort?: Record<string, 1 | -1>;
124
134
  limit?: number;
@@ -126,7 +136,7 @@ interface FindBody {
126
136
  after?: string;
127
137
  count?: boolean;
128
138
  }
129
- interface FindResult<R> {
139
+ interface SearchResult<R> {
130
140
  rows: R[];
131
141
  next: string;
132
142
  total: number;
@@ -140,14 +150,14 @@ interface WatchOptions<F extends Fields = Fields> {
140
150
  from?: string;
141
151
  limit?: number;
142
152
  signal?: AbortSignal;
143
- where?: Where<F>;
153
+ query?: Where<F>;
144
154
  }
145
155
  interface WatchEvent<R> {
146
156
  consumer: string;
147
157
  pos: string;
148
158
  op: 'put' | 'del' | 'truncate';
149
159
  _id: string;
150
- v: number;
160
+ _v: number;
151
161
  doc: R | undefined;
152
162
  }
153
163
 
@@ -160,12 +170,12 @@ interface State {
160
170
  after?: string;
161
171
  }
162
172
  declare class Query<F extends Fields, R = Row<F>> implements PromiseLike<R[]> {
163
- private readonly model;
173
+ private readonly coll;
164
174
  private readonly state;
165
175
  nextCursor: string;
166
- constructor(model: Model<F>, state?: State);
167
- where(w: Where<F>): Query<F, R>;
168
- whereRaw(w: Record<string, unknown>): Query<F, R>;
176
+ constructor(coll: Collection<F>, state?: State);
177
+ query(w: Where<F>): Query<F, R>;
178
+ rawQuery(w: Record<string, unknown>): Query<F, R>;
169
179
  not(w: Where<F>): Query<F, R>;
170
180
  or(...ws: Where<F>[]): Query<F, R>;
171
181
  sort(spec: SortSpec<F>): Query<F, R>;
@@ -178,26 +188,30 @@ declare class Query<F extends Fields, R = Row<F>> implements PromiseLike<R[]> {
178
188
  all(): Promise<R[]>;
179
189
  first(): Promise<R | null>;
180
190
  count(): Promise<number>;
181
- iterate(): AsyncGenerator<R>;
191
+ each(): AsyncGenerator<R>;
182
192
  private rows;
183
193
  private body;
184
194
  private whereDoc;
185
195
  private with;
186
196
  }
187
197
 
188
- declare class Model<F extends Fields> {
198
+ declare class Collection<F extends Fields> {
189
199
  readonly db: Ndb;
190
200
  readonly name: string;
191
201
  readonly schema: Schema<F>;
192
202
  private ensured?;
193
203
  constructor(db: Ndb, name: string, schema: Schema<F>);
194
- path(op?: string): string;
204
+ path(action?: string): string;
195
205
  get isPattern(): boolean;
196
206
  ready(): Promise<void>;
197
- insert(docs: Input<F> | Input<F>[], opts?: InsertOptions): Promise<WriteResult[]>;
198
- create(docs: Input<F> | Input<F>[], opts?: InsertOptions): Promise<WriteResult[]>;
199
- update(idOrFilter: string | Filter<F>, ops: UpdateOps<F>, opts?: UpdateOptions): Promise<UpdateResult<F>>;
200
- delete(idOrFilter: string | Filter<F>, opts?: DeleteOptions): Promise<DeleteResult>;
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>;
201
215
  truncate(): Promise<void>;
202
216
  drop(): Promise<void>;
203
217
  private confirm;
@@ -207,9 +221,8 @@ declare class Model<F extends Fields> {
207
221
  ttl(id: string): Promise<number | null>;
208
222
  private setExpiry;
209
223
  get(id: string): Promise<Row<F> | null>;
210
- query(): Query<F>;
211
- where(w: Where<F>): Query<F>;
212
- whereRaw(w: Record<string, unknown>): Query<F>;
224
+ query(w?: Where<F>): Query<F>;
225
+ rawQuery(w: Record<string, unknown>): Query<F>;
213
226
  not(w: Where<F>): Query<F>;
214
227
  or(...ws: Where<F>[]): Query<F>;
215
228
  sort(spec: SortSpec<F>): Query<F>;
@@ -219,14 +232,20 @@ declare class Model<F extends Fields> {
219
232
  after(token: string): Query<F>;
220
233
  fields(...names: string[]): Query<F, Partial<Row<F>>>;
221
234
  all(): Promise<Row<F>[]>;
222
- count(): Promise<number>;
235
+ count(w?: Where<F>): Promise<number>;
223
236
  first(): Promise<Row<F> | null>;
224
- iterate(): AsyncGenerator<Row<F>>;
225
- find(body: FindBody): Promise<FindResult<Row<F>>>;
237
+ each(): AsyncGenerator<Row<F>>;
238
+ search(body: SearchBody): Promise<SearchResult<Row<F>>>;
226
239
  aggregate<R = Record<string, unknown>>(pipeline: Record<string, unknown>[], opts?: AggregateOptions): Promise<AggregateResult<R>>;
227
240
  watch(consumer: string, opts?: WatchOptions<F>): AsyncGenerator<WatchEvent<Row<F>>>;
228
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[]>;
229
246
  decode(raw: Record<string, unknown>): Record<string, unknown>;
247
+ private send;
248
+ private updated;
230
249
  private catalog;
231
250
  }
232
251
 
@@ -247,8 +266,8 @@ declare class Transport {
247
266
  private readonly token;
248
267
  private readonly readyTimeout;
249
268
  constructor(addr?: string, opts?: ConnectOptions);
250
- stream(method: Method, path: string, body?: unknown, signal?: AbortSignal): Promise<Streamed>;
251
- 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>;
252
271
  close(): Promise<void>;
253
272
  private withReadyRetry;
254
273
  private headers;
@@ -258,8 +277,13 @@ declare class Transport {
258
277
  declare class Ndb {
259
278
  readonly transport: Transport;
260
279
  constructor(addr?: string, opts?: ConnectOptions);
261
- model<const F extends Fields>(name: string, schema: Schema<F>): Model<F>;
280
+ collection<const F extends Fields>(name: string, schema: Schema<F>): Collection<F>;
262
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>;
263
287
  request<T = unknown>(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, body?: unknown): Promise<T>;
264
288
  stream(...args: Parameters<Transport['stream']>): ReturnType<Transport['stream']>;
265
289
  close(): Promise<void>;
@@ -296,5 +320,5 @@ declare class TtlError extends NdbError {
296
320
  }
297
321
  declare function makeError(code: ErrorCode, message: string, status?: number): NdbError;
298
322
 
299
- export { CursorError, DuplicateIdError, HistoryTruncatedError, InvalidQueryError, InvalidUpdateError, Model, Ndb, NdbError, NotFoundError, Query, TtlError, UnauthorizedError, UniqueViolationError, WatchLaggedError, connect, makeError, newId };
300
- export type { AggregateOptions, AggregateResult, ConnectOptions, DeleteOptions, DeleteResult, Doc, Duration, ErrorCode, ExpireResult, FieldDef, FieldType, Fields, Filter, FindBody, FindResult, 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
@@ -68,9 +68,14 @@ type Where<F extends Fields> = {
68
68
  [P in `${JsonKeys<F>}.${string}`]?: unknown;
69
69
  };
70
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
+ }
71
76
  interface WriteResult {
72
77
  _id: string;
73
- v: number;
78
+ _v: number;
74
79
  }
75
80
  type Duration = number | string;
76
81
  type Filter<F extends Fields> = Where<F> & {
@@ -89,7 +94,12 @@ interface UpdateOps<F extends Fields = Fields> {
89
94
  $min?: Record<string, number | string>;
90
95
  $max?: Record<string, number | string>;
91
96
  }
92
- interface UpdateOptions {
97
+ interface UpdateOptions<F extends Fields = Fields> {
98
+ guard?: Filter<F>;
99
+ upsert?: boolean;
100
+ expireIn?: Duration;
101
+ }
102
+ interface UpdateByOptions {
93
103
  many?: boolean;
94
104
  upsert?: boolean;
95
105
  expireIn?: Duration;
@@ -117,8 +127,8 @@ interface AggregateOptions {
117
127
  after?: string;
118
128
  count?: boolean;
119
129
  }
120
- interface FindBody {
121
- where?: Record<string, unknown>;
130
+ interface SearchBody {
131
+ query?: Record<string, unknown>;
122
132
  fields?: string[];
123
133
  sort?: Record<string, 1 | -1>;
124
134
  limit?: number;
@@ -126,7 +136,7 @@ interface FindBody {
126
136
  after?: string;
127
137
  count?: boolean;
128
138
  }
129
- interface FindResult<R> {
139
+ interface SearchResult<R> {
130
140
  rows: R[];
131
141
  next: string;
132
142
  total: number;
@@ -140,14 +150,14 @@ interface WatchOptions<F extends Fields = Fields> {
140
150
  from?: string;
141
151
  limit?: number;
142
152
  signal?: AbortSignal;
143
- where?: Where<F>;
153
+ query?: Where<F>;
144
154
  }
145
155
  interface WatchEvent<R> {
146
156
  consumer: string;
147
157
  pos: string;
148
158
  op: 'put' | 'del' | 'truncate';
149
159
  _id: string;
150
- v: number;
160
+ _v: number;
151
161
  doc: R | undefined;
152
162
  }
153
163
 
@@ -160,12 +170,12 @@ interface State {
160
170
  after?: string;
161
171
  }
162
172
  declare class Query<F extends Fields, R = Row<F>> implements PromiseLike<R[]> {
163
- private readonly model;
173
+ private readonly coll;
164
174
  private readonly state;
165
175
  nextCursor: string;
166
- constructor(model: Model<F>, state?: State);
167
- where(w: Where<F>): Query<F, R>;
168
- whereRaw(w: Record<string, unknown>): Query<F, R>;
176
+ constructor(coll: Collection<F>, state?: State);
177
+ query(w: Where<F>): Query<F, R>;
178
+ rawQuery(w: Record<string, unknown>): Query<F, R>;
169
179
  not(w: Where<F>): Query<F, R>;
170
180
  or(...ws: Where<F>[]): Query<F, R>;
171
181
  sort(spec: SortSpec<F>): Query<F, R>;
@@ -178,26 +188,30 @@ declare class Query<F extends Fields, R = Row<F>> implements PromiseLike<R[]> {
178
188
  all(): Promise<R[]>;
179
189
  first(): Promise<R | null>;
180
190
  count(): Promise<number>;
181
- iterate(): AsyncGenerator<R>;
191
+ each(): AsyncGenerator<R>;
182
192
  private rows;
183
193
  private body;
184
194
  private whereDoc;
185
195
  private with;
186
196
  }
187
197
 
188
- declare class Model<F extends Fields> {
198
+ declare class Collection<F extends Fields> {
189
199
  readonly db: Ndb;
190
200
  readonly name: string;
191
201
  readonly schema: Schema<F>;
192
202
  private ensured?;
193
203
  constructor(db: Ndb, name: string, schema: Schema<F>);
194
- path(op?: string): string;
204
+ path(action?: string): string;
195
205
  get isPattern(): boolean;
196
206
  ready(): Promise<void>;
197
- insert(docs: Input<F> | Input<F>[], opts?: InsertOptions): Promise<WriteResult[]>;
198
- create(docs: Input<F> | Input<F>[], opts?: InsertOptions): Promise<WriteResult[]>;
199
- update(idOrFilter: string | Filter<F>, ops: UpdateOps<F>, opts?: UpdateOptions): Promise<UpdateResult<F>>;
200
- delete(idOrFilter: string | Filter<F>, opts?: DeleteOptions): Promise<DeleteResult>;
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>;
201
215
  truncate(): Promise<void>;
202
216
  drop(): Promise<void>;
203
217
  private confirm;
@@ -207,9 +221,8 @@ declare class Model<F extends Fields> {
207
221
  ttl(id: string): Promise<number | null>;
208
222
  private setExpiry;
209
223
  get(id: string): Promise<Row<F> | null>;
210
- query(): Query<F>;
211
- where(w: Where<F>): Query<F>;
212
- whereRaw(w: Record<string, unknown>): Query<F>;
224
+ query(w?: Where<F>): Query<F>;
225
+ rawQuery(w: Record<string, unknown>): Query<F>;
213
226
  not(w: Where<F>): Query<F>;
214
227
  or(...ws: Where<F>[]): Query<F>;
215
228
  sort(spec: SortSpec<F>): Query<F>;
@@ -219,14 +232,20 @@ declare class Model<F extends Fields> {
219
232
  after(token: string): Query<F>;
220
233
  fields(...names: string[]): Query<F, Partial<Row<F>>>;
221
234
  all(): Promise<Row<F>[]>;
222
- count(): Promise<number>;
235
+ count(w?: Where<F>): Promise<number>;
223
236
  first(): Promise<Row<F> | null>;
224
- iterate(): AsyncGenerator<Row<F>>;
225
- find(body: FindBody): Promise<FindResult<Row<F>>>;
237
+ each(): AsyncGenerator<Row<F>>;
238
+ search(body: SearchBody): Promise<SearchResult<Row<F>>>;
226
239
  aggregate<R = Record<string, unknown>>(pipeline: Record<string, unknown>[], opts?: AggregateOptions): Promise<AggregateResult<R>>;
227
240
  watch(consumer: string, opts?: WatchOptions<F>): AsyncGenerator<WatchEvent<Row<F>>>;
228
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[]>;
229
246
  decode(raw: Record<string, unknown>): Record<string, unknown>;
247
+ private send;
248
+ private updated;
230
249
  private catalog;
231
250
  }
232
251
 
@@ -247,8 +266,8 @@ declare class Transport {
247
266
  private readonly token;
248
267
  private readonly readyTimeout;
249
268
  constructor(addr?: string, opts?: ConnectOptions);
250
- stream(method: Method, path: string, body?: unknown, signal?: AbortSignal): Promise<Streamed>;
251
- 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>;
252
271
  close(): Promise<void>;
253
272
  private withReadyRetry;
254
273
  private headers;
@@ -258,8 +277,13 @@ declare class Transport {
258
277
  declare class Ndb {
259
278
  readonly transport: Transport;
260
279
  constructor(addr?: string, opts?: ConnectOptions);
261
- model<const F extends Fields>(name: string, schema: Schema<F>): Model<F>;
280
+ collection<const F extends Fields>(name: string, schema: Schema<F>): Collection<F>;
262
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>;
263
287
  request<T = unknown>(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, body?: unknown): Promise<T>;
264
288
  stream(...args: Parameters<Transport['stream']>): ReturnType<Transport['stream']>;
265
289
  close(): Promise<void>;
@@ -296,5 +320,5 @@ declare class TtlError extends NdbError {
296
320
  }
297
321
  declare function makeError(code: ErrorCode, message: string, status?: number): NdbError;
298
322
 
299
- export { CursorError, DuplicateIdError, HistoryTruncatedError, InvalidQueryError, InvalidUpdateError, Model, Ndb, NdbError, NotFoundError, Query, TtlError, UnauthorizedError, UniqueViolationError, WatchLaggedError, connect, makeError, newId };
300
- export type { AggregateOptions, AggregateResult, ConnectOptions, DeleteOptions, DeleteResult, Doc, Duration, ErrorCode, ExpireResult, FieldDef, FieldType, Fields, Filter, FindBody, FindResult, 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 };