forge-fsql 1.0.2 → 1.0.3
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/bin/setup +75 -39
- package/dist/cjs/client.js +1 -5
- package/dist/client.js +0 -1
- package/package.json +2 -3
package/bin/setup
CHANGED
|
@@ -6,7 +6,7 @@ import { createRequire } from "module";
|
|
|
6
6
|
|
|
7
7
|
// Support both ESM and CJS imports for js-yaml
|
|
8
8
|
const require = createRequire(import.meta.url);
|
|
9
|
-
const
|
|
9
|
+
const YAML = require("yaml");
|
|
10
10
|
|
|
11
11
|
const projectRoot = process.cwd();
|
|
12
12
|
|
|
@@ -67,45 +67,70 @@ if (!fs.existsSync(manifestPath)) {
|
|
|
67
67
|
process.exit(1);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
let
|
|
70
|
+
let doc;
|
|
71
71
|
try {
|
|
72
72
|
const fileContents = fs.readFileSync(manifestPath, "utf8");
|
|
73
|
-
|
|
73
|
+
doc = YAML.parseDocument(fileContents);
|
|
74
74
|
} catch (e) {
|
|
75
75
|
console.error("Error reading manifest:", e);
|
|
76
76
|
process.exit(1);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
if (!
|
|
80
|
-
|
|
79
|
+
if (!doc.contents) {
|
|
80
|
+
doc.contents = doc.createNode({});
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
if (!doc.has("modules")) {
|
|
84
|
+
doc.set("modules", doc.createNode({}));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const modules = doc.get("modules");
|
|
88
|
+
|
|
83
89
|
// Ensure function is an array
|
|
84
90
|
const functionKey = "executeSql";
|
|
85
|
-
if (!
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
if (!modules.has("function")) {
|
|
92
|
+
modules.set("function", doc.createNode([]));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let functions = modules.get("function");
|
|
96
|
+
|
|
97
|
+
// If it's somehow not a sequence, convert it (though unlikely in Forge)
|
|
98
|
+
if (!YAML.isSeq(functions)) {
|
|
99
|
+
const obj = functions.toJSON();
|
|
100
|
+
functions = doc.createNode(
|
|
101
|
+
Object.entries(obj).map(([key, val]) => ({ key, ...val })),
|
|
91
102
|
);
|
|
103
|
+
modules.set("function", functions);
|
|
92
104
|
}
|
|
93
105
|
|
|
94
|
-
const functionExists = manifest.modules.function.find(
|
|
95
|
-
(f) => f.key === functionKey,
|
|
96
|
-
);
|
|
97
106
|
const handlerName = "fsql.executeSql";
|
|
107
|
+
let functionExists = functions.items.find((f) => {
|
|
108
|
+
const js = f.toJSON();
|
|
109
|
+
return js && js.key === functionKey;
|
|
110
|
+
});
|
|
98
111
|
|
|
99
112
|
if (!functionExists) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
113
|
+
functions.add(
|
|
114
|
+
doc.createNode({
|
|
115
|
+
key: functionKey,
|
|
116
|
+
handler: handlerName,
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
104
119
|
console.log(
|
|
105
120
|
`✓ Added function:${functionKey} with handler ${handlerName} to manifest`,
|
|
106
121
|
);
|
|
107
122
|
} else {
|
|
108
|
-
|
|
123
|
+
// If it's a Pair (map item) or just a Map in the sequence
|
|
124
|
+
if (YAML.isMap(functionExists)) {
|
|
125
|
+
functionExists.set("handler", handlerName);
|
|
126
|
+
} else {
|
|
127
|
+
// Should not happen with doc.createNode above, but for safety:
|
|
128
|
+
const idx = functions.items.indexOf(functionExists);
|
|
129
|
+
functions.set(
|
|
130
|
+
idx,
|
|
131
|
+
doc.createNode({ key: functionKey, handler: handlerName }),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
109
134
|
console.log(
|
|
110
135
|
`✓ Updated function:${functionKey} handler to ${handlerName} in manifest`,
|
|
111
136
|
);
|
|
@@ -113,38 +138,49 @@ if (!functionExists) {
|
|
|
113
138
|
|
|
114
139
|
// Ensure webtrigger is an array
|
|
115
140
|
const webtriggerKey = "execute-sql";
|
|
116
|
-
if (!
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
141
|
+
if (!modules.has("webtrigger")) {
|
|
142
|
+
modules.set("webtrigger", doc.createNode([]));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
let webtriggers = modules.get("webtrigger");
|
|
146
|
+
if (!YAML.isSeq(webtriggers)) {
|
|
147
|
+
const obj = webtriggers.toJSON();
|
|
148
|
+
webtriggers = doc.createNode(
|
|
149
|
+
Object.entries(obj).map(([key, val]) => ({ key, ...val })),
|
|
121
150
|
);
|
|
151
|
+
modules.set("webtrigger", webtriggers);
|
|
122
152
|
}
|
|
123
153
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
154
|
+
let webtriggerExists = webtriggers.items.find((w) => {
|
|
155
|
+
const js = w.toJSON();
|
|
156
|
+
return js && js.key === webtriggerKey;
|
|
157
|
+
});
|
|
158
|
+
|
|
127
159
|
if (!webtriggerExists) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
160
|
+
webtriggers.add(
|
|
161
|
+
doc.createNode({
|
|
162
|
+
key: webtriggerKey,
|
|
163
|
+
function: functionKey,
|
|
164
|
+
}),
|
|
165
|
+
);
|
|
132
166
|
console.log(`✓ Added webtrigger:${webtriggerKey} to manifest`);
|
|
133
167
|
} else {
|
|
134
|
-
webtriggerExists
|
|
168
|
+
if (YAML.isMap(webtriggerExists)) {
|
|
169
|
+
webtriggerExists.set("function", functionKey);
|
|
170
|
+
} else {
|
|
171
|
+
const idx = webtriggers.items.indexOf(webtriggerExists);
|
|
172
|
+
webtriggers.set(
|
|
173
|
+
idx,
|
|
174
|
+
doc.createNode({ key: webtriggerKey, function: functionKey }),
|
|
175
|
+
);
|
|
176
|
+
}
|
|
135
177
|
console.log(
|
|
136
178
|
`✓ Ensured webtrigger:${webtriggerKey} points to function ${functionKey}`,
|
|
137
179
|
);
|
|
138
180
|
}
|
|
139
181
|
|
|
140
182
|
try {
|
|
141
|
-
|
|
142
|
-
const newYaml = yaml.dump(manifest, {
|
|
143
|
-
indent: 2,
|
|
144
|
-
lineWidth: -1,
|
|
145
|
-
noRefs: true,
|
|
146
|
-
});
|
|
147
|
-
fs.writeFileSync(manifestPath, newYaml);
|
|
183
|
+
fs.writeFileSync(manifestPath, doc.toString());
|
|
148
184
|
console.log("✓ Updated manifest file successfully");
|
|
149
185
|
} catch (e) {
|
|
150
186
|
console.error("Error writing manifest:", e);
|
package/dist/cjs/client.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.ForgeClient = void 0;
|
|
7
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
4
|
class ForgeClient {
|
|
9
5
|
constructor(config) {
|
|
10
6
|
this.config = {
|
|
@@ -22,7 +18,7 @@ class ForgeClient {
|
|
|
22
18
|
const headers = {
|
|
23
19
|
"Content-Type": "application/json",
|
|
24
20
|
};
|
|
25
|
-
const response = await (
|
|
21
|
+
const response = await fetch(this.config.url, {
|
|
26
22
|
method: "POST",
|
|
27
23
|
headers,
|
|
28
24
|
body: JSON.stringify({ query: finalSql }),
|
package/dist/client.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "forge-fsql",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Interactive SQL CLI for Atlassian Forge SQL via web triggers",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -41,12 +41,11 @@
|
|
|
41
41
|
"chalk": "^5.4.1",
|
|
42
42
|
"cli-table3": "^0.6.3",
|
|
43
43
|
"dotenv": "^16.0.3",
|
|
44
|
-
"
|
|
44
|
+
"yaml": "^2.8.2"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@eslint/eslintrc": "^3.3.3",
|
|
48
48
|
"@eslint/js": "^9.39.1",
|
|
49
|
-
"@types/js-yaml": "^4.0.9",
|
|
50
49
|
"@types/node": "^22.19.1",
|
|
51
50
|
"@typescript-eslint/eslint-plugin": "^8.48.0",
|
|
52
51
|
"@typescript-eslint/parser": "^8.48.0",
|