albedo-node 0.8.2 â 0.9.2
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/bun.lock +25 -0
- package/dist/index.d.ts +11 -94
- package/dist/index.js +19 -78
- package/dist/query.d.ts +132 -0
- package/dist/query.js +125 -0
- package/native/albedo.aarch64_linux_gnu.node +0 -0
- package/native/albedo.aarch64_linux_musl.node +0 -0
- package/native/albedo.aarch64_macos.node +0 -0
- package/native/albedo.x86_64_linux_gnu.node +0 -0
- package/native/albedo.x86_64_linux_musl.node +0 -0
- package/native/albedo.x86_64_macos.node +0 -0
- package/package.json +2 -2
- package/scripts/publish.ts +20 -7
package/bun.lock
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lockfileVersion": 1,
|
|
3
|
+
"configVersion": 0,
|
|
4
|
+
"workspaces": {
|
|
5
|
+
"": {
|
|
6
|
+
"name": "albedo-node",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"detect-libc": "^2.1.2",
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@types/node": "^24.0.0",
|
|
12
|
+
"typescript": "^5.9.3",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
"packages": {
|
|
17
|
+
"@types/node": ["@types/node@24.10.13", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-oH72nZRfDv9lADUBSo104Aq7gPHpQZc4BTx38r9xf9pg5LfP6EzSyH2n7qFmmxRQXh7YlUXODcYsg6PuTDSxGg=="],
|
|
18
|
+
|
|
19
|
+
"detect-libc": ["detect-libc@2.1.2", "", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="],
|
|
20
|
+
|
|
21
|
+
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
|
|
22
|
+
|
|
23
|
+
"undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
|
|
24
|
+
}
|
|
25
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type QueryInput } from "./query";
|
|
2
|
+
export * from "./query";
|
|
1
3
|
type ByteBuffer = Uint8Array;
|
|
2
4
|
type BucketHandle = object;
|
|
3
5
|
type TransactionHandle = object;
|
|
@@ -113,7 +115,6 @@ export declare const BSON: {
|
|
|
113
115
|
* ```
|
|
114
116
|
*/
|
|
115
117
|
export declare const ObjectId: ObjectIdConstructor;
|
|
116
|
-
type QueryInput = object | Query;
|
|
117
118
|
type TransformReplacement<T extends object> = T | ByteBuffer | null;
|
|
118
119
|
/**
|
|
119
120
|
* Wrapper around a native transaction handle providing
|
|
@@ -241,7 +242,7 @@ export declare class Bucket {
|
|
|
241
242
|
* bucket.delete(new Query().where('name', { $eq: 'Bob' }));
|
|
242
243
|
* ```
|
|
243
244
|
*/
|
|
244
|
-
delete(query?:
|
|
245
|
+
delete(query?: QueryInput): void;
|
|
245
246
|
/**
|
|
246
247
|
* Retrieve information about all indexes defined on the bucket.
|
|
247
248
|
* @example
|
|
@@ -279,7 +280,7 @@ export declare class Bucket {
|
|
|
279
280
|
* }
|
|
280
281
|
* ```
|
|
281
282
|
*/
|
|
282
|
-
list<T>(query?:
|
|
283
|
+
list<T>(query?: QueryInput): Generator<T>;
|
|
283
284
|
/**
|
|
284
285
|
* Async iterator that continuously polls a change subscription.
|
|
285
286
|
*
|
|
@@ -300,7 +301,7 @@ export declare class Bucket {
|
|
|
300
301
|
* }
|
|
301
302
|
* ```
|
|
302
303
|
*/
|
|
303
|
-
subscribe<T>(query?:
|
|
304
|
+
subscribe<T>(query?: QueryInput, options?: SubscribeOptions): AsyncGenerator<SubscriptionEvent<T>>;
|
|
304
305
|
/**
|
|
305
306
|
* Collect all documents matching the optional query into an array.
|
|
306
307
|
* @param query - filter or `Query` object
|
|
@@ -310,7 +311,7 @@ export declare class Bucket {
|
|
|
310
311
|
* const docs = bucket.all<{ name: string }>(where('name', { $exists: true }));
|
|
311
312
|
* ```
|
|
312
313
|
*/
|
|
313
|
-
all<T>(query?:
|
|
314
|
+
all<T>(query?: QueryInput): Array<T>;
|
|
314
315
|
/**
|
|
315
316
|
* Return the first document matching the optional query, or `null`
|
|
316
317
|
* when no document matches.
|
|
@@ -321,7 +322,7 @@ export declare class Bucket {
|
|
|
321
322
|
* const doc = bucket.one<{ _id: number }>(where('_id', { $eq: 1 }));
|
|
322
323
|
* ```
|
|
323
324
|
*/
|
|
324
|
-
one<T>(query?:
|
|
325
|
+
one<T>(query?: QueryInput): T | null;
|
|
325
326
|
/**
|
|
326
327
|
* Normalize a query argument to a plain object, unpacking
|
|
327
328
|
* `Query` instances.
|
|
@@ -331,7 +332,7 @@ export declare class Bucket {
|
|
|
331
332
|
* Bucket.convertToQuery({ foo: { $exists: true } });
|
|
332
333
|
* ```
|
|
333
334
|
*/
|
|
334
|
-
static convertToQuery(query?:
|
|
335
|
+
static convertToQuery(query?: QueryInput): object;
|
|
335
336
|
/**
|
|
336
337
|
* Generator that allows reading and optionally modifying each
|
|
337
338
|
* document matching the query.
|
|
@@ -348,7 +349,7 @@ export declare class Bucket {
|
|
|
348
349
|
* }
|
|
349
350
|
* ```
|
|
350
351
|
*/
|
|
351
|
-
transformIterator<T extends object>(query?:
|
|
352
|
+
transformIterator<T extends object>(query?: QueryInput): Generator<T, undefined, TransformReplacement<T>>;
|
|
352
353
|
/**
|
|
353
354
|
* Apply a transformation function to each document matching the
|
|
354
355
|
* provided query. The predicate receives the current document and
|
|
@@ -367,11 +368,11 @@ export declare class Bucket {
|
|
|
367
368
|
* });
|
|
368
369
|
* ```
|
|
369
370
|
*/
|
|
370
|
-
transform<T extends object>(query:
|
|
371
|
+
transform<T extends object>(query: QueryInput | undefined, fn: (doc: T) => TransformReplacement<T>): void;
|
|
371
372
|
/**
|
|
372
373
|
* Alias for `transform` that reads more naturally for document updates.
|
|
373
374
|
*/
|
|
374
|
-
update<T extends object>(query:
|
|
375
|
+
update<T extends object>(query: QueryInput | undefined, fn: (doc: T) => TransformReplacement<T>): void;
|
|
375
376
|
replicationCursor(): ReplicationCursor;
|
|
376
377
|
readReplicationBatch(cursor: ReplicationCursor, maxBytes?: number): Uint8Array | null;
|
|
377
378
|
/**
|
|
@@ -384,87 +385,3 @@ export declare class Bucket {
|
|
|
384
385
|
*/
|
|
385
386
|
applyReplicationBatch(data: Uint8Array): ReplicationCursor;
|
|
386
387
|
}
|
|
387
|
-
type BSONValue = any;
|
|
388
|
-
type FilterOperators = {
|
|
389
|
-
$eq: BSONValue;
|
|
390
|
-
} | BSONValue | {
|
|
391
|
-
$ne: BSONValue;
|
|
392
|
-
} | {
|
|
393
|
-
$lt: BSONValue;
|
|
394
|
-
} | {
|
|
395
|
-
$lte: BSONValue;
|
|
396
|
-
} | {
|
|
397
|
-
$gt: BSONValue;
|
|
398
|
-
} | {
|
|
399
|
-
$gte: BSONValue;
|
|
400
|
-
} | {
|
|
401
|
-
$in: BSONValue[];
|
|
402
|
-
} | {
|
|
403
|
-
$between: [BSONValue, BSONValue];
|
|
404
|
-
} | {
|
|
405
|
-
$startsWith: string;
|
|
406
|
-
} | {
|
|
407
|
-
$endsWith: string;
|
|
408
|
-
} | {
|
|
409
|
-
$exists: boolean;
|
|
410
|
-
} | {
|
|
411
|
-
$notExists: boolean;
|
|
412
|
-
};
|
|
413
|
-
/**
|
|
414
|
-
* Builder for query objects that can be used with bucket
|
|
415
|
-
* operations like `list`, `delete`, and `transform`.
|
|
416
|
-
*
|
|
417
|
-
* The class supports chaining to construct filters, sorting,
|
|
418
|
-
* and pagination (offset/limit).
|
|
419
|
-
*/
|
|
420
|
-
export declare class Query {
|
|
421
|
-
private _query;
|
|
422
|
-
/**
|
|
423
|
-
* Return the raw query object to pass to the native layer.
|
|
424
|
-
*/
|
|
425
|
-
get query(): object;
|
|
426
|
-
/**
|
|
427
|
-
* Add a filter condition for the specified field.
|
|
428
|
-
* @param field - dot-separated path to the document field
|
|
429
|
-
* @param filter - comparison operator object
|
|
430
|
-
* @returns the same `Query` for chaining
|
|
431
|
-
* @example
|
|
432
|
-
* ```ts
|
|
433
|
-
* const q = new Query().where('age', { $gt: 18 });
|
|
434
|
-
* ```
|
|
435
|
-
*/
|
|
436
|
-
where(field: string, filter: FilterOperators): this;
|
|
437
|
-
/**
|
|
438
|
-
* Specify sorting for the result set.
|
|
439
|
-
* @param field - field to sort by
|
|
440
|
-
* @param direction - `asc` or `desc` (defaults to `asc`)
|
|
441
|
-
* @example
|
|
442
|
-
* ```ts
|
|
443
|
-
* const q = new Query().sortBy('name', 'desc');
|
|
444
|
-
* ```
|
|
445
|
-
*/
|
|
446
|
-
sortBy(field: string, direction?: "asc" | "desc"): this;
|
|
447
|
-
/**
|
|
448
|
-
* Set an offset and limit for pagination.
|
|
449
|
-
* @param offset - number of documents to skip
|
|
450
|
-
* @param limit - maximum number of documents to return
|
|
451
|
-
* @example
|
|
452
|
-
* ```ts
|
|
453
|
-
* const q = new Query().sector(10, 5);
|
|
454
|
-
* ```
|
|
455
|
-
*/
|
|
456
|
-
sector(offset?: number, limit?: number): this;
|
|
457
|
-
}
|
|
458
|
-
/**
|
|
459
|
-
* Shortcut helper that creates a new `Query` with a single
|
|
460
|
-
* `where` clause applied.
|
|
461
|
-
*
|
|
462
|
-
* @param field - field name to filter on
|
|
463
|
-
* @param filter - filter operator object
|
|
464
|
-
* @returns a `Query` instance ready to use
|
|
465
|
-
* @example
|
|
466
|
-
* ```ts
|
|
467
|
-
* bucket.list(where('age', { $lt: 30 }));
|
|
468
|
-
* ```
|
|
469
|
-
*/
|
|
470
|
-
export declare function where(field: string, filter: FilterOperators): Query;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.where = where;
|
|
17
|
+
exports.Bucket = exports.Transaction = exports.ObjectId = exports.BSON = exports.albedo = void 0;
|
|
5
18
|
const detect_libc_1 = require("detect-libc");
|
|
19
|
+
const query_1 = require("./query");
|
|
20
|
+
__exportStar(require("./query"), exports);
|
|
6
21
|
function getNativeBinding() {
|
|
7
22
|
const platformMap = {
|
|
8
23
|
win32: "windows",
|
|
@@ -48,7 +63,7 @@ exports.BSON = {
|
|
|
48
63
|
*/
|
|
49
64
|
exports.ObjectId = exports.albedo.ObjectId;
|
|
50
65
|
function convertToQuery(query) {
|
|
51
|
-
if (query instanceof Query) {
|
|
66
|
+
if (query instanceof query_1.Query) {
|
|
52
67
|
return query.query;
|
|
53
68
|
}
|
|
54
69
|
return query || {};
|
|
@@ -379,6 +394,7 @@ class Bucket {
|
|
|
379
394
|
try {
|
|
380
395
|
while (true) {
|
|
381
396
|
const batch = exports.albedo.subscribePoll(subscription, batchSize);
|
|
397
|
+
console.log("Polled subscription, got batch:", batch);
|
|
382
398
|
if (batch !== null) {
|
|
383
399
|
for (const event of batch.batch) {
|
|
384
400
|
yield event;
|
|
@@ -498,78 +514,3 @@ class Bucket {
|
|
|
498
514
|
}
|
|
499
515
|
}
|
|
500
516
|
exports.Bucket = Bucket;
|
|
501
|
-
/**
|
|
502
|
-
* Builder for query objects that can be used with bucket
|
|
503
|
-
* operations like `list`, `delete`, and `transform`.
|
|
504
|
-
*
|
|
505
|
-
* The class supports chaining to construct filters, sorting,
|
|
506
|
-
* and pagination (offset/limit).
|
|
507
|
-
*/
|
|
508
|
-
class Query {
|
|
509
|
-
_query = {};
|
|
510
|
-
/**
|
|
511
|
-
* Return the raw query object to pass to the native layer.
|
|
512
|
-
*/
|
|
513
|
-
get query() {
|
|
514
|
-
return this._query;
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Add a filter condition for the specified field.
|
|
518
|
-
* @param field - dot-separated path to the document field
|
|
519
|
-
* @param filter - comparison operator object
|
|
520
|
-
* @returns the same `Query` for chaining
|
|
521
|
-
* @example
|
|
522
|
-
* ```ts
|
|
523
|
-
* const q = new Query().where('age', { $gt: 18 });
|
|
524
|
-
* ```
|
|
525
|
-
*/
|
|
526
|
-
where(field, filter) {
|
|
527
|
-
if (!this._query.query) {
|
|
528
|
-
this._query.query = {};
|
|
529
|
-
}
|
|
530
|
-
this._query.query[field] = filter;
|
|
531
|
-
return this;
|
|
532
|
-
}
|
|
533
|
-
/**
|
|
534
|
-
* Specify sorting for the result set.
|
|
535
|
-
* @param field - field to sort by
|
|
536
|
-
* @param direction - `asc` or `desc` (defaults to `asc`)
|
|
537
|
-
* @example
|
|
538
|
-
* ```ts
|
|
539
|
-
* const q = new Query().sortBy('name', 'desc');
|
|
540
|
-
* ```
|
|
541
|
-
*/
|
|
542
|
-
sortBy(field, direction = "asc") {
|
|
543
|
-
this._query.sort = direction === "asc" ? { asc: field } : { desc: field };
|
|
544
|
-
return this;
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* Set an offset and limit for pagination.
|
|
548
|
-
* @param offset - number of documents to skip
|
|
549
|
-
* @param limit - maximum number of documents to return
|
|
550
|
-
* @example
|
|
551
|
-
* ```ts
|
|
552
|
-
* const q = new Query().sector(10, 5);
|
|
553
|
-
* ```
|
|
554
|
-
*/
|
|
555
|
-
sector(offset, limit) {
|
|
556
|
-
this._query.sector = { offset, limit };
|
|
557
|
-
return this;
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
exports.Query = Query;
|
|
561
|
-
/**
|
|
562
|
-
* Shortcut helper that creates a new `Query` with a single
|
|
563
|
-
* `where` clause applied.
|
|
564
|
-
*
|
|
565
|
-
* @param field - field name to filter on
|
|
566
|
-
* @param filter - filter operator object
|
|
567
|
-
* @returns a `Query` instance ready to use
|
|
568
|
-
* @example
|
|
569
|
-
* ```ts
|
|
570
|
-
* bucket.list(where('age', { $lt: 30 }));
|
|
571
|
-
* ```
|
|
572
|
-
*/
|
|
573
|
-
function where(field, filter) {
|
|
574
|
-
return new Query().where(field, filter);
|
|
575
|
-
}
|
package/dist/query.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
type BSONValue = any;
|
|
2
|
+
export type FilterOperators = {
|
|
3
|
+
$eq: BSONValue;
|
|
4
|
+
} | BSONValue | {
|
|
5
|
+
$ne: BSONValue;
|
|
6
|
+
} | {
|
|
7
|
+
$lt: BSONValue;
|
|
8
|
+
} | {
|
|
9
|
+
$lte: BSONValue;
|
|
10
|
+
} | {
|
|
11
|
+
$gt: BSONValue;
|
|
12
|
+
} | {
|
|
13
|
+
$gte: BSONValue;
|
|
14
|
+
} | {
|
|
15
|
+
$in: BSONValue[];
|
|
16
|
+
} | {
|
|
17
|
+
$between: [BSONValue, BSONValue];
|
|
18
|
+
} | {
|
|
19
|
+
$startsWith: string;
|
|
20
|
+
} | {
|
|
21
|
+
$endsWith: string;
|
|
22
|
+
} | {
|
|
23
|
+
$exists: boolean;
|
|
24
|
+
} | {
|
|
25
|
+
$notExists: boolean;
|
|
26
|
+
};
|
|
27
|
+
export interface QueryClause {
|
|
28
|
+
$or?: QueryClause[];
|
|
29
|
+
$and?: QueryClause[];
|
|
30
|
+
$nor?: QueryClause[];
|
|
31
|
+
[field: string]: FilterOperators | QueryClause[] | undefined;
|
|
32
|
+
}
|
|
33
|
+
export type QuerySort = {
|
|
34
|
+
asc: string;
|
|
35
|
+
} | {
|
|
36
|
+
desc: string;
|
|
37
|
+
};
|
|
38
|
+
export interface QuerySector {
|
|
39
|
+
offset?: number;
|
|
40
|
+
limit?: number;
|
|
41
|
+
}
|
|
42
|
+
export interface QueryObject {
|
|
43
|
+
query?: QueryClause;
|
|
44
|
+
sort?: QuerySort;
|
|
45
|
+
sector?: QuerySector;
|
|
46
|
+
projection?: {
|
|
47
|
+
omit: string[];
|
|
48
|
+
} | {
|
|
49
|
+
pick: string[];
|
|
50
|
+
};
|
|
51
|
+
cursor?: Record<string, unknown>;
|
|
52
|
+
}
|
|
53
|
+
export type QueryInput = QueryObject | Query;
|
|
54
|
+
export type QueryClauseInput = QueryClause | Query;
|
|
55
|
+
/**
|
|
56
|
+
* Builder for query objects that can be used with bucket
|
|
57
|
+
* operations like `list`, `delete`, and `transform`.
|
|
58
|
+
*
|
|
59
|
+
* The class supports chaining to construct filters, sorting,
|
|
60
|
+
* and pagination (offset/limit).
|
|
61
|
+
*/
|
|
62
|
+
export declare class Query {
|
|
63
|
+
private _query;
|
|
64
|
+
static or(...clauses: QueryClauseInput[]): Query;
|
|
65
|
+
static and(...clauses: QueryClauseInput[]): Query;
|
|
66
|
+
static nor(...clauses: QueryClauseInput[]): Query;
|
|
67
|
+
/**
|
|
68
|
+
* Return the raw query object to pass to the native layer.
|
|
69
|
+
*/
|
|
70
|
+
get query(): QueryObject;
|
|
71
|
+
/**
|
|
72
|
+
* Add a filter condition for the specified field.
|
|
73
|
+
* @param field - dot-separated path to the document field
|
|
74
|
+
* @param filter - comparison operator object
|
|
75
|
+
* @returns the same `Query` for chaining
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* const q = new Query().where('age', { $gt: 18 });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
where(field: string, filter: FilterOperators): this;
|
|
82
|
+
/**
|
|
83
|
+
* Add an `$or` clause to the query.
|
|
84
|
+
* @param clauses - query groups where at least one must match
|
|
85
|
+
*/
|
|
86
|
+
or(...clauses: QueryClauseInput[]): this;
|
|
87
|
+
/**
|
|
88
|
+
* Add an `$and` clause to the query.
|
|
89
|
+
* @param clauses - query groups where all must match
|
|
90
|
+
*/
|
|
91
|
+
and(...clauses: QueryClauseInput[]): this;
|
|
92
|
+
/**
|
|
93
|
+
* Add a `$nor` clause to the query.
|
|
94
|
+
* @param clauses - query groups where none may match
|
|
95
|
+
*/
|
|
96
|
+
nor(...clauses: QueryClauseInput[]): this;
|
|
97
|
+
/**
|
|
98
|
+
* Specify sorting for the result set.
|
|
99
|
+
* @param field - field to sort by
|
|
100
|
+
* @param direction - `asc` or `desc` (defaults to `asc`)
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* const q = new Query().sortBy('name', 'desc');
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
sortBy(field: string, direction?: "asc" | "desc"): this;
|
|
107
|
+
/**
|
|
108
|
+
* Set an offset and limit for pagination.
|
|
109
|
+
* @param offset - number of documents to skip
|
|
110
|
+
* @param limit - maximum number of documents to return
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const q = new Query().sector(10, 5);
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
sector(offset?: number, limit?: number): this;
|
|
117
|
+
private addLogicalClause;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Shortcut helper that creates a new `Query` with a single
|
|
121
|
+
* `where` clause applied.
|
|
122
|
+
*
|
|
123
|
+
* @param field - field name to filter on
|
|
124
|
+
* @param filter - filter operator object
|
|
125
|
+
* @returns a `Query` instance ready to use
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* bucket.list(where('age', { $lt: 30 }));
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export declare function where(field: string, filter: FilterOperators): Query;
|
|
132
|
+
export {};
|
package/dist/query.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Query = void 0;
|
|
4
|
+
exports.where = where;
|
|
5
|
+
function isQuery(value) {
|
|
6
|
+
return value instanceof Query;
|
|
7
|
+
}
|
|
8
|
+
function toClause(value) {
|
|
9
|
+
if (isQuery(value)) {
|
|
10
|
+
return value.query.query ?? {};
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Builder for query objects that can be used with bucket
|
|
16
|
+
* operations like `list`, `delete`, and `transform`.
|
|
17
|
+
*
|
|
18
|
+
* The class supports chaining to construct filters, sorting,
|
|
19
|
+
* and pagination (offset/limit).
|
|
20
|
+
*/
|
|
21
|
+
class Query {
|
|
22
|
+
_query = {};
|
|
23
|
+
static or(...clauses) {
|
|
24
|
+
return new Query().or(...clauses);
|
|
25
|
+
}
|
|
26
|
+
static and(...clauses) {
|
|
27
|
+
return new Query().and(...clauses);
|
|
28
|
+
}
|
|
29
|
+
static nor(...clauses) {
|
|
30
|
+
return new Query().nor(...clauses);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Return the raw query object to pass to the native layer.
|
|
34
|
+
*/
|
|
35
|
+
get query() {
|
|
36
|
+
return this._query;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Add a filter condition for the specified field.
|
|
40
|
+
* @param field - dot-separated path to the document field
|
|
41
|
+
* @param filter - comparison operator object
|
|
42
|
+
* @returns the same `Query` for chaining
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const q = new Query().where('age', { $gt: 18 });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
where(field, filter) {
|
|
49
|
+
if (!this._query.query) {
|
|
50
|
+
this._query.query = {};
|
|
51
|
+
}
|
|
52
|
+
this._query.query[field] = filter;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Add an `$or` clause to the query.
|
|
57
|
+
* @param clauses - query groups where at least one must match
|
|
58
|
+
*/
|
|
59
|
+
or(...clauses) {
|
|
60
|
+
return this.addLogicalClause("$or", clauses);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Add an `$and` clause to the query.
|
|
64
|
+
* @param clauses - query groups where all must match
|
|
65
|
+
*/
|
|
66
|
+
and(...clauses) {
|
|
67
|
+
return this.addLogicalClause("$and", clauses);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Add a `$nor` clause to the query.
|
|
71
|
+
* @param clauses - query groups where none may match
|
|
72
|
+
*/
|
|
73
|
+
nor(...clauses) {
|
|
74
|
+
return this.addLogicalClause("$nor", clauses);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Specify sorting for the result set.
|
|
78
|
+
* @param field - field to sort by
|
|
79
|
+
* @param direction - `asc` or `desc` (defaults to `asc`)
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const q = new Query().sortBy('name', 'desc');
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
sortBy(field, direction = "asc") {
|
|
86
|
+
this._query.sort = direction === "asc" ? { asc: field } : { desc: field };
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Set an offset and limit for pagination.
|
|
91
|
+
* @param offset - number of documents to skip
|
|
92
|
+
* @param limit - maximum number of documents to return
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* const q = new Query().sector(10, 5);
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
sector(offset, limit) {
|
|
99
|
+
this._query.sector = { offset, limit };
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
addLogicalClause(operator, clauses) {
|
|
103
|
+
if (!this._query.query) {
|
|
104
|
+
this._query.query = {};
|
|
105
|
+
}
|
|
106
|
+
this._query.query[operator] = clauses.map(toClause);
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.Query = Query;
|
|
111
|
+
/**
|
|
112
|
+
* Shortcut helper that creates a new `Query` with a single
|
|
113
|
+
* `where` clause applied.
|
|
114
|
+
*
|
|
115
|
+
* @param field - field name to filter on
|
|
116
|
+
* @param filter - filter operator object
|
|
117
|
+
* @returns a `Query` instance ready to use
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* bucket.list(where('age', { $lt: 30 }));
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
function where(field, filter) {
|
|
124
|
+
return new Query().where(field, filter);
|
|
125
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "albedo-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "High-performance embedded database for Node.js with native bindings, BSON support, indexing, and replication",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"albedo",
|
|
@@ -35,4 +35,4 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"detect-libc": "^2.1.2"
|
|
37
37
|
}
|
|
38
|
-
}
|
|
38
|
+
}
|
package/scripts/publish.ts
CHANGED
|
@@ -18,7 +18,9 @@ async function main() {
|
|
|
18
18
|
const buildRes = await $`bun run build`;
|
|
19
19
|
if (buildRes.exitCode !== 0) throw new Error("build failed");
|
|
20
20
|
|
|
21
|
-
const tmp = fs.mkdtempSync(
|
|
21
|
+
const tmp = fs.mkdtempSync(
|
|
22
|
+
path.join(os.tmpdir(), `${name.replace("/", "-")}-`),
|
|
23
|
+
);
|
|
22
24
|
console.log(`đĻ Preparing publish directory: ${tmp}`);
|
|
23
25
|
|
|
24
26
|
function copyOrFail(rel: string) {
|
|
@@ -41,17 +43,24 @@ async function main() {
|
|
|
41
43
|
const publishPkg = { ...pkg } as Record<string, any>;
|
|
42
44
|
delete publishPkg.devDependencies;
|
|
43
45
|
delete publishPkg.scripts;
|
|
44
|
-
publishPkg.files = Array.from(
|
|
46
|
+
publishPkg.files = Array.from(
|
|
47
|
+
new Set([...(publishPkg.files || []), "dist", "native"]),
|
|
48
|
+
);
|
|
45
49
|
if (publishPkg.private) delete publishPkg.private;
|
|
46
50
|
|
|
47
|
-
fs.writeFileSync(
|
|
51
|
+
fs.writeFileSync(
|
|
52
|
+
path.join(tmp, "package.json"),
|
|
53
|
+
JSON.stringify(publishPkg, null, 2) + "\n",
|
|
54
|
+
);
|
|
48
55
|
|
|
49
56
|
console.log("đ Files staged for publish:");
|
|
50
57
|
const lsRes = await $`ls -1`.cwd(tmp);
|
|
51
58
|
if (lsRes.exitCode === 0) console.log(String(lsRes.stdout || "").trim());
|
|
52
59
|
|
|
53
60
|
if (dry) {
|
|
54
|
-
console.log(
|
|
61
|
+
console.log(
|
|
62
|
+
"â ī¸ Dry run â skipping npm publish. Use --no-dry-run to actually publish.",
|
|
63
|
+
);
|
|
55
64
|
} else {
|
|
56
65
|
const packOnly = process.argv.includes("--pack-only");
|
|
57
66
|
|
|
@@ -61,9 +70,12 @@ async function main() {
|
|
|
61
70
|
console.error(String(packRes.stderr || packRes.stdout || ""));
|
|
62
71
|
throw new Error(`bun pm pack failed (${packRes.exitCode})`);
|
|
63
72
|
}
|
|
64
|
-
console.log("â
Package tarball created:", packRes.stdout.toString(
|
|
73
|
+
console.log("â
Package tarball created:", packRes.stdout.toString("utf8"));
|
|
65
74
|
|
|
66
|
-
const tarballName = String(packRes.stdout || packRes.stderr || "")
|
|
75
|
+
const tarballName = String(packRes.stdout || packRes.stderr || "")
|
|
76
|
+
.trim()
|
|
77
|
+
.split(/\r?\n/)
|
|
78
|
+
.pop();
|
|
67
79
|
const tarballPath = path.join(tmp, tarballName || "package.tgz");
|
|
68
80
|
console.log(`đĻ Packaged: ${tarballPath}`);
|
|
69
81
|
|
|
@@ -71,7 +83,8 @@ async function main() {
|
|
|
71
83
|
console.log("âšī¸ --pack-only provided; skipping publish.");
|
|
72
84
|
} else {
|
|
73
85
|
console.log("âĄī¸ Publishing tarball with bun publish...");
|
|
74
|
-
const publishRes =
|
|
86
|
+
const publishRes =
|
|
87
|
+
await $`npm publish --access public ${tarballPath}`.cwd(root);
|
|
75
88
|
if (publishRes.exitCode !== 0) {
|
|
76
89
|
console.error(String(publishRes.stderr || publishRes.stdout || ""));
|
|
77
90
|
throw new Error(`bun publish failed (${publishRes.exitCode})`);
|