@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.
- package/dist/commands/documents.d.ts +20 -0
- package/dist/commands/documents.js +164 -0
- package/dist/commands/extras.d.ts +10 -0
- package/dist/commands/extras.js +108 -0
- package/dist/commands/keys.d.ts +8 -0
- package/dist/commands/keys.js +66 -0
- package/dist/commands/login.d.ts +5 -0
- package/dist/commands/login.js +64 -0
- package/dist/commands/pull.d.ts +6 -0
- package/dist/commands/pull.js +87 -0
- package/dist/commands/push.d.ts +5 -0
- package/dist/commands/push.js +77 -0
- package/dist/commands/schema.d.ts +6 -0
- package/dist/commands/schema.js +82 -0
- package/dist/commands/versions.d.ts +8 -0
- package/dist/commands/versions.js +63 -0
- package/dist/commands/webhooks.d.ts +17 -0
- package/dist/commands/webhooks.js +101 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +281 -0
- package/dist/lib/client.d.ts +15 -0
- package/dist/lib/client.js +70 -0
- package/dist/lib/config.d.ts +9 -0
- package/dist/lib/config.js +79 -0
- package/dist/lib/output.d.ts +5 -0
- package/dist/lib/output.js +54 -0
- package/package.json +16 -6
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ApiClient } from "../lib/client";
|
|
2
|
+
export declare function getCommand(path: string, client: ApiClient, options: {
|
|
3
|
+
format?: string;
|
|
4
|
+
}): Promise<void>;
|
|
5
|
+
export declare function createCommand(collection: string, client: ApiClient, options: {
|
|
6
|
+
file?: string;
|
|
7
|
+
id?: string;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
export declare function updateCommand(path: string, client: ApiClient, options: {
|
|
10
|
+
file?: string;
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
export declare function patchCommand(path: string, client: ApiClient, options: {
|
|
13
|
+
file?: string;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
export declare function deleteCommand(path: string, client: ApiClient): Promise<void>;
|
|
16
|
+
export declare function listCollectionsCommand(client: ApiClient): Promise<void>;
|
|
17
|
+
export declare function listDocumentsCommand(collection: string, client: ApiClient, options: {
|
|
18
|
+
limit?: string;
|
|
19
|
+
format?: string;
|
|
20
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,164 @@
|
|
|
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.getCommand = getCommand;
|
|
37
|
+
exports.createCommand = createCommand;
|
|
38
|
+
exports.updateCommand = updateCommand;
|
|
39
|
+
exports.patchCommand = patchCommand;
|
|
40
|
+
exports.deleteCommand = deleteCommand;
|
|
41
|
+
exports.listCollectionsCommand = listCollectionsCommand;
|
|
42
|
+
exports.listDocumentsCommand = listDocumentsCommand;
|
|
43
|
+
const fs = __importStar(require("fs"));
|
|
44
|
+
const output_1 = require("../lib/output");
|
|
45
|
+
async function getCommand(path, client, options) {
|
|
46
|
+
// path = "collection/docId"
|
|
47
|
+
const res = await client.get(path);
|
|
48
|
+
if (!res.ok) {
|
|
49
|
+
const data = await res.json().catch(() => ({}));
|
|
50
|
+
(0, output_1.error)(data.error?.message || `Request failed with status ${res.status}`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
const doc = await res.json();
|
|
54
|
+
(0, output_1.printJson)(doc, options.format === "raw");
|
|
55
|
+
}
|
|
56
|
+
async function createCommand(collection, client, options) {
|
|
57
|
+
let body;
|
|
58
|
+
if (options.file) {
|
|
59
|
+
const content = fs.readFileSync(options.file, "utf-8");
|
|
60
|
+
body = JSON.parse(content);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// Read from stdin
|
|
64
|
+
const chunks = [];
|
|
65
|
+
for await (const chunk of process.stdin) {
|
|
66
|
+
chunks.push(chunk);
|
|
67
|
+
}
|
|
68
|
+
body = JSON.parse(Buffer.concat(chunks).toString("utf-8"));
|
|
69
|
+
}
|
|
70
|
+
const path = options.id ? `${collection}/${options.id}` : collection;
|
|
71
|
+
const res = await client.post(path, body);
|
|
72
|
+
if (!res.ok) {
|
|
73
|
+
const data = await res.json().catch(() => ({}));
|
|
74
|
+
(0, output_1.error)(data.error?.message || `Create failed with status ${res.status}`);
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
const doc = await res.json();
|
|
78
|
+
(0, output_1.success)(`Created ${doc._id} in ${collection}`);
|
|
79
|
+
}
|
|
80
|
+
async function updateCommand(path, client, options) {
|
|
81
|
+
let body;
|
|
82
|
+
if (options.file) {
|
|
83
|
+
const content = fs.readFileSync(options.file, "utf-8");
|
|
84
|
+
body = JSON.parse(content);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const chunks = [];
|
|
88
|
+
for await (const chunk of process.stdin) {
|
|
89
|
+
chunks.push(chunk);
|
|
90
|
+
}
|
|
91
|
+
body = JSON.parse(Buffer.concat(chunks).toString("utf-8"));
|
|
92
|
+
}
|
|
93
|
+
const res = await client.put(path, body);
|
|
94
|
+
if (!res.ok) {
|
|
95
|
+
const data = await res.json().catch(() => ({}));
|
|
96
|
+
(0, output_1.error)(data.error?.message || `Update failed with status ${res.status}`);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
const doc = await res.json();
|
|
100
|
+
(0, output_1.success)(`Updated ${doc._id}`);
|
|
101
|
+
}
|
|
102
|
+
async function patchCommand(path, client, options) {
|
|
103
|
+
let body;
|
|
104
|
+
if (options.file) {
|
|
105
|
+
const content = fs.readFileSync(options.file, "utf-8");
|
|
106
|
+
body = JSON.parse(content);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const chunks = [];
|
|
110
|
+
for await (const chunk of process.stdin) {
|
|
111
|
+
chunks.push(chunk);
|
|
112
|
+
}
|
|
113
|
+
body = JSON.parse(Buffer.concat(chunks).toString("utf-8"));
|
|
114
|
+
}
|
|
115
|
+
const res = await client.patch(path, body);
|
|
116
|
+
if (!res.ok) {
|
|
117
|
+
const data = await res.json().catch(() => ({}));
|
|
118
|
+
(0, output_1.error)(data.error?.message || `Patch failed with status ${res.status}`);
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
const doc = await res.json();
|
|
122
|
+
(0, output_1.success)(`Patched ${doc._id}`);
|
|
123
|
+
}
|
|
124
|
+
async function deleteCommand(path, client) {
|
|
125
|
+
const res = await client.delete(path);
|
|
126
|
+
if (!res.ok && res.status !== 204) {
|
|
127
|
+
const data = await res.json().catch(() => ({}));
|
|
128
|
+
(0, output_1.error)(data.error?.message || `Delete failed with status ${res.status}`);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
(0, output_1.success)(`Deleted ${path}`);
|
|
132
|
+
}
|
|
133
|
+
async function listCollectionsCommand(client) {
|
|
134
|
+
// List documents and extract unique collection names
|
|
135
|
+
const res = await client.get("?limit=100");
|
|
136
|
+
if (!res.ok) {
|
|
137
|
+
(0, output_1.error)("Failed to list collections");
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
const data = await res.json();
|
|
141
|
+
const collections = new Set();
|
|
142
|
+
for (const doc of data.data || []) {
|
|
143
|
+
if (doc.$collection)
|
|
144
|
+
collections.add(doc.$collection);
|
|
145
|
+
}
|
|
146
|
+
for (const coll of Array.from(collections).sort()) {
|
|
147
|
+
console.log(coll);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async function listDocumentsCommand(collection, client, options) {
|
|
151
|
+
const limit = options.limit || "20";
|
|
152
|
+
const res = await client.get(`${collection}?limit=${limit}`);
|
|
153
|
+
if (!res.ok) {
|
|
154
|
+
(0, output_1.error)("Failed to list documents");
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
const data = await res.json();
|
|
158
|
+
if (options.format === "raw") {
|
|
159
|
+
(0, output_1.printJson)(data, true);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
(0, output_1.printJson)(data);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ApiClient } from "../lib/client";
|
|
2
|
+
export declare function validateCommand(collection: string, client: ApiClient, options: {
|
|
3
|
+
file?: string;
|
|
4
|
+
}): Promise<void>;
|
|
5
|
+
export declare function countCommand(collection: string, client: ApiClient, options: {
|
|
6
|
+
filter?: string[];
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
export declare function bulkCommand(collection: string, client: ApiClient, options: {
|
|
9
|
+
file?: string;
|
|
10
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,108 @@
|
|
|
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.validateCommand = validateCommand;
|
|
37
|
+
exports.countCommand = countCommand;
|
|
38
|
+
exports.bulkCommand = bulkCommand;
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const output_1 = require("../lib/output");
|
|
41
|
+
function readInput(options) {
|
|
42
|
+
let raw;
|
|
43
|
+
if (options.file) {
|
|
44
|
+
raw = fs.readFileSync(options.file, "utf-8");
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const buf = fs.readFileSync(0, "utf-8");
|
|
48
|
+
raw = buf;
|
|
49
|
+
}
|
|
50
|
+
return JSON.parse(raw);
|
|
51
|
+
}
|
|
52
|
+
async function validateCommand(collection, client, options) {
|
|
53
|
+
const body = readInput(options);
|
|
54
|
+
const res = await client.post(`${collection}/_validate`, body);
|
|
55
|
+
if (!res.ok) {
|
|
56
|
+
const data = await res.json().catch(() => ({}));
|
|
57
|
+
if (res.status === 422) {
|
|
58
|
+
(0, output_1.error)("Validation failed");
|
|
59
|
+
(0, output_1.printJson)(data);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
(0, output_1.error)(data.error?.message || `Validation request failed: ${res.status}`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
const data = await res.json();
|
|
66
|
+
(0, output_1.success)("Document is valid");
|
|
67
|
+
(0, output_1.printJson)(data);
|
|
68
|
+
}
|
|
69
|
+
async function countCommand(collection, client, options) {
|
|
70
|
+
let query = `${collection}?count=true`;
|
|
71
|
+
if (options.filter && options.filter.length > 0) {
|
|
72
|
+
for (const f of options.filter) {
|
|
73
|
+
const eqIndex = f.indexOf("=");
|
|
74
|
+
if (eqIndex === -1) {
|
|
75
|
+
(0, output_1.error)(`Invalid filter: ${f}. Use field=value or field[op]=value`);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
const key = f.slice(0, eqIndex);
|
|
79
|
+
const value = f.slice(eqIndex + 1);
|
|
80
|
+
query += `&filter[${key}]=${encodeURIComponent(value)}`;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const res = await client.get(query);
|
|
84
|
+
if (!res.ok) {
|
|
85
|
+
const data = await res.json().catch(() => ({}));
|
|
86
|
+
(0, output_1.error)(data.error?.message || `Count failed: ${res.status}`);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
const data = await res.json();
|
|
90
|
+
const count = data.count ?? data.meta?.total ?? data;
|
|
91
|
+
console.log(String(count));
|
|
92
|
+
}
|
|
93
|
+
async function bulkCommand(collection, client, options) {
|
|
94
|
+
const body = readInput(options);
|
|
95
|
+
if (!Array.isArray(body)) {
|
|
96
|
+
(0, output_1.error)("Bulk operations must be a JSON array");
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
const res = await client.post(`${collection}/_bulk`, body);
|
|
100
|
+
if (!res.ok) {
|
|
101
|
+
const data = await res.json().catch(() => ({}));
|
|
102
|
+
(0, output_1.error)(data.error?.message || `Bulk operation failed: ${res.status}`);
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
const data = await res.json();
|
|
106
|
+
(0, output_1.success)(`Bulk operation completed`);
|
|
107
|
+
(0, output_1.printJson)(data);
|
|
108
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ApiClient } from "../lib/client";
|
|
2
|
+
export declare function listKeysCommand(client: ApiClient): Promise<void>;
|
|
3
|
+
export declare function createKeyCommand(client: ApiClient, options: {
|
|
4
|
+
name?: string;
|
|
5
|
+
scope?: string;
|
|
6
|
+
project?: string;
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
export declare function revokeKeyCommand(keyId: string, client: ApiClient): Promise<void>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listKeysCommand = listKeysCommand;
|
|
4
|
+
exports.createKeyCommand = createKeyCommand;
|
|
5
|
+
exports.revokeKeyCommand = revokeKeyCommand;
|
|
6
|
+
const output_1 = require("../lib/output");
|
|
7
|
+
async function listKeysCommand(client) {
|
|
8
|
+
const res = await client.rawGet("/api/keys");
|
|
9
|
+
if (!res.ok) {
|
|
10
|
+
(0, output_1.error)("Failed to list API keys");
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
const data = await res.json();
|
|
14
|
+
const keys = Array.isArray(data) ? data : data.data || [];
|
|
15
|
+
if (keys.length === 0) {
|
|
16
|
+
console.log("No API keys found.");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const headers = ["NAME", "HINT", "SCOPE", "PROJECT", "STATUS", "CREATED"];
|
|
20
|
+
const rows = keys.map((k) => [
|
|
21
|
+
k.name || "",
|
|
22
|
+
`...${k.hint || ""}`,
|
|
23
|
+
k.scope || "",
|
|
24
|
+
k.project || "",
|
|
25
|
+
k.status || "",
|
|
26
|
+
k.createdAt ? new Date(k.createdAt).toLocaleDateString() : "",
|
|
27
|
+
]);
|
|
28
|
+
(0, output_1.printTable)(headers, rows);
|
|
29
|
+
}
|
|
30
|
+
async function createKeyCommand(client, options) {
|
|
31
|
+
const res = await client.rawGet("/api/keys"); // POST via the dashboard API
|
|
32
|
+
// Actually we need to post to create. Use a different approach
|
|
33
|
+
const body = {
|
|
34
|
+
name: options.name || "CLI-generated key",
|
|
35
|
+
scope: options.scope || "read-write",
|
|
36
|
+
project: options.project || "default",
|
|
37
|
+
};
|
|
38
|
+
// This goes through the dashboard API
|
|
39
|
+
const base = "https://api.jsondb.cloud"; // Will be overridden by config
|
|
40
|
+
const createRes = await fetch(`${base}/api/keys`, {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: {
|
|
43
|
+
"Content-Type": "application/json",
|
|
44
|
+
// Dashboard API requires Clerk auth — this is a limitation of CLI
|
|
45
|
+
// For now, just output the intent
|
|
46
|
+
},
|
|
47
|
+
body: JSON.stringify(body),
|
|
48
|
+
});
|
|
49
|
+
if (createRes.ok) {
|
|
50
|
+
const data = await createRes.json();
|
|
51
|
+
(0, output_1.success)(`Created API key: ${data.rawKey || data.key || "check dashboard"}`);
|
|
52
|
+
(0, output_1.warn)("This key will only be shown once. Store it securely.");
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
(0, output_1.error)("Key creation requires dashboard authentication. Use the web dashboard to create keys.");
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function revokeKeyCommand(keyId, client) {
|
|
60
|
+
const res = await client.rawGet(`/api/keys/${keyId}`);
|
|
61
|
+
if (!res.ok) {
|
|
62
|
+
(0, output_1.error)("Key revocation requires dashboard authentication. Use the web dashboard.");
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
(0, output_1.success)(`Key ${keyId} revoked`);
|
|
66
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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.loginCommand = loginCommand;
|
|
37
|
+
const readline = __importStar(require("readline"));
|
|
38
|
+
const config_1 = require("../lib/config");
|
|
39
|
+
const output_1 = require("../lib/output");
|
|
40
|
+
async function loginCommand(options) {
|
|
41
|
+
let apiKey = options.apiKey || "";
|
|
42
|
+
if (!apiKey) {
|
|
43
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
44
|
+
apiKey = await new Promise((resolve) => {
|
|
45
|
+
rl.question("? Enter your API key: ", (answer) => {
|
|
46
|
+
rl.close();
|
|
47
|
+
resolve(answer.trim());
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (!apiKey || !apiKey.startsWith("jdb_sk_")) {
|
|
52
|
+
(0, output_1.error)("Invalid API key format", "API keys start with 'jdb_sk_live_' or 'jdb_sk_test_'");
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
const config = {
|
|
56
|
+
apiKey,
|
|
57
|
+
project: options.project || "default",
|
|
58
|
+
baseUrl: options.baseUrl || "https://api.jsondb.cloud",
|
|
59
|
+
};
|
|
60
|
+
(0, config_1.saveConfig)(config);
|
|
61
|
+
(0, output_1.success)(`Authenticated successfully`);
|
|
62
|
+
console.log(` Project: ${config.project}`);
|
|
63
|
+
console.log(` Key stored in ${(0, config_1.getConfigPath)()}`);
|
|
64
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
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.pullCommand = pullCommand;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const output_1 = require("../lib/output");
|
|
39
|
+
async function pullCommand(collection, client, options) {
|
|
40
|
+
const format = options.format || "json";
|
|
41
|
+
let accept = "application/json";
|
|
42
|
+
if (format === "csv")
|
|
43
|
+
accept = "text/csv";
|
|
44
|
+
else if (format === "ndjson")
|
|
45
|
+
accept = "application/x-ndjson";
|
|
46
|
+
let path = `${collection}/_export`;
|
|
47
|
+
if (options.filter) {
|
|
48
|
+
// Parse simple filter: "field=value"
|
|
49
|
+
const parts = options.filter.split("=");
|
|
50
|
+
if (parts.length === 2) {
|
|
51
|
+
path += `?filter[${parts[0]}]=${encodeURIComponent(parts[1])}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const res = await client.get(path, accept);
|
|
55
|
+
if (!res.ok) {
|
|
56
|
+
const data = await res.json().catch(() => ({}));
|
|
57
|
+
(0, output_1.error)(data.error?.message || `Export failed with status ${res.status}`);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
const content = await res.text();
|
|
61
|
+
if (options.out) {
|
|
62
|
+
fs.writeFileSync(options.out, content, "utf-8");
|
|
63
|
+
// Count documents
|
|
64
|
+
let count = 0;
|
|
65
|
+
if (format === "json") {
|
|
66
|
+
try {
|
|
67
|
+
count = JSON.parse(content).length;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
count = 0;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (format === "ndjson") {
|
|
74
|
+
count = content.split("\n").filter((l) => l.trim()).length;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
count = content.split("\n").filter((l) => l.trim()).length - 1; // exclude header
|
|
78
|
+
}
|
|
79
|
+
(0, output_1.success)(`Exported ${count} documents to ${options.out}`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
// Output to stdout
|
|
83
|
+
process.stdout.write(content);
|
|
84
|
+
if (!content.endsWith("\n"))
|
|
85
|
+
process.stdout.write("\n");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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.pushCommand = pushCommand;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const output_1 = require("../lib/output");
|
|
40
|
+
async function pushCommand(file, client, options) {
|
|
41
|
+
if (!fs.existsSync(file)) {
|
|
42
|
+
(0, output_1.error)(`File not found: ${file}`);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
const collection = options.to || path.basename(file, path.extname(file));
|
|
46
|
+
const content = fs.readFileSync(file, "utf-8");
|
|
47
|
+
const ext = path.extname(file).toLowerCase();
|
|
48
|
+
let contentType = "application/json";
|
|
49
|
+
if (ext === ".csv")
|
|
50
|
+
contentType = "text/csv";
|
|
51
|
+
else if (ext === ".ndjson")
|
|
52
|
+
contentType = "application/x-ndjson";
|
|
53
|
+
const onConflict = options.onConflict || "fail";
|
|
54
|
+
const url = `${collection}/_import?onConflict=${onConflict}`;
|
|
55
|
+
const isTTY = process.stdout.isTTY;
|
|
56
|
+
if (isTTY) {
|
|
57
|
+
console.log(`Importing to ${collection}...`);
|
|
58
|
+
}
|
|
59
|
+
const res = await client.postRaw(url, content, contentType);
|
|
60
|
+
if (!res.ok) {
|
|
61
|
+
const data = await res.json().catch(() => ({}));
|
|
62
|
+
(0, output_1.error)(data.error?.message || `Import failed with status ${res.status}`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
const result = await res.json();
|
|
66
|
+
const summary = result.summary;
|
|
67
|
+
(0, output_1.success)(`Imported ${summary.total} documents (${summary.created} created, ${summary.skipped || 0} skipped, ${summary.failed || 0} failed, ${summary.overwritten || 0} overwritten)`);
|
|
68
|
+
if (result.errors && result.errors.length > 0) {
|
|
69
|
+
(0, output_1.warn)(`${result.errors.length} errors:`);
|
|
70
|
+
for (const e of result.errors.slice(0, 10)) {
|
|
71
|
+
console.log(` - Index ${e.index}: ${e.error.message}`);
|
|
72
|
+
}
|
|
73
|
+
if (result.errors.length > 10) {
|
|
74
|
+
console.log(` ... and ${result.errors.length - 10} more`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ApiClient } from "../lib/client";
|
|
2
|
+
export declare function getSchemaCommand(collection: string, client: ApiClient): Promise<void>;
|
|
3
|
+
export declare function setSchemaCommand(collection: string, client: ApiClient, options: {
|
|
4
|
+
file?: string;
|
|
5
|
+
}): Promise<void>;
|
|
6
|
+
export declare function removeSchemaCommand(collection: string, client: ApiClient): Promise<void>;
|