@jsondb-cloud/cli 1.0.0 → 1.0.10

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.
@@ -0,0 +1,82 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.getSchemaCommand = getSchemaCommand;
37
+ exports.setSchemaCommand = setSchemaCommand;
38
+ exports.removeSchemaCommand = removeSchemaCommand;
39
+ const fs = __importStar(require("fs"));
40
+ const output_1 = require("../lib/output");
41
+ async function getSchemaCommand(collection, client) {
42
+ const res = await client.get(`${collection}/_schema`);
43
+ if (!res.ok) {
44
+ if (res.status === 404) {
45
+ console.log(`No schema set for collection '${collection}'`);
46
+ return;
47
+ }
48
+ (0, output_1.error)(`Failed to get schema: ${res.status}`);
49
+ process.exit(1);
50
+ }
51
+ const data = await res.json();
52
+ (0, output_1.printJson)(data.schema || data);
53
+ }
54
+ async function setSchemaCommand(collection, client, options) {
55
+ let schema;
56
+ if (options.file) {
57
+ const content = fs.readFileSync(options.file, "utf-8");
58
+ schema = JSON.parse(content);
59
+ }
60
+ else {
61
+ const chunks = [];
62
+ for await (const chunk of process.stdin) {
63
+ chunks.push(chunk);
64
+ }
65
+ schema = JSON.parse(Buffer.concat(chunks).toString("utf-8"));
66
+ }
67
+ const res = await client.put(`${collection}/_schema`, schema);
68
+ if (!res.ok) {
69
+ const data = await res.json().catch(() => ({}));
70
+ (0, output_1.error)(data.error?.message || `Failed to set schema: ${res.status}`);
71
+ process.exit(1);
72
+ }
73
+ (0, output_1.success)(`Schema set for collection '${collection}'`);
74
+ }
75
+ async function removeSchemaCommand(collection, client) {
76
+ const res = await client.delete(`${collection}/_schema`);
77
+ if (!res.ok) {
78
+ (0, output_1.error)(`Failed to remove schema: ${res.status}`);
79
+ process.exit(1);
80
+ }
81
+ (0, output_1.success)(`Schema removed from collection '${collection}'`);
82
+ }
@@ -0,0 +1,8 @@
1
+ import { ApiClient } from "../lib/client";
2
+ export declare function listVersionsCommand(collection: string, docId: string, client: ApiClient): Promise<void>;
3
+ export declare function getVersionCommand(collection: string, docId: string, version: string, client: ApiClient): Promise<void>;
4
+ export declare function diffVersionsCommand(collection: string, docId: string, client: ApiClient, options: {
5
+ from: string;
6
+ to: string;
7
+ }): Promise<void>;
8
+ export declare function restoreVersionCommand(collection: string, docId: string, version: string, client: ApiClient): Promise<void>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listVersionsCommand = listVersionsCommand;
4
+ exports.getVersionCommand = getVersionCommand;
5
+ exports.diffVersionsCommand = diffVersionsCommand;
6
+ exports.restoreVersionCommand = restoreVersionCommand;
7
+ const output_1 = require("../lib/output");
8
+ async function listVersionsCommand(collection, docId, client) {
9
+ const res = await client.get(`${collection}/${docId}/versions`);
10
+ if (!res.ok) {
11
+ const data = await res.json().catch(() => ({}));
12
+ (0, output_1.error)(data.error?.message || `Failed to list versions: ${res.status}`);
13
+ process.exit(1);
14
+ }
15
+ const data = await res.json();
16
+ const versions = data.versions || data.data || data;
17
+ if (Array.isArray(versions) && versions.length > 0) {
18
+ (0, output_1.printTable)(["Version", "Action", "Timestamp", "Size"], versions.map((v) => [
19
+ String(v.version),
20
+ v.action || "",
21
+ v.timestamp || "",
22
+ v.size != null ? String(v.size) : "",
23
+ ]));
24
+ }
25
+ else {
26
+ console.log("No versions found.");
27
+ }
28
+ }
29
+ async function getVersionCommand(collection, docId, version, client) {
30
+ const res = await client.get(`${collection}/${docId}/versions/${version}`);
31
+ if (!res.ok) {
32
+ const data = await res.json().catch(() => ({}));
33
+ (0, output_1.error)(data.error?.message || `Failed to get version: ${res.status}`);
34
+ process.exit(1);
35
+ }
36
+ const doc = await res.json();
37
+ (0, output_1.printJson)(doc);
38
+ }
39
+ async function diffVersionsCommand(collection, docId, client, options) {
40
+ if (!options.from || !options.to) {
41
+ (0, output_1.error)("Both --from and --to version numbers are required");
42
+ process.exit(1);
43
+ }
44
+ const res = await client.get(`${collection}/${docId}/versions/diff?from=${options.from}&to=${options.to}`);
45
+ if (!res.ok) {
46
+ const data = await res.json().catch(() => ({}));
47
+ (0, output_1.error)(data.error?.message || `Failed to diff versions: ${res.status}`);
48
+ process.exit(1);
49
+ }
50
+ const diff = await res.json();
51
+ (0, output_1.printJson)(diff);
52
+ }
53
+ async function restoreVersionCommand(collection, docId, version, client) {
54
+ const res = await client.post(`${collection}/${docId}/versions/${version}/restore`);
55
+ if (!res.ok) {
56
+ const data = await res.json().catch(() => ({}));
57
+ (0, output_1.error)(data.error?.message || `Failed to restore version: ${res.status}`);
58
+ process.exit(1);
59
+ }
60
+ const doc = await res.json();
61
+ (0, output_1.success)(`Restored ${docId} to version ${version}`);
62
+ (0, output_1.printJson)(doc);
63
+ }
@@ -0,0 +1,17 @@
1
+ import { ApiClient } from "../lib/client";
2
+ export declare function listWebhooksCommand(collection: string, client: ApiClient): Promise<void>;
3
+ export declare function createWebhookCommand(collection: string, client: ApiClient, options: {
4
+ url: string;
5
+ events: string;
6
+ description?: string;
7
+ secret?: string;
8
+ }): Promise<void>;
9
+ export declare function getWebhookCommand(collection: string, webhookId: string, client: ApiClient): Promise<void>;
10
+ export declare function updateWebhookCommand(collection: string, webhookId: string, client: ApiClient, options: {
11
+ url?: string;
12
+ events?: string;
13
+ description?: string;
14
+ status?: string;
15
+ }): Promise<void>;
16
+ export declare function deleteWebhookCommand(collection: string, webhookId: string, client: ApiClient): Promise<void>;
17
+ export declare function testWebhookCommand(collection: string, webhookId: string, client: ApiClient): Promise<void>;
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listWebhooksCommand = listWebhooksCommand;
4
+ exports.createWebhookCommand = createWebhookCommand;
5
+ exports.getWebhookCommand = getWebhookCommand;
6
+ exports.updateWebhookCommand = updateWebhookCommand;
7
+ exports.deleteWebhookCommand = deleteWebhookCommand;
8
+ exports.testWebhookCommand = testWebhookCommand;
9
+ const output_1 = require("../lib/output");
10
+ async function listWebhooksCommand(collection, client) {
11
+ const res = await client.get(`${collection}/_webhooks`);
12
+ if (!res.ok) {
13
+ const data = await res.json().catch(() => ({}));
14
+ (0, output_1.error)(data.error?.message || `Failed to list webhooks: ${res.status}`);
15
+ process.exit(1);
16
+ }
17
+ const data = await res.json();
18
+ const webhooks = data.webhooks || data.data || data;
19
+ if (Array.isArray(webhooks) && webhooks.length > 0) {
20
+ (0, output_1.printTable)(["ID", "URL", "Events", "Status"], webhooks.map((w) => [
21
+ w._id || "",
22
+ w.url || "",
23
+ Array.isArray(w.events) ? w.events.join(", ") : "",
24
+ w.status || "",
25
+ ]));
26
+ }
27
+ else {
28
+ console.log("No webhooks found.");
29
+ }
30
+ }
31
+ async function createWebhookCommand(collection, client, options) {
32
+ const events = options.events.split(",").map((e) => e.trim());
33
+ const body = { url: options.url, events };
34
+ if (options.description)
35
+ body.description = options.description;
36
+ if (options.secret)
37
+ body.secret = options.secret;
38
+ const res = await client.post(`${collection}/_webhooks`, body);
39
+ if (!res.ok) {
40
+ const data = await res.json().catch(() => ({}));
41
+ (0, output_1.error)(data.error?.message || `Failed to create webhook: ${res.status}`);
42
+ process.exit(1);
43
+ }
44
+ const webhook = await res.json();
45
+ (0, output_1.success)(`Created webhook ${webhook._id}`);
46
+ (0, output_1.printJson)(webhook);
47
+ }
48
+ async function getWebhookCommand(collection, webhookId, client) {
49
+ const res = await client.get(`${collection}/_webhooks/${webhookId}`);
50
+ if (!res.ok) {
51
+ const data = await res.json().catch(() => ({}));
52
+ (0, output_1.error)(data.error?.message || `Failed to get webhook: ${res.status}`);
53
+ process.exit(1);
54
+ }
55
+ const webhook = await res.json();
56
+ (0, output_1.printJson)(webhook);
57
+ }
58
+ async function updateWebhookCommand(collection, webhookId, client, options) {
59
+ const body = {};
60
+ if (options.url)
61
+ body.url = options.url;
62
+ if (options.events)
63
+ body.events = options.events.split(",").map((e) => e.trim());
64
+ if (options.description)
65
+ body.description = options.description;
66
+ if (options.status)
67
+ body.status = options.status;
68
+ if (Object.keys(body).length === 0) {
69
+ (0, output_1.error)("No update options provided. Use --url, --events, --description, or --status.");
70
+ process.exit(1);
71
+ }
72
+ const res = await client.put(`${collection}/_webhooks/${webhookId}`, body);
73
+ if (!res.ok) {
74
+ const data = await res.json().catch(() => ({}));
75
+ (0, output_1.error)(data.error?.message || `Failed to update webhook: ${res.status}`);
76
+ process.exit(1);
77
+ }
78
+ const webhook = await res.json();
79
+ (0, output_1.success)(`Updated webhook ${webhookId}`);
80
+ (0, output_1.printJson)(webhook);
81
+ }
82
+ async function deleteWebhookCommand(collection, webhookId, client) {
83
+ const res = await client.delete(`${collection}/_webhooks/${webhookId}`);
84
+ if (!res.ok && res.status !== 204) {
85
+ const data = await res.json().catch(() => ({}));
86
+ (0, output_1.error)(data.error?.message || `Failed to delete webhook: ${res.status}`);
87
+ process.exit(1);
88
+ }
89
+ (0, output_1.success)(`Deleted webhook ${webhookId}`);
90
+ }
91
+ async function testWebhookCommand(collection, webhookId, client) {
92
+ const res = await client.post(`${collection}/_webhooks/${webhookId}/test`);
93
+ if (!res.ok) {
94
+ const data = await res.json().catch(() => ({}));
95
+ (0, output_1.error)(data.error?.message || `Failed to test webhook: ${res.status}`);
96
+ process.exit(1);
97
+ }
98
+ const result = await res.json();
99
+ (0, output_1.success)(`Test event sent for webhook ${webhookId}`);
100
+ (0, output_1.printJson)(result);
101
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,281 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const commander_1 = require("commander");
4
+ const config_1 = require("./lib/config");
5
+ const client_1 = require("./lib/client");
6
+ const output_1 = require("./lib/output");
7
+ const login_1 = require("./commands/login");
8
+ const documents_1 = require("./commands/documents");
9
+ const push_1 = require("./commands/push");
10
+ const pull_1 = require("./commands/pull");
11
+ const keys_1 = require("./commands/keys");
12
+ const schema_1 = require("./commands/schema");
13
+ const versions_1 = require("./commands/versions");
14
+ const webhooks_1 = require("./commands/webhooks");
15
+ const extras_1 = require("./commands/extras");
16
+ const program = new commander_1.Command();
17
+ program
18
+ .name("jsondb")
19
+ .description("The jsondb.cloud CLI — manage your JSON database from the terminal")
20
+ .version("1.0.0")
21
+ .option("--api-key <key>", "Use a specific API key")
22
+ .option("--project <ns>", "Target project (default: \"default\")")
23
+ .option("--base-url <url>", "API base URL")
24
+ .option("--format <fmt>", "Output format: json, raw, ndjson, table");
25
+ function getClient() {
26
+ const opts = program.opts();
27
+ const config = (0, config_1.loadConfig)();
28
+ const apiKey = opts.apiKey || config?.apiKey;
29
+ if (!apiKey) {
30
+ (0, output_1.error)("Not authenticated", "Run `jsondb login` to authenticate, or pass --api-key");
31
+ process.exit(1);
32
+ }
33
+ return new client_1.ApiClient({
34
+ apiKey,
35
+ project: opts.project || config?.project || "default",
36
+ baseUrl: opts.baseUrl || config?.baseUrl || "https://api.jsondb.cloud",
37
+ });
38
+ }
39
+ // ─── Auth commands ───
40
+ program
41
+ .command("login")
42
+ .description("Authenticate with jsondb.cloud")
43
+ .option("--api-key <key>", "API key to use")
44
+ .option("--project <ns>", "Default project")
45
+ .option("--base-url <url>", "API base URL")
46
+ .action(async (opts) => {
47
+ await (0, login_1.loginCommand)(opts);
48
+ });
49
+ program
50
+ .command("logout")
51
+ .description("Remove stored credentials")
52
+ .action(() => {
53
+ (0, config_1.clearConfig)();
54
+ (0, output_1.success)("Logged out. Credentials removed.");
55
+ });
56
+ program
57
+ .command("whoami")
58
+ .description("Show current configuration")
59
+ .action(() => {
60
+ const config = (0, config_1.loadConfig)();
61
+ if (!config) {
62
+ (0, output_1.error)("Not authenticated", "Run `jsondb login` to authenticate");
63
+ process.exit(1);
64
+ }
65
+ console.log(` API Key: ${config.apiKey.slice(0, 16)}...${config.apiKey.slice(-4)}`);
66
+ console.log(` Project: ${config.project}`);
67
+ console.log(` Base URL: ${config.baseUrl}`);
68
+ });
69
+ // ─── Document commands ───
70
+ program
71
+ .command("get <path>")
72
+ .description("Read a document (e.g., users/usr_abc123)")
73
+ .option("--format <fmt>", "Output format: json, raw")
74
+ .action(async (path, opts) => {
75
+ await (0, documents_1.getCommand)(path, getClient(), opts);
76
+ });
77
+ program
78
+ .command("create <collection>")
79
+ .description("Create a document from stdin or file")
80
+ .option("--file <file>", "Read document from file")
81
+ .option("--id <id>", "Explicit document ID")
82
+ .action(async (collection, opts) => {
83
+ await (0, documents_1.createCommand)(collection, getClient(), opts);
84
+ });
85
+ program
86
+ .command("update <path>")
87
+ .description("Replace a document (e.g., users/usr_abc123)")
88
+ .option("--file <file>", "Read document from file")
89
+ .action(async (path, opts) => {
90
+ await (0, documents_1.updateCommand)(path, getClient(), opts);
91
+ });
92
+ program
93
+ .command("patch <path>")
94
+ .description("Partial update a document")
95
+ .option("--file <file>", "Read patch from file")
96
+ .action(async (path, opts) => {
97
+ await (0, documents_1.patchCommand)(path, getClient(), opts);
98
+ });
99
+ program
100
+ .command("delete <path>")
101
+ .description("Delete a document")
102
+ .action(async (path) => {
103
+ await (0, documents_1.deleteCommand)(path, getClient());
104
+ });
105
+ // ─── Collection commands ───
106
+ program
107
+ .command("collections")
108
+ .description("List collections in the project")
109
+ .action(async () => {
110
+ await (0, documents_1.listCollectionsCommand)(getClient());
111
+ });
112
+ program
113
+ .command("documents <collection>")
114
+ .description("List documents in a collection")
115
+ .option("--limit <n>", "Max documents to show")
116
+ .option("--format <fmt>", "Output format: json, raw")
117
+ .action(async (collection, opts) => {
118
+ await (0, documents_1.listDocumentsCommand)(collection, getClient(), opts);
119
+ });
120
+ // ─── Import / Export ───
121
+ program
122
+ .command("push <file>")
123
+ .description("Import documents from JSON/CSV/NDJSON file")
124
+ .requiredOption("--to <collection>", "Target collection")
125
+ .option("--on-conflict <strategy>", "Conflict strategy: fail, skip, overwrite", "fail")
126
+ .action(async (file, opts) => {
127
+ await (0, push_1.pushCommand)(file, getClient(), opts);
128
+ });
129
+ program
130
+ .command("pull <collection>")
131
+ .description("Export documents to stdout or file")
132
+ .option("--out <file>", "Output file path")
133
+ .option("--format <fmt>", "Format: json, csv, ndjson", "json")
134
+ .option("--filter <expr>", "Filter expression (field=value)")
135
+ .action(async (collection, opts) => {
136
+ await (0, pull_1.pullCommand)(collection, getClient(), opts);
137
+ });
138
+ // ─── Key management ───
139
+ const keys = program.command("keys").description("Manage API keys");
140
+ keys
141
+ .command("list")
142
+ .description("List API keys")
143
+ .action(async () => {
144
+ await (0, keys_1.listKeysCommand)(getClient());
145
+ });
146
+ keys
147
+ .command("create")
148
+ .description("Create a new API key")
149
+ .option("--name <name>", "Key name")
150
+ .option("--scope <scope>", "Scope: read-only, read-write", "read-write")
151
+ .option("--project <ns>", "Target project")
152
+ .action(async (opts) => {
153
+ (0, output_1.error)("Key creation requires dashboard authentication. Use the web dashboard at https://jsondb.cloud/dashboard/api-keys");
154
+ process.exit(1);
155
+ });
156
+ keys
157
+ .command("revoke <id>")
158
+ .description("Revoke an API key")
159
+ .action(async (id) => {
160
+ (0, output_1.error)("Key revocation requires dashboard authentication. Use the web dashboard at https://jsondb.cloud/dashboard/api-keys");
161
+ process.exit(1);
162
+ });
163
+ // ─── Schema ───
164
+ const schema = program.command("schema").description("Manage collection schemas");
165
+ schema
166
+ .command("get <collection>")
167
+ .description("Get collection schema")
168
+ .action(async (collection) => {
169
+ await (0, schema_1.getSchemaCommand)(collection, getClient());
170
+ });
171
+ schema
172
+ .command("set <collection>")
173
+ .description("Set collection schema from file or stdin")
174
+ .option("--file <file>", "Schema JSON file")
175
+ .action(async (collection, opts) => {
176
+ await (0, schema_1.setSchemaCommand)(collection, getClient(), opts);
177
+ });
178
+ schema
179
+ .command("remove <collection>")
180
+ .description("Remove collection schema")
181
+ .action(async (collection) => {
182
+ await (0, schema_1.removeSchemaCommand)(collection, getClient());
183
+ });
184
+ // ─── Versions ───
185
+ const versions = program.command("versions").description("Manage document version history");
186
+ versions
187
+ .command("list <collection> <id>")
188
+ .description("List versions of a document")
189
+ .action(async (collection, id) => {
190
+ await (0, versions_1.listVersionsCommand)(collection, id, getClient());
191
+ });
192
+ versions
193
+ .command("get <collection> <id> <version>")
194
+ .description("Get a document at a specific version")
195
+ .action(async (collection, id, version) => {
196
+ await (0, versions_1.getVersionCommand)(collection, id, version, getClient());
197
+ });
198
+ versions
199
+ .command("diff <collection> <id>")
200
+ .description("Diff two versions of a document")
201
+ .requiredOption("--from <version>", "From version number")
202
+ .requiredOption("--to <version>", "To version number")
203
+ .action(async (collection, id, opts) => {
204
+ await (0, versions_1.diffVersionsCommand)(collection, id, getClient(), opts);
205
+ });
206
+ versions
207
+ .command("restore <collection> <id> <version>")
208
+ .description("Restore a document to a specific version")
209
+ .action(async (collection, id, version) => {
210
+ await (0, versions_1.restoreVersionCommand)(collection, id, version, getClient());
211
+ });
212
+ // ─── Webhooks ───
213
+ const webhooks = program.command("webhooks").description("Manage collection webhooks");
214
+ webhooks
215
+ .command("list <collection>")
216
+ .description("List webhooks for a collection")
217
+ .action(async (collection) => {
218
+ await (0, webhooks_1.listWebhooksCommand)(collection, getClient());
219
+ });
220
+ webhooks
221
+ .command("create <collection>")
222
+ .description("Create a webhook")
223
+ .requiredOption("--url <url>", "Webhook endpoint URL")
224
+ .requiredOption("--events <events>", "Comma-separated events (document.created,document.updated,document.deleted)")
225
+ .option("--description <desc>", "Webhook description")
226
+ .option("--secret <secret>", "HMAC signing secret")
227
+ .action(async (collection, opts) => {
228
+ await (0, webhooks_1.createWebhookCommand)(collection, getClient(), opts);
229
+ });
230
+ webhooks
231
+ .command("get <collection> <id>")
232
+ .description("Get webhook details and recent deliveries")
233
+ .action(async (collection, id) => {
234
+ await (0, webhooks_1.getWebhookCommand)(collection, id, getClient());
235
+ });
236
+ webhooks
237
+ .command("update <collection> <id>")
238
+ .description("Update a webhook")
239
+ .option("--url <url>", "New endpoint URL")
240
+ .option("--events <events>", "New comma-separated events")
241
+ .option("--description <desc>", "New description")
242
+ .option("--status <status>", "Status: active or disabled")
243
+ .action(async (collection, id, opts) => {
244
+ await (0, webhooks_1.updateWebhookCommand)(collection, id, getClient(), opts);
245
+ });
246
+ webhooks
247
+ .command("delete <collection> <id>")
248
+ .description("Delete a webhook")
249
+ .action(async (collection, id) => {
250
+ await (0, webhooks_1.deleteWebhookCommand)(collection, id, getClient());
251
+ });
252
+ webhooks
253
+ .command("test <collection> <id>")
254
+ .description("Send a test event to a webhook")
255
+ .action(async (collection, id) => {
256
+ await (0, webhooks_1.testWebhookCommand)(collection, id, getClient());
257
+ });
258
+ // ─── Validate / Count / Bulk ───
259
+ program
260
+ .command("validate <collection>")
261
+ .description("Dry-run schema validation against a document")
262
+ .option("--file <file>", "Read document from file (otherwise reads stdin)")
263
+ .action(async (collection, opts) => {
264
+ await (0, extras_1.validateCommand)(collection, getClient(), opts);
265
+ });
266
+ program
267
+ .command("count <collection>")
268
+ .description("Count documents in a collection")
269
+ .option("--filter <expr...>", "Filter expressions (field=value)")
270
+ .action(async (collection, opts) => {
271
+ await (0, extras_1.countCommand)(collection, getClient(), opts);
272
+ });
273
+ program
274
+ .command("bulk <collection>")
275
+ .description("Execute bulk operations from stdin or file")
276
+ .option("--file <file>", "Read operations from file (otherwise reads stdin)")
277
+ .action(async (collection, opts) => {
278
+ await (0, extras_1.bulkCommand)(collection, getClient(), opts);
279
+ });
280
+ // Parse and execute
281
+ program.parse();
@@ -0,0 +1,15 @@
1
+ import type { CliConfig } from "./config";
2
+ export declare class ApiClient {
3
+ private config;
4
+ constructor(config: CliConfig);
5
+ private url;
6
+ private headers;
7
+ get(path: string, accept?: string): Promise<Response>;
8
+ post(path: string, body?: unknown, extraHeaders?: Record<string, string>): Promise<Response>;
9
+ postRaw(path: string, body: string, contentType: string): Promise<Response>;
10
+ put(path: string, body: unknown): Promise<Response>;
11
+ patch(path: string, body: unknown, contentType?: string): Promise<Response>;
12
+ delete(path: string): Promise<Response>;
13
+ /** Raw API call without project prefix */
14
+ rawGet(fullPath: string): Promise<Response>;
15
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiClient = void 0;
4
+ class ApiClient {
5
+ config;
6
+ constructor(config) {
7
+ this.config = config;
8
+ }
9
+ url(path) {
10
+ const base = this.config.baseUrl.replace(/\/$/, "");
11
+ return `${base}/${this.config.project}/${path}`;
12
+ }
13
+ headers(extra) {
14
+ return {
15
+ Authorization: `Bearer ${this.config.apiKey}`,
16
+ "Content-Type": "application/json",
17
+ ...extra,
18
+ };
19
+ }
20
+ async get(path, accept) {
21
+ const headers = this.headers(accept ? { Accept: accept } : undefined);
22
+ return fetch(this.url(path), { method: "GET", headers });
23
+ }
24
+ async post(path, body, extraHeaders) {
25
+ return fetch(this.url(path), {
26
+ method: "POST",
27
+ headers: this.headers(extraHeaders),
28
+ body: body !== undefined ? JSON.stringify(body) : undefined,
29
+ });
30
+ }
31
+ async postRaw(path, body, contentType) {
32
+ return fetch(this.url(path), {
33
+ method: "POST",
34
+ headers: {
35
+ Authorization: `Bearer ${this.config.apiKey}`,
36
+ "Content-Type": contentType,
37
+ },
38
+ body,
39
+ });
40
+ }
41
+ async put(path, body) {
42
+ return fetch(this.url(path), {
43
+ method: "PUT",
44
+ headers: this.headers(),
45
+ body: JSON.stringify(body),
46
+ });
47
+ }
48
+ async patch(path, body, contentType) {
49
+ return fetch(this.url(path), {
50
+ method: "PATCH",
51
+ headers: this.headers(contentType ? { "Content-Type": contentType } : undefined),
52
+ body: JSON.stringify(body),
53
+ });
54
+ }
55
+ async delete(path) {
56
+ return fetch(this.url(path), {
57
+ method: "DELETE",
58
+ headers: this.headers(),
59
+ });
60
+ }
61
+ /** Raw API call without project prefix */
62
+ async rawGet(fullPath) {
63
+ const base = this.config.baseUrl.replace(/\/$/, "");
64
+ return fetch(`${base}${fullPath}`, {
65
+ method: "GET",
66
+ headers: this.headers(),
67
+ });
68
+ }
69
+ }
70
+ exports.ApiClient = ApiClient;
@@ -0,0 +1,9 @@
1
+ export interface CliConfig {
2
+ apiKey: string;
3
+ project: string;
4
+ baseUrl: string;
5
+ }
6
+ export declare function loadConfig(): CliConfig | null;
7
+ export declare function saveConfig(config: CliConfig): void;
8
+ export declare function clearConfig(): void;
9
+ export declare function getConfigPath(): string;