clefbase 1.3.6 → 1.3.8
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/cli-src/cli/commands/deploy.js +4 -23
- package/dist/cli.js +4 -20
- package/dist/db/batch.d.ts +62 -0
- package/dist/db/batch.d.ts.map +1 -0
- package/dist/db/batch.js +94 -0
- package/dist/db/batch.js.map +1 -0
- package/dist/db/index.d.ts +121 -2
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +198 -3
- package/dist/db/index.js.map +1 -1
- package/dist/db/transaction.d.ts +96 -0
- package/dist/db/transaction.d.ts.map +1 -0
- package/dist/db/transaction.js +130 -0
- package/dist/db/transaction.js.map +1 -0
- package/dist/field_value.d.ts +93 -0
- package/dist/field_value.d.ts.map +1 -0
- package/dist/field_value.js +161 -0
- package/dist/field_value.js.map +1 -0
- package/dist/index.d.ts +30 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -177,29 +177,10 @@ async function runDeploy(opts) {
|
|
|
177
177
|
finSpinner.fail(`Finalize failed: ${err.message}`);
|
|
178
178
|
process.exit(1);
|
|
179
179
|
}
|
|
180
|
-
// ── Result
|
|
181
|
-
// The previewUrl from the config may be stale (e.g. if the site was renamed)
|
|
182
|
-
// and a custom domain may have been added since init. Always fetch the live
|
|
183
|
-
// site record to get the correct canonical URL.
|
|
184
|
-
let canonicalUrl = previewUrl;
|
|
185
|
-
try {
|
|
186
|
-
// Fetch the current site record to get the canonical URL — it may differ
|
|
187
|
-
// from the config if the site was renamed or a custom domain was added.
|
|
188
|
-
const sites = await (0, api_1.listSites)(cfg);
|
|
189
|
-
const liveSite = sites.find(s => s.id === siteId);
|
|
190
|
-
if (liveSite) {
|
|
191
|
-
canonicalUrl = siteUrl(liveSite);
|
|
192
|
-
// Keep the config preview URL in sync for future deploys.
|
|
193
|
-
if (cfg.hosting && liveSite.previewUrl && cfg.hosting.previewUrl !== liveSite.previewUrl) {
|
|
194
|
-
cfg.hosting.previewUrl = liveSite.previewUrl;
|
|
195
|
-
(0, config_1.saveConfig)(cfg, cwd);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
catch { /* best-effort — fall back to stored previewUrl */ }
|
|
180
|
+
// ── Result ────────────────────────────────────────────────────────────────
|
|
200
181
|
console.log();
|
|
201
|
-
if (
|
|
202
|
-
console.log(chalk_1.default.green.bold(` ✓ ${
|
|
182
|
+
if (previewUrl) {
|
|
183
|
+
console.log(chalk_1.default.green.bold(` ✓ ${previewUrl}`));
|
|
203
184
|
}
|
|
204
185
|
console.log();
|
|
205
186
|
}
|
|
@@ -389,7 +370,7 @@ async function createSiteInteractive(cfg) {
|
|
|
389
370
|
while (true) {
|
|
390
371
|
const { name } = await inquirer_1.default.prompt([{
|
|
391
372
|
type: "input", name: "name",
|
|
392
|
-
message: "New site name (used as subdomain, e.g. my-app → my-app.
|
|
373
|
+
message: "New site name (used as subdomain, e.g. my-app → my-app.cleforyx.com)",
|
|
393
374
|
validate: (v) => v.trim().length >= 2 || "Must be at least 2 characters",
|
|
394
375
|
}]);
|
|
395
376
|
const s = (0, ora_1.default)(`Creating "${name.trim()}"…`).start();
|
package/dist/cli.js
CHANGED
|
@@ -34151,9 +34151,6 @@ function fmtBytes(n) {
|
|
|
34151
34151
|
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
|
|
34152
34152
|
return `${(n / (1024 * 1024)).toFixed(2)} MB`;
|
|
34153
34153
|
}
|
|
34154
|
-
function siteUrl(site) {
|
|
34155
|
-
return site.customDomain ? `https://${site.customDomain}` : site.previewUrl;
|
|
34156
|
-
}
|
|
34157
34154
|
async function runDeploy(opts) {
|
|
34158
34155
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
34159
34156
|
const cwd = opts.cwd ?? process.cwd();
|
|
@@ -34252,22 +34249,9 @@ async function runDeploy(opts) {
|
|
|
34252
34249
|
finSpinner.fail(`Finalize failed: ${err.message}`);
|
|
34253
34250
|
process.exit(1);
|
|
34254
34251
|
}
|
|
34255
|
-
let canonicalUrl = previewUrl;
|
|
34256
|
-
try {
|
|
34257
|
-
const sites = await listSites(cfg);
|
|
34258
|
-
const liveSite = sites.find((s) => s.id === siteId);
|
|
34259
|
-
if (liveSite) {
|
|
34260
|
-
canonicalUrl = siteUrl(liveSite);
|
|
34261
|
-
if (cfg.hosting && liveSite.previewUrl && cfg.hosting.previewUrl !== liveSite.previewUrl) {
|
|
34262
|
-
cfg.hosting.previewUrl = liveSite.previewUrl;
|
|
34263
|
-
saveConfig(cfg, cwd);
|
|
34264
|
-
}
|
|
34265
|
-
}
|
|
34266
|
-
} catch {
|
|
34267
|
-
}
|
|
34268
34252
|
console.log();
|
|
34269
|
-
if (
|
|
34270
|
-
console.log(source_default.green.bold(` \u2713 ${
|
|
34253
|
+
if (previewUrl) {
|
|
34254
|
+
console.log(source_default.green.bold(` \u2713 ${previewUrl}`));
|
|
34271
34255
|
}
|
|
34272
34256
|
console.log();
|
|
34273
34257
|
}
|
|
@@ -34442,7 +34426,7 @@ async function createSiteInteractive(cfg) {
|
|
|
34442
34426
|
const { name } = await lib_default.prompt([{
|
|
34443
34427
|
type: "input",
|
|
34444
34428
|
name: "name",
|
|
34445
|
-
message: "New site name (used as subdomain, e.g. my-app \u2192 my-app.
|
|
34429
|
+
message: "New site name (used as subdomain, e.g. my-app \u2192 my-app.cleforyx.com)",
|
|
34446
34430
|
validate: (v) => v.trim().length >= 2 || "Must be at least 2 characters"
|
|
34447
34431
|
}]);
|
|
34448
34432
|
const s = ora2(`Creating "${name.trim()}"\u2026`).start();
|
|
@@ -34539,7 +34523,7 @@ async function runSitesList(cwd = process.cwd()) {
|
|
|
34539
34523
|
}
|
|
34540
34524
|
|
|
34541
34525
|
// package.json
|
|
34542
|
-
var version = "1.3.
|
|
34526
|
+
var version = "1.3.8";
|
|
34543
34527
|
|
|
34544
34528
|
// src/cli/index.ts
|
|
34545
34529
|
var program2 = new Command();
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { HttpClient } from "../http";
|
|
2
|
+
import type { ClefbaseDocument } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Atomic multi-document writer.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const batch = db.batch();
|
|
8
|
+
*
|
|
9
|
+
* // set — full overwrite (no merge)
|
|
10
|
+
* batch.set(db.collection("users").doc("u1"), { name: "Alice", role: "admin" });
|
|
11
|
+
*
|
|
12
|
+
* // update — merge patch (same as doc.update())
|
|
13
|
+
* batch.update(db.collection("posts").doc("p1"), { views: FieldValue.increment(1) });
|
|
14
|
+
*
|
|
15
|
+
* // delete a document
|
|
16
|
+
* batch.delete(db.collection("sessions").doc("s9"));
|
|
17
|
+
*
|
|
18
|
+
* await batch.commit();
|
|
19
|
+
*/
|
|
20
|
+
export declare class WriteBatch {
|
|
21
|
+
private readonly http;
|
|
22
|
+
private readonly _ops;
|
|
23
|
+
private _committed;
|
|
24
|
+
constructor(http: HttpClient);
|
|
25
|
+
/** Number of operations staged so far. */
|
|
26
|
+
get size(): number;
|
|
27
|
+
private _assertNotCommitted;
|
|
28
|
+
/**
|
|
29
|
+
* Stage a full overwrite for the given document reference.
|
|
30
|
+
* Equivalent to `ref.set(data)`.
|
|
31
|
+
*/
|
|
32
|
+
set<T extends ClefbaseDocument>(ref: {
|
|
33
|
+
collectionPath: string;
|
|
34
|
+
id: string;
|
|
35
|
+
}, data: Omit<T, "_id" | "_createdAt" | "_updatedAt">): this;
|
|
36
|
+
/**
|
|
37
|
+
* Stage a merge-patch update for the given document reference.
|
|
38
|
+
* Equivalent to `ref.update(data)`.
|
|
39
|
+
* Supports FieldValue sentinels.
|
|
40
|
+
*/
|
|
41
|
+
update<T extends ClefbaseDocument>(ref: {
|
|
42
|
+
collectionPath: string;
|
|
43
|
+
id: string;
|
|
44
|
+
}, data: Partial<Omit<T, "_id" | "_createdAt" | "_updatedAt">>): this;
|
|
45
|
+
/**
|
|
46
|
+
* Stage a document deletion.
|
|
47
|
+
* Equivalent to `ref.delete()`.
|
|
48
|
+
*/
|
|
49
|
+
delete(ref: {
|
|
50
|
+
collectionPath: string;
|
|
51
|
+
id: string;
|
|
52
|
+
}): this;
|
|
53
|
+
/**
|
|
54
|
+
* Execute all staged operations atomically.
|
|
55
|
+
* After commit() the batch is sealed — calling commit() again throws.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* await batch.commit();
|
|
59
|
+
*/
|
|
60
|
+
commit(): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=batch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../src/db/batch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AA6BjD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,UAAU;IAIT,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;IACtC,OAAO,CAAC,UAAU,CAAS;gBAEE,IAAI,EAAE,UAAU;IAE7C,0CAA0C;IAC1C,IAAI,IAAI,IAAI,MAAM,CAA6B;IAE/C,OAAO,CAAC,mBAAmB;IAM3B;;;OAGG;IACH,GAAG,CAAC,CAAC,SAAS,gBAAgB,EAC5B,GAAG,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAC3C,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,KAAK,GAAG,YAAY,GAAG,YAAY,CAAC,GACjD,IAAI;IAYP;;;;OAIG;IACH,MAAM,CAAC,CAAC,SAAS,gBAAgB,EAC/B,GAAG,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAC3C,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,GAAG,YAAY,GAAG,YAAY,CAAC,CAAC,GAC1D,IAAI;IAYP;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAUzD;;;;;;OAMG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ9B"}
|
package/dist/db/batch.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WriteBatch = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Atomic multi-document writer.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const batch = db.batch();
|
|
9
|
+
*
|
|
10
|
+
* // set — full overwrite (no merge)
|
|
11
|
+
* batch.set(db.collection("users").doc("u1"), { name: "Alice", role: "admin" });
|
|
12
|
+
*
|
|
13
|
+
* // update — merge patch (same as doc.update())
|
|
14
|
+
* batch.update(db.collection("posts").doc("p1"), { views: FieldValue.increment(1) });
|
|
15
|
+
*
|
|
16
|
+
* // delete a document
|
|
17
|
+
* batch.delete(db.collection("sessions").doc("s9"));
|
|
18
|
+
*
|
|
19
|
+
* await batch.commit();
|
|
20
|
+
*/
|
|
21
|
+
class WriteBatch {
|
|
22
|
+
constructor(http) {
|
|
23
|
+
this.http = http;
|
|
24
|
+
this._ops = [];
|
|
25
|
+
this._committed = false;
|
|
26
|
+
}
|
|
27
|
+
/** Number of operations staged so far. */
|
|
28
|
+
get size() { return this._ops.length; }
|
|
29
|
+
_assertNotCommitted() {
|
|
30
|
+
if (this._committed) {
|
|
31
|
+
throw new Error("WriteBatch: cannot add operations after commit()");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Stage a full overwrite for the given document reference.
|
|
36
|
+
* Equivalent to `ref.set(data)`.
|
|
37
|
+
*/
|
|
38
|
+
set(ref, data) {
|
|
39
|
+
this._assertNotCommitted();
|
|
40
|
+
this._ops.push({
|
|
41
|
+
type: "set",
|
|
42
|
+
collectionPath: ref.collectionPath,
|
|
43
|
+
id: ref.id,
|
|
44
|
+
data: data,
|
|
45
|
+
merge: false,
|
|
46
|
+
});
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Stage a merge-patch update for the given document reference.
|
|
51
|
+
* Equivalent to `ref.update(data)`.
|
|
52
|
+
* Supports FieldValue sentinels.
|
|
53
|
+
*/
|
|
54
|
+
update(ref, data) {
|
|
55
|
+
this._assertNotCommitted();
|
|
56
|
+
this._ops.push({
|
|
57
|
+
type: "update",
|
|
58
|
+
collectionPath: ref.collectionPath,
|
|
59
|
+
id: ref.id,
|
|
60
|
+
data: data,
|
|
61
|
+
merge: true,
|
|
62
|
+
});
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Stage a document deletion.
|
|
67
|
+
* Equivalent to `ref.delete()`.
|
|
68
|
+
*/
|
|
69
|
+
delete(ref) {
|
|
70
|
+
this._assertNotCommitted();
|
|
71
|
+
this._ops.push({
|
|
72
|
+
type: "delete",
|
|
73
|
+
collectionPath: ref.collectionPath,
|
|
74
|
+
id: ref.id,
|
|
75
|
+
});
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Execute all staged operations atomically.
|
|
80
|
+
* After commit() the batch is sealed — calling commit() again throws.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* await batch.commit();
|
|
84
|
+
*/
|
|
85
|
+
async commit() {
|
|
86
|
+
this._assertNotCommitted();
|
|
87
|
+
this._committed = true;
|
|
88
|
+
if (this._ops.length === 0)
|
|
89
|
+
return;
|
|
90
|
+
await this.http.post("/batch", { operations: this._ops });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.WriteBatch = WriteBatch;
|
|
94
|
+
//# sourceMappingURL=batch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.js","sourceRoot":"","sources":["../../src/db/batch.ts"],"names":[],"mappings":";;;AA8BA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,UAAU;IAIrB,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;QAH5B,SAAI,GAAc,EAAE,CAAC;QAC9B,eAAU,GAAG,KAAK,CAAC;IAEqB,CAAC;IAEjD,0CAA0C;IAC1C,IAAI,IAAI,KAAa,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAEvC,mBAAmB;QACzB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,GAAG,CACD,GAA2C,EAC3C,IAAkD;QAElD,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC3B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACb,IAAI,EAAY,KAAK;YACrB,cAAc,EAAE,GAAG,CAAC,cAAc;YAClC,EAAE,EAAc,GAAG,CAAC,EAAE;YACtB,IAAI,EAAY,IAA+B;YAC/C,KAAK,EAAW,KAAK;SACtB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,MAAM,CACJ,GAA2C,EAC3C,IAA2D;QAE3D,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC3B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACb,IAAI,EAAY,QAAQ;YACxB,cAAc,EAAE,GAAG,CAAC,cAAc;YAClC,EAAE,EAAc,GAAG,CAAC,EAAE;YACtB,IAAI,EAAY,IAA+B;YAC/C,KAAK,EAAW,IAAI;SACrB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,GAA2C;QAChD,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC3B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACb,IAAI,EAAY,QAAQ;YACxB,cAAc,EAAE,GAAG,CAAC,cAAc;YAClC,EAAE,EAAc,GAAG,CAAC,EAAE;SACvB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,MAAM;QACV,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QAEvB,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAEnC,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5D,CAAC;CACF;AAnFD,gCAmFC"}
|
package/dist/db/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { HttpClient } from "../http";
|
|
2
|
+
import { WriteBatch } from "./batch";
|
|
3
|
+
import { Transaction } from "./transaction";
|
|
2
4
|
import type { ClefbaseDocument, QueryResult, WhereClause } from "../types";
|
|
3
5
|
export type { WhereClause, WhereValue } from "../types";
|
|
6
|
+
export { WriteBatch } from "./batch";
|
|
7
|
+
export { Transaction, runTransaction } from "./transaction";
|
|
4
8
|
/**
|
|
5
9
|
* A typed reference to a single document.
|
|
6
10
|
*
|
|
@@ -16,11 +20,14 @@ export declare class DocumentReference<T extends ClefbaseDocument = ClefbaseDocu
|
|
|
16
20
|
readonly collectionPath: string;
|
|
17
21
|
readonly id: string;
|
|
18
22
|
constructor(http: HttpClient, collectionPath: string, id: string);
|
|
23
|
+
/** Fully-qualified path string, e.g. "posts/p1" or "posts/p1/comments/c1". */
|
|
24
|
+
get path(): string;
|
|
19
25
|
/** Fetch this document. Returns null when it does not exist. */
|
|
20
26
|
get(): Promise<T | null>;
|
|
21
27
|
/**
|
|
22
28
|
* Patch this document (merge by default).
|
|
23
29
|
* Pass `{ merge: false }` to fully replace the document.
|
|
30
|
+
* Supports FieldValue sentinels — they are serialized by JSON.stringify.
|
|
24
31
|
*/
|
|
25
32
|
update(data: Partial<Omit<T, "_id" | "_createdAt" | "_updatedAt">>, opts?: {
|
|
26
33
|
merge?: boolean;
|
|
@@ -39,6 +46,20 @@ export declare class DocumentReference<T extends ClefbaseDocument = ClefbaseDocu
|
|
|
39
46
|
collection<S extends ClefbaseDocument = ClefbaseDocument>(name: string): CollectionReference<S>;
|
|
40
47
|
/** @deprecated Use .collection() — kept for backwards compat */
|
|
41
48
|
subcollection<S extends ClefbaseDocument = ClefbaseDocument>(name: string): CollectionReference<S>;
|
|
49
|
+
/**
|
|
50
|
+
* Subscribe to real-time updates for this document.
|
|
51
|
+
* Returns an unsubscribe function.
|
|
52
|
+
* Requires the server to support SSE at GET /<collection>/<id>/stream.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* const unsub = ref.onSnapshot((doc) => {
|
|
56
|
+
* if (doc) console.log("Updated:", doc);
|
|
57
|
+
* else console.log("Deleted");
|
|
58
|
+
* });
|
|
59
|
+
* // later:
|
|
60
|
+
* unsub();
|
|
61
|
+
*/
|
|
62
|
+
onSnapshot(callback: (doc: T | null) => void, onError?: (err: Error) => void): () => void;
|
|
42
63
|
}
|
|
43
64
|
/**
|
|
44
65
|
* A chainable query builder.
|
|
@@ -65,9 +86,10 @@ export declare class Query<T extends ClefbaseDocument = ClefbaseDocument> {
|
|
|
65
86
|
/**
|
|
66
87
|
* Filter by field values or operators.
|
|
67
88
|
* Multiple calls are AND-merged.
|
|
89
|
+
* Supports dot-notation for nested fields: `where({ "address.city": "London" })`
|
|
68
90
|
*/
|
|
69
91
|
where(clauses: WhereClause): this;
|
|
70
|
-
/** Sort by a field. */
|
|
92
|
+
/** Sort by a field. Supports dot-notation: `orderBy("meta.score", "desc")` */
|
|
71
93
|
orderBy(field: string, dir?: "asc" | "desc"): this;
|
|
72
94
|
/** Cap results (server max: 500). */
|
|
73
95
|
limit(n: number): this;
|
|
@@ -82,6 +104,36 @@ export declare class Query<T extends ClefbaseDocument = ClefbaseDocument> {
|
|
|
82
104
|
get(): Promise<T[]>;
|
|
83
105
|
/** @alias get() */
|
|
84
106
|
getDocs(): Promise<T[]>;
|
|
107
|
+
/**
|
|
108
|
+
* Count matching documents without fetching their data.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* const total = await db.collection("orders").where({ status: "pending" }).count();
|
|
112
|
+
*/
|
|
113
|
+
count(): Promise<number>;
|
|
114
|
+
/**
|
|
115
|
+
* Fetch a single matching document (first result).
|
|
116
|
+
* Returns null when no document matches.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* const admin = await db.collection("users").where({ role: "admin" }).findOne();
|
|
120
|
+
*/
|
|
121
|
+
findOne(): Promise<T | null>;
|
|
122
|
+
/**
|
|
123
|
+
* Iterate over all matching documents in pages, calling `callback` for
|
|
124
|
+
* each page. Useful for large datasets you don't want to load at once.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* await db.collection("logs")
|
|
128
|
+
* .where({ level: "error" })
|
|
129
|
+
* .orderBy("_createdAt")
|
|
130
|
+
* .forEach(async (page) => {
|
|
131
|
+
* for (const doc of page) await process(doc);
|
|
132
|
+
* }, { pageSize: 100 });
|
|
133
|
+
*/
|
|
134
|
+
forEach(callback: (docs: T[]) => Promise<void> | void, opts?: {
|
|
135
|
+
pageSize?: number;
|
|
136
|
+
}): Promise<void>;
|
|
85
137
|
}
|
|
86
138
|
/**
|
|
87
139
|
* A reference to a collection (or subcollection path).
|
|
@@ -107,23 +159,90 @@ export declare class CollectionReference<T extends ClefbaseDocument = ClefbaseDo
|
|
|
107
159
|
offset?: number;
|
|
108
160
|
}): Promise<QueryResult<T>>;
|
|
109
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Query across ALL collections (and subcollections) that share the same name.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* // Find all comments across every post
|
|
167
|
+
* const allComments = await db
|
|
168
|
+
* .collectionGroup("comments")
|
|
169
|
+
* .where({ approved: true })
|
|
170
|
+
* .orderBy("_createdAt", "desc")
|
|
171
|
+
* .limit(50)
|
|
172
|
+
* .getDocs();
|
|
173
|
+
*/
|
|
174
|
+
export declare class CollectionGroup<T extends ClefbaseDocument = ClefbaseDocument> extends Query<T> {
|
|
175
|
+
constructor(http: HttpClient, collectionId: string);
|
|
176
|
+
}
|
|
110
177
|
/**
|
|
111
178
|
* Top-level database service. Obtain via `getDatabase(app)`.
|
|
112
179
|
*
|
|
113
180
|
* @example
|
|
114
181
|
* const db = getDatabase(app);
|
|
182
|
+
*
|
|
183
|
+
* // Document reads / writes
|
|
115
184
|
* const post = await db.collection("posts").doc("p1").get();
|
|
116
|
-
*
|
|
185
|
+
* await db.collection("posts").doc("p1").update({ views: FieldValue.increment(1) });
|
|
186
|
+
*
|
|
187
|
+
* // Atomic batch write
|
|
188
|
+
* const batch = db.batch();
|
|
189
|
+
* batch.update(db.collection("counters").doc("hits"), { n: FieldValue.increment(1) });
|
|
190
|
+
* batch.delete(db.collection("sessions").doc("expired-id"));
|
|
191
|
+
* await batch.commit();
|
|
192
|
+
*
|
|
193
|
+
* // Transaction (read-then-write)
|
|
194
|
+
* await db.runTransaction(async (tx) => {
|
|
195
|
+
* const doc = await tx.get(db.collection("wallets").doc(id));
|
|
196
|
+
* tx.update(db.collection("wallets").doc(id), { balance: (doc?.balance as number ?? 0) + 10 });
|
|
197
|
+
* });
|
|
117
198
|
*/
|
|
118
199
|
export declare class Database {
|
|
119
200
|
private readonly http;
|
|
120
201
|
constructor(http: HttpClient);
|
|
121
202
|
collection<T extends ClefbaseDocument = ClefbaseDocument>(name: string): CollectionReference<T>;
|
|
203
|
+
/**
|
|
204
|
+
* Query across ALL collections that share `collectionId`, regardless of
|
|
205
|
+
* where they are nested in the document tree.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* const allLikes = await db.collectionGroup("likes").where({ userId: uid }).getDocs();
|
|
209
|
+
*/
|
|
210
|
+
collectionGroup<T extends ClefbaseDocument = ClefbaseDocument>(collectionId: string): CollectionGroup<T>;
|
|
122
211
|
getDoc<T extends ClefbaseDocument = ClefbaseDocument>(collectionName: string, id: string): Promise<T | null>;
|
|
123
212
|
addDoc<T extends ClefbaseDocument = ClefbaseDocument>(collectionName: string, data: Omit<T, "_id" | "_createdAt" | "_updatedAt">): Promise<T>;
|
|
124
213
|
updateDoc<T extends ClefbaseDocument = ClefbaseDocument>(collectionName: string, id: string, data: Partial<Omit<T, "_id" | "_createdAt" | "_updatedAt">>, opts?: {
|
|
125
214
|
merge?: boolean;
|
|
126
215
|
}): Promise<T>;
|
|
127
216
|
deleteDoc(collectionName: string, id: string): Promise<void>;
|
|
217
|
+
/**
|
|
218
|
+
* Fetch a document by its full slash-separated path string.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* const comment = await db.doc("posts/p1/comments/c1");
|
|
222
|
+
*/
|
|
223
|
+
doc<T extends ClefbaseDocument = ClefbaseDocument>(path: string): Promise<T | null>;
|
|
224
|
+
/**
|
|
225
|
+
* Create an atomic WriteBatch. Stage operations with `batch.set()`,
|
|
226
|
+
* `batch.update()`, `batch.delete()`, then call `batch.commit()`.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* const batch = db.batch();
|
|
230
|
+
* batch.set(db.collection("users").doc("u1"), { name: "Alice" });
|
|
231
|
+
* batch.update(db.collection("counters").doc("users"), { total: FieldValue.increment(1) });
|
|
232
|
+
* await batch.commit();
|
|
233
|
+
*/
|
|
234
|
+
batch(): WriteBatch;
|
|
235
|
+
/**
|
|
236
|
+
* Execute a transaction — reads are consistent, writes are atomic.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* await db.runTransaction(async (tx) => {
|
|
240
|
+
* const wallet = await tx.get(db.collection("wallets").doc(userId));
|
|
241
|
+
* if ((wallet?.credits as number ?? 0) < cost) throw new Error("Insufficient credits");
|
|
242
|
+
* tx.update(db.collection("wallets").doc(userId), { credits: (wallet!.credits as number) - cost });
|
|
243
|
+
* tx.update(db.collection("items").doc(itemId), { ownerId: userId });
|
|
244
|
+
* });
|
|
245
|
+
*/
|
|
246
|
+
runTransaction<T = void>(updateFn: (tx: Transaction) => Promise<T>): Promise<T>;
|
|
128
247
|
}
|
|
129
248
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/db/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EACV,gBAAgB,EAEhB,WAAW,EACX,WAAW,EACZ,MAAM,UAAU,CAAC;AAElB,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,WAAW,EAAkB,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EACV,gBAAgB,EAEhB,WAAW,EACX,WAAW,EACZ,MAAM,UAAU,CAAC;AAElB,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAI5D;;;;;;;;;GASG;AACH,qBAAa,iBAAiB,CAAC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