@superblocksteam/cli 2.0.6-next.22 → 2.0.6-next.24
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/README.md +1 -1
- package/dist/index.js +415 -421
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ $ npm install -g @superblocksteam/cli
|
|
|
14
14
|
$ superblocks COMMAND
|
|
15
15
|
running command...
|
|
16
16
|
$ superblocks (--version)
|
|
17
|
-
@superblocksteam/cli/2.0.6-next.
|
|
17
|
+
@superblocksteam/cli/2.0.6-next.24 linux-x64 node-v20.19.0
|
|
18
18
|
$ superblocks --help [COMMAND]
|
|
19
19
|
USAGE
|
|
20
20
|
$ superblocks COMMAND
|
package/dist/index.js
CHANGED
|
@@ -431941,6 +431941,7 @@ init_cjs_shims();
|
|
|
431941
431941
|
import path21 from "node:path";
|
|
431942
431942
|
var PAGES_DIRECTORY = "pages";
|
|
431943
431943
|
var CUSTOM_COMPONENTS_DIRECTORY = "components";
|
|
431944
|
+
var API_FOLDER = "apis";
|
|
431944
431945
|
var ROUTES_FILE = "routes.json";
|
|
431945
431946
|
var SCOPE_FILE = "scope.ts";
|
|
431946
431947
|
function getPageFolder(rootPath, pageName) {
|
|
@@ -431952,6 +431953,9 @@ function getPageFilePath(rootPath, pageName) {
|
|
|
431952
431953
|
function isPageFilePath(filePath) {
|
|
431953
431954
|
return /pages\/.*\/index\.tsx/.test(filePath);
|
|
431954
431955
|
}
|
|
431956
|
+
function getApiFilePath(rootPath, pageName, apiName) {
|
|
431957
|
+
return path21.join(getPageFolder(rootPath, pageName), API_FOLDER, apiName, "api.yaml");
|
|
431958
|
+
}
|
|
431955
431959
|
|
|
431956
431960
|
// ../../../vite-plugin-file-sync/dist/traverse.js
|
|
431957
431961
|
init_cjs_shims();
|
|
@@ -436807,6 +436811,9 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
436807
436811
|
registeredComponentPaths = {};
|
|
436808
436812
|
renameManager = new RenameManager();
|
|
436809
436813
|
_tracer;
|
|
436814
|
+
transactionNonce = Date.now();
|
|
436815
|
+
pendingTransactions = /* @__PURE__ */ new Set();
|
|
436816
|
+
processedTransactions = [];
|
|
436810
436817
|
constructor(fsOperationQueue, generationNumberSequence, tracer2) {
|
|
436811
436818
|
super(tracer2, { captureRejections: true });
|
|
436812
436819
|
this.rootDir = "/";
|
|
@@ -436863,27 +436870,7 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
436863
436870
|
}
|
|
436864
436871
|
return path27.join(this.rootDir, "App.tsx");
|
|
436865
436872
|
}
|
|
436866
|
-
|
|
436867
|
-
if (!this.rootDir) {
|
|
436868
|
-
throw new Error("Root directory not set");
|
|
436869
|
-
}
|
|
436870
|
-
const { api: apiContents, stepPathMap } = content2;
|
|
436871
|
-
const pageName = getPageName2(path55);
|
|
436872
|
-
let scopeId = this.sourceTracker?.getScopeDefinitionForPage(pageName)?.id;
|
|
436873
|
-
if (!scopeId) {
|
|
436874
|
-
console.warn("Scope ID not found for API", apiContents.metadata.name);
|
|
436875
|
-
scopeId = "";
|
|
436876
|
-
}
|
|
436877
|
-
const updatedApi = {
|
|
436878
|
-
apiPb: import_yaml2.default.parse(JSON.stringify(apiContents)),
|
|
436879
|
-
pageName,
|
|
436880
|
-
stepPathMap,
|
|
436881
|
-
scopeId
|
|
436882
|
-
};
|
|
436883
|
-
const isNewApi = !this.apiFiles[path55];
|
|
436884
|
-
this.apiFiles[path55] = updatedApi;
|
|
436885
|
-
return { updatedApi, pageName, isNewApi };
|
|
436886
|
-
};
|
|
436873
|
+
// MARK: core setup/init
|
|
436887
436874
|
async watch(watcher, rootPath) {
|
|
436888
436875
|
const logger3 = getLogger();
|
|
436889
436876
|
this.rootDir = rootPath;
|
|
@@ -436961,11 +436948,113 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
436961
436948
|
return;
|
|
436962
436949
|
const { type: type2, path: path55 } = file;
|
|
436963
436950
|
if (type2 === "api") {
|
|
436964
|
-
this.
|
|
436951
|
+
this.updateInternalApiData(content2, path55);
|
|
436965
436952
|
}
|
|
436966
436953
|
});
|
|
436967
436954
|
watcher.on("all", this.handleFileChange);
|
|
436968
436955
|
}
|
|
436956
|
+
initializeSourceTracker() {
|
|
436957
|
+
this.sourceTracker = new SourceTracker(this._tracer);
|
|
436958
|
+
this.sourceTracker.initializeSourceTracker({
|
|
436959
|
+
files: this.tsFiles
|
|
436960
|
+
});
|
|
436961
|
+
}
|
|
436962
|
+
handleNonVisualChangeByDeletingIds(path55, content2) {
|
|
436963
|
+
if (!this.sourceTracker) {
|
|
436964
|
+
throw new Error("Source tracker not initialized");
|
|
436965
|
+
}
|
|
436966
|
+
return this.sourceTracker.handleNonVisualChangeByDeletingIds(path55, content2);
|
|
436967
|
+
}
|
|
436968
|
+
async getFileWithIds(filePath) {
|
|
436969
|
+
const logger3 = getLogger();
|
|
436970
|
+
if (!this.sourceTracker) {
|
|
436971
|
+
throw new Error("Source tracker not initialized");
|
|
436972
|
+
}
|
|
436973
|
+
const files = this.sourceTracker.getCurrentFiles();
|
|
436974
|
+
if (!files[filePath]) {
|
|
436975
|
+
throw new Error("File not found in source tracker " + filePath);
|
|
436976
|
+
}
|
|
436977
|
+
const ast = files[filePath].ast;
|
|
436978
|
+
if (!ast) {
|
|
436979
|
+
throw new Error("No AST found for file in source tracker " + filePath);
|
|
436980
|
+
}
|
|
436981
|
+
const clonedAst = await (0, import_core3.transformFromAstAsync)(ast, void 0, {
|
|
436982
|
+
ast: true
|
|
436983
|
+
});
|
|
436984
|
+
if (!clonedAst?.ast) {
|
|
436985
|
+
throw new Error("Failed to clone AST for file " + filePath);
|
|
436986
|
+
}
|
|
436987
|
+
const componentsManager = ComponentsManager.getInstance();
|
|
436988
|
+
const processedTransactions = this.getProcessedTransactionsWithNonce();
|
|
436989
|
+
const customImports = /* @__PURE__ */ new Set();
|
|
436990
|
+
traverse(clonedAst.ast, {
|
|
436991
|
+
Program: {
|
|
436992
|
+
exit(nodePath) {
|
|
436993
|
+
if (isCustomBuildEnabled()) {
|
|
436994
|
+
addLegacyCustomComponentVariables(nodePath, customImports);
|
|
436995
|
+
}
|
|
436996
|
+
const name18 = componentsManager.getComponentName(filePath);
|
|
436997
|
+
if (name18) {
|
|
436998
|
+
nodePath.pushContainer("body", import_types26.default.variableDeclaration("const", [
|
|
436999
|
+
import_types26.default.variableDeclarator(import_types26.default.identifier("componentName"), import_types26.default.stringLiteral(name18))
|
|
437000
|
+
]));
|
|
437001
|
+
}
|
|
437002
|
+
}
|
|
437003
|
+
},
|
|
437004
|
+
ImportDeclaration(path55) {
|
|
437005
|
+
if (isCustomBuildEnabled()) {
|
|
437006
|
+
modifyLegacyCustomComponentImports(path55, customImports);
|
|
437007
|
+
}
|
|
437008
|
+
},
|
|
437009
|
+
JSXElement(path55) {
|
|
437010
|
+
if (isCustomBuildEnabled()) {
|
|
437011
|
+
modifyLegacyCustomComponentElements(path55, customImports);
|
|
437012
|
+
}
|
|
437013
|
+
},
|
|
437014
|
+
ReturnStatement(path55) {
|
|
437015
|
+
const argument = path55.get("argument");
|
|
437016
|
+
if (!argument.isJSXElement()) {
|
|
437017
|
+
return;
|
|
437018
|
+
}
|
|
437019
|
+
const openingElement = argument.get("openingElement");
|
|
437020
|
+
if (!openingElement.isJSXOpeningElement()) {
|
|
437021
|
+
return;
|
|
437022
|
+
}
|
|
437023
|
+
openingElement.pushContainer("attributes", makeJSXAttribute(ROOT_WIDGET_ATTRIBUTE, "true"));
|
|
437024
|
+
openingElement.pushContainer("attributes", generateJSXAttribute(PROCESSED_TRANSACTIONS_ATTRIBUTE, {
|
|
437025
|
+
value: processedTransactions,
|
|
437026
|
+
type: "EXPRESSION",
|
|
437027
|
+
__info: true
|
|
437028
|
+
}));
|
|
437029
|
+
},
|
|
437030
|
+
JSXOpeningElement(path55) {
|
|
437031
|
+
const elementId = getSbElementId(path55.node);
|
|
437032
|
+
if (elementId) {
|
|
437033
|
+
path55.pushContainer("attributes", makeJSXAttribute(WIDGET_SOURCE_ID_ATTRIBUTE, elementId));
|
|
437034
|
+
}
|
|
437035
|
+
},
|
|
437036
|
+
ObjectProperty(path55) {
|
|
437037
|
+
const elementId = getSbElementId(path55.node);
|
|
437038
|
+
if (!elementId) {
|
|
437039
|
+
path55.skip();
|
|
437040
|
+
return;
|
|
437041
|
+
}
|
|
437042
|
+
path55.traverse({
|
|
437043
|
+
ObjectExpression(path56) {
|
|
437044
|
+
path56.pushContainer("properties", import_types26.default.objectProperty(import_types26.default.identifier("id"), import_types26.default.stringLiteral(elementId)));
|
|
437045
|
+
path56.skip();
|
|
437046
|
+
}
|
|
437047
|
+
});
|
|
437048
|
+
}
|
|
437049
|
+
});
|
|
437050
|
+
try {
|
|
437051
|
+
const result = generate(clonedAst.ast);
|
|
437052
|
+
return result.code;
|
|
437053
|
+
} catch (e) {
|
|
437054
|
+
logger3.error("Error generating file with ids", getErrorMeta(e));
|
|
437055
|
+
return null;
|
|
437056
|
+
}
|
|
437057
|
+
}
|
|
436969
437058
|
enableOperationsQueue() {
|
|
436970
437059
|
this.operationProcessor.enable();
|
|
436971
437060
|
}
|
|
@@ -436975,6 +437064,7 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
436975
437064
|
async flushOperations() {
|
|
436976
437065
|
await this.operationProcessor.flush();
|
|
436977
437066
|
}
|
|
437067
|
+
// MARK: file change handling
|
|
436978
437068
|
handleFileChange = async (event, filePath) => {
|
|
436979
437069
|
const logger3 = getLogger();
|
|
436980
437070
|
logger3.info(`File changed: ${filePath}, event: ${event}`);
|
|
@@ -437024,7 +437114,7 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437024
437114
|
case "api":
|
|
437025
437115
|
case "python-api-step":
|
|
437026
437116
|
case "js-api-step": {
|
|
437027
|
-
await this.
|
|
437117
|
+
await this.processApiFileUpdates(filePath, fileType);
|
|
437028
437118
|
break;
|
|
437029
437119
|
}
|
|
437030
437120
|
}
|
|
@@ -437085,7 +437175,7 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437085
437175
|
case "python-api-step":
|
|
437086
437176
|
case "js-api-step":
|
|
437087
437177
|
{
|
|
437088
|
-
await this.
|
|
437178
|
+
await this.processApiFileUpdates(filePath, fileType2);
|
|
437089
437179
|
}
|
|
437090
437180
|
break;
|
|
437091
437181
|
}
|
|
@@ -437110,7 +437200,7 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437110
437200
|
filePath
|
|
437111
437201
|
},
|
|
437112
437202
|
execute: async () => {
|
|
437113
|
-
await this.
|
|
437203
|
+
await this.removeApiData(filePath);
|
|
437114
437204
|
}
|
|
437115
437205
|
});
|
|
437116
437206
|
}
|
|
@@ -437118,9 +437208,6 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437118
437208
|
}
|
|
437119
437209
|
}
|
|
437120
437210
|
};
|
|
437121
|
-
getApiFiles() {
|
|
437122
|
-
return this.formatApisToClientApis(this.apiFiles);
|
|
437123
|
-
}
|
|
437124
437211
|
async deleteTsFile(filePath) {
|
|
437125
437212
|
delete this.tsFiles[filePath];
|
|
437126
437213
|
this.sourceTracker?.removeFile(filePath);
|
|
@@ -437128,35 +437215,13 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437128
437215
|
this.emit("deletePage", filePath);
|
|
437129
437216
|
}
|
|
437130
437217
|
}
|
|
437131
|
-
async deleteApiFile(filePath) {
|
|
437132
|
-
const api = this.apiFiles[filePath];
|
|
437133
|
-
if (!api) {
|
|
437134
|
-
return;
|
|
437135
|
-
}
|
|
437136
|
-
delete this.apiFiles[filePath];
|
|
437137
|
-
this.sourceTracker?.deleteApi({
|
|
437138
|
-
pageName: api.pageName,
|
|
437139
|
-
apiName: api.apiPb.metadata.name
|
|
437140
|
-
});
|
|
437141
|
-
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437142
|
-
await this.writeChanges(changes);
|
|
437143
|
-
const scopeId = this.sourceTracker?.getScopeDefinitionForPage(api.pageName)?.id;
|
|
437144
|
-
this.emit("apiManualDelete", {
|
|
437145
|
-
api: {
|
|
437146
|
-
id: getClientApiId(api.apiPb.metadata.name, api.pageName),
|
|
437147
|
-
apiName: api.apiPb.metadata.name,
|
|
437148
|
-
// TODO(saksham): get pagename more defensively
|
|
437149
|
-
pageName: getPageName2(filePath),
|
|
437150
|
-
scopeId
|
|
437151
|
-
}
|
|
437152
|
-
});
|
|
437153
|
-
}
|
|
437154
437218
|
getTsFilePaths() {
|
|
437155
437219
|
return Object.keys(this.tsFiles);
|
|
437156
437220
|
}
|
|
437157
437221
|
getSourceTracker() {
|
|
437158
437222
|
return this.sourceTracker;
|
|
437159
437223
|
}
|
|
437224
|
+
// MARK: fs read/write
|
|
437160
437225
|
async writeFile(path55, content2, kind) {
|
|
437161
437226
|
if (kind === "ts") {
|
|
437162
437227
|
this.tsFiles[path55] = content2;
|
|
@@ -437170,7 +437235,7 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437170
437235
|
delete apiPb.metadata.id;
|
|
437171
437236
|
}
|
|
437172
437237
|
const stepPathMap = currentApiFile?.stepPathMap ?? {};
|
|
437173
|
-
this.
|
|
437238
|
+
this.updateInternalApiData({ api: apiPb, stepPathMap }, path55);
|
|
437174
437239
|
await this.fsOperationQueue.enqueue(async () => {
|
|
437175
437240
|
await (0, import_util23.writeApiFiles)({ apiPb }, "api", path55.split("/").slice(0, -1).join("/"), false, [], [], { extractLargeSourceFiles: true, minLinesForExtraction: 1 }, new Set(Object.keys(this.apiFiles)), stepPathMap);
|
|
437176
437241
|
if (this.apiFiles[path55]) {
|
|
@@ -437182,124 +437247,43 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437182
437247
|
readFile(path55) {
|
|
437183
437248
|
return this.tsFiles[path55];
|
|
437184
437249
|
}
|
|
437185
|
-
|
|
437186
|
-
|
|
437187
|
-
|
|
437188
|
-
|
|
437189
|
-
}
|
|
437250
|
+
async addRoute(route, filePath) {
|
|
437251
|
+
if (!this.rootDir) {
|
|
437252
|
+
throw new Error("Root directory not set");
|
|
437253
|
+
}
|
|
437254
|
+
this.routes[route] = { file: this.getRelativeRoutePath(filePath) };
|
|
437255
|
+
await this.writeFile(path27.join(this.rootDir, ROUTES_FILE), JSON.stringify(this.routes, null, 2));
|
|
437190
437256
|
}
|
|
437191
|
-
|
|
437192
|
-
if (!this.
|
|
437193
|
-
throw new Error("
|
|
437257
|
+
async removeRoute(filePath) {
|
|
437258
|
+
if (!this.rootDir) {
|
|
437259
|
+
throw new Error("Root directory not set");
|
|
437194
437260
|
}
|
|
437195
|
-
|
|
437261
|
+
const relativeFilePath = this.getRelativeRoutePath(filePath);
|
|
437262
|
+
this.routes = Object.fromEntries(Object.entries(this.routes).filter(([_, value2]) => value2.file !== relativeFilePath));
|
|
437263
|
+
await this.writeFile(path27.join(this.rootDir, ROUTES_FILE), JSON.stringify(this.routes, null, 2));
|
|
437196
437264
|
}
|
|
437197
|
-
async
|
|
437265
|
+
async writeChanges(changes, callback) {
|
|
437266
|
+
return Promise.all(changes.map(async ({ fileName, source: source2, kind }) => {
|
|
437267
|
+
await this.writeFile(fileName, source2, kind);
|
|
437268
|
+
return callback?.(fileName, source2);
|
|
437269
|
+
}));
|
|
437270
|
+
}
|
|
437271
|
+
getLocalBindingEntities(path55) {
|
|
437198
437272
|
const logger3 = getLogger();
|
|
437199
|
-
|
|
437200
|
-
|
|
437201
|
-
|
|
437202
|
-
|
|
437203
|
-
if (!files[filePath]) {
|
|
437204
|
-
throw new Error("File not found in source tracker " + filePath);
|
|
437273
|
+
const files = this.sourceTracker?.getCurrentFiles();
|
|
437274
|
+
if (!files || !files[path55]) {
|
|
437275
|
+
logger3.warn(`File not found in source tracker for local binding entities: ${path55}`);
|
|
437276
|
+
return [];
|
|
437205
437277
|
}
|
|
437206
|
-
const ast = files[
|
|
437278
|
+
const ast = files[path55].ast;
|
|
437207
437279
|
if (!ast) {
|
|
437208
|
-
|
|
437209
|
-
|
|
437210
|
-
const clonedAst = await (0, import_core3.transformFromAstAsync)(ast, void 0, {
|
|
437211
|
-
ast: true
|
|
437212
|
-
});
|
|
437213
|
-
if (!clonedAst?.ast) {
|
|
437214
|
-
throw new Error("Failed to clone AST for file " + filePath);
|
|
437280
|
+
logger3.warn(`No AST found for file in source tracker for local binding entities: ${path55}`);
|
|
437281
|
+
return [];
|
|
437215
437282
|
}
|
|
437216
|
-
const
|
|
437217
|
-
|
|
437218
|
-
|
|
437219
|
-
|
|
437220
|
-
Program: {
|
|
437221
|
-
exit(nodePath) {
|
|
437222
|
-
if (isCustomBuildEnabled()) {
|
|
437223
|
-
addLegacyCustomComponentVariables(nodePath, customImports);
|
|
437224
|
-
}
|
|
437225
|
-
const name18 = componentsManager.getComponentName(filePath);
|
|
437226
|
-
if (name18) {
|
|
437227
|
-
nodePath.pushContainer("body", import_types26.default.variableDeclaration("const", [
|
|
437228
|
-
import_types26.default.variableDeclarator(import_types26.default.identifier("componentName"), import_types26.default.stringLiteral(name18))
|
|
437229
|
-
]));
|
|
437230
|
-
}
|
|
437231
|
-
}
|
|
437232
|
-
},
|
|
437233
|
-
ImportDeclaration(path55) {
|
|
437234
|
-
if (isCustomBuildEnabled()) {
|
|
437235
|
-
modifyLegacyCustomComponentImports(path55, customImports);
|
|
437236
|
-
}
|
|
437237
|
-
},
|
|
437238
|
-
JSXElement(path55) {
|
|
437239
|
-
if (isCustomBuildEnabled()) {
|
|
437240
|
-
modifyLegacyCustomComponentElements(path55, customImports);
|
|
437241
|
-
}
|
|
437242
|
-
},
|
|
437243
|
-
ReturnStatement(path55) {
|
|
437244
|
-
const argument = path55.get("argument");
|
|
437245
|
-
if (!argument.isJSXElement()) {
|
|
437246
|
-
return;
|
|
437247
|
-
}
|
|
437248
|
-
const openingElement = argument.get("openingElement");
|
|
437249
|
-
if (!openingElement.isJSXOpeningElement()) {
|
|
437250
|
-
return;
|
|
437251
|
-
}
|
|
437252
|
-
openingElement.pushContainer("attributes", makeJSXAttribute(ROOT_WIDGET_ATTRIBUTE, "true"));
|
|
437253
|
-
openingElement.pushContainer("attributes", generateJSXAttribute(PROCESSED_TRANSACTIONS_ATTRIBUTE, {
|
|
437254
|
-
value: processedTransactions,
|
|
437255
|
-
type: "EXPRESSION",
|
|
437256
|
-
__info: true
|
|
437257
|
-
}));
|
|
437258
|
-
},
|
|
437259
|
-
JSXOpeningElement(path55) {
|
|
437260
|
-
const elementId = getSbElementId(path55.node);
|
|
437261
|
-
if (elementId) {
|
|
437262
|
-
path55.pushContainer("attributes", makeJSXAttribute(WIDGET_SOURCE_ID_ATTRIBUTE, elementId));
|
|
437263
|
-
}
|
|
437264
|
-
},
|
|
437265
|
-
ObjectProperty(path55) {
|
|
437266
|
-
const elementId = getSbElementId(path55.node);
|
|
437267
|
-
if (!elementId) {
|
|
437268
|
-
path55.skip();
|
|
437269
|
-
return;
|
|
437270
|
-
}
|
|
437271
|
-
path55.traverse({
|
|
437272
|
-
ObjectExpression(path56) {
|
|
437273
|
-
path56.pushContainer("properties", import_types26.default.objectProperty(import_types26.default.identifier("id"), import_types26.default.stringLiteral(elementId)));
|
|
437274
|
-
path56.skip();
|
|
437275
|
-
}
|
|
437276
|
-
});
|
|
437277
|
-
}
|
|
437278
|
-
});
|
|
437279
|
-
try {
|
|
437280
|
-
const result = generate(clonedAst.ast);
|
|
437281
|
-
return result.code;
|
|
437282
|
-
} catch (e) {
|
|
437283
|
-
logger3.error("Error generating file with ids", getErrorMeta(e));
|
|
437284
|
-
return null;
|
|
437285
|
-
}
|
|
437286
|
-
}
|
|
437287
|
-
getLocalBindingEntities(path55) {
|
|
437288
|
-
const logger3 = getLogger();
|
|
437289
|
-
const files = this.sourceTracker?.getCurrentFiles();
|
|
437290
|
-
if (!files || !files[path55]) {
|
|
437291
|
-
logger3.warn(`File not found in source tracker for local binding entities: ${path55}`);
|
|
437292
|
-
return [];
|
|
437293
|
-
}
|
|
437294
|
-
const ast = files[path55].ast;
|
|
437295
|
-
if (!ast) {
|
|
437296
|
-
logger3.warn(`No AST found for file in source tracker for local binding entities: ${path55}`);
|
|
437297
|
-
return [];
|
|
437298
|
-
}
|
|
437299
|
-
const localBindingEntities = /* @__PURE__ */ new Set();
|
|
437300
|
-
traverse(ast, {
|
|
437301
|
-
JSXOpeningElement(path56) {
|
|
437302
|
-
const elementId = getSbElementId(path56.node);
|
|
437283
|
+
const localBindingEntities = /* @__PURE__ */ new Set();
|
|
437284
|
+
traverse(ast, {
|
|
437285
|
+
JSXOpeningElement(path56) {
|
|
437286
|
+
const elementId = getSbElementId(path56.node);
|
|
437303
437287
|
if (!elementId) {
|
|
437304
437288
|
return;
|
|
437305
437289
|
}
|
|
@@ -437311,8 +437295,35 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437311
437295
|
});
|
|
437312
437296
|
return Array.from(localBindingEntities);
|
|
437313
437297
|
}
|
|
437314
|
-
|
|
437315
|
-
|
|
437298
|
+
getPageRoots(filePath) {
|
|
437299
|
+
const scopeFilePath = path27.join(path27.dirname(filePath), "index.tsx");
|
|
437300
|
+
const currentFile = this.sourceTracker?.getCurrentFiles()[scopeFilePath];
|
|
437301
|
+
if (!currentFile) {
|
|
437302
|
+
return null;
|
|
437303
|
+
}
|
|
437304
|
+
return getPageRoots(filePath, currentFile);
|
|
437305
|
+
}
|
|
437306
|
+
getScope(filePath) {
|
|
437307
|
+
const scopeFilePath = path27.join(path27.dirname(filePath), SCOPE_FILE);
|
|
437308
|
+
const currentFile = this.sourceTracker?.getCurrentFiles()[scopeFilePath];
|
|
437309
|
+
if (!currentFile) {
|
|
437310
|
+
console.log("File not found", scopeFilePath);
|
|
437311
|
+
return null;
|
|
437312
|
+
}
|
|
437313
|
+
const scope = getScope(scopeFilePath, currentFile);
|
|
437314
|
+
return scope;
|
|
437315
|
+
}
|
|
437316
|
+
getRoutes() {
|
|
437317
|
+
const routes = [];
|
|
437318
|
+
for (const [path55, { file }] of Object.entries(this.routes)) {
|
|
437319
|
+
routes.push({
|
|
437320
|
+
path: path55,
|
|
437321
|
+
component: file
|
|
437322
|
+
});
|
|
437323
|
+
}
|
|
437324
|
+
return routes;
|
|
437325
|
+
}
|
|
437326
|
+
// MARK: transaction handling
|
|
437316
437327
|
flushTransactions = () => {
|
|
437317
437328
|
this.processedTransactions = this.processedTransactions.slice(-20);
|
|
437318
437329
|
this.processedTransactions.push(...Array.from(this.pendingTransactions));
|
|
@@ -437324,13 +437335,13 @@ var FileSystemManager = class extends import_shared32.TracedEventEmitter {
|
|
|
437324
437335
|
}
|
|
437325
437336
|
this.pendingTransactions.add(transactionId);
|
|
437326
437337
|
};
|
|
437327
|
-
transactionNonce = Date.now();
|
|
437328
437338
|
// Until we have a sophisticated way to track ALL operations, including non-UI initiated ops, we will use a nonce
|
|
437329
437339
|
// TODO https://github.com/superblocksteam/superblocks/pull/11788
|
|
437330
437340
|
getProcessedTransactionsWithNonce() {
|
|
437331
437341
|
const nonce = `t-${this.transactionNonce++}`;
|
|
437332
437342
|
return this.processedTransactions.concat(nonce);
|
|
437333
437343
|
}
|
|
437344
|
+
// MARK: editor operations
|
|
437334
437345
|
handleCreatePage = async (payload) => {
|
|
437335
437346
|
const { name: name18 } = payload;
|
|
437336
437347
|
if (!this.rootDir) {
|
|
@@ -437350,7 +437361,9 @@ function Page() {
|
|
|
437350
437361
|
export default registerPage(Page, { name: "${name18}" });
|
|
437351
437362
|
`
|
|
437352
437363
|
);
|
|
437353
|
-
await
|
|
437364
|
+
await this.fsOperationQueue.enqueue(async () => {
|
|
437365
|
+
await fs12.mkdir(pagePath, { recursive: true });
|
|
437366
|
+
});
|
|
437354
437367
|
await this.writeFile(pageIndexPath, pageContent, "ts");
|
|
437355
437368
|
await this.handleNonVisualChangeByDeletingIds(pageIndexPath, pageContent);
|
|
437356
437369
|
this.emit("addPage", pageIndexPath);
|
|
@@ -437477,173 +437490,7 @@ export default registerPage(Page, { name: "${name18}" });
|
|
|
437477
437490
|
this.flushTransactions();
|
|
437478
437491
|
return returnValues;
|
|
437479
437492
|
};
|
|
437480
|
-
|
|
437481
|
-
const { api } = payload;
|
|
437482
|
-
if (!this.sourceTracker) {
|
|
437483
|
-
throw new Error("Source tracker not initialized");
|
|
437484
|
-
}
|
|
437485
|
-
if (!this.rootDir) {
|
|
437486
|
-
throw new Error("Root directory not set");
|
|
437487
|
-
}
|
|
437488
|
-
if (!api.pageName) {
|
|
437489
|
-
throw new Error("API page name is not set");
|
|
437490
|
-
}
|
|
437491
|
-
const apiName = api.apiPb.metadata.name;
|
|
437492
|
-
if (!apiName) {
|
|
437493
|
-
throw new Error("API name is not set");
|
|
437494
|
-
}
|
|
437495
|
-
const apiDir = path27.join(this.rootDir, "pages", api.pageName, "apis", apiName);
|
|
437496
|
-
const apiPath = path27.join(apiDir, "api.yaml");
|
|
437497
|
-
const isNewApi = !this.getApiFiles()[apiPath];
|
|
437498
|
-
try {
|
|
437499
|
-
const stats = await fs12.stat(apiDir);
|
|
437500
|
-
if (!stats.isDirectory()) {
|
|
437501
|
-
await fs12.mkdir(apiDir, { recursive: true });
|
|
437502
|
-
}
|
|
437503
|
-
} catch {
|
|
437504
|
-
await fs12.mkdir(apiDir, { recursive: true });
|
|
437505
|
-
}
|
|
437506
|
-
await this.writeFile(apiPath, import_yaml2.default.stringify(api.apiPb), "api");
|
|
437507
|
-
const generationNumber = this.generationNumberSequence.next();
|
|
437508
|
-
const apiDef = this.createClientApi(api);
|
|
437509
|
-
let scopeId = "";
|
|
437510
|
-
if (isNewApi) {
|
|
437511
|
-
scopeId = await this.createScopedApi(api);
|
|
437512
|
-
} else {
|
|
437513
|
-
const scopeDef = this.sourceTracker.getScopeDefinitionForPage(api.pageName);
|
|
437514
|
-
scopeId = scopeDef?.id ?? "";
|
|
437515
|
-
}
|
|
437516
|
-
this.emit("apiUpdate", { api: apiDef, scopeId });
|
|
437517
|
-
return { api: apiDef, scopeId, generationNumber };
|
|
437518
|
-
};
|
|
437519
|
-
createScopedApi = async (api) => {
|
|
437520
|
-
if (!this.sourceTracker) {
|
|
437521
|
-
throw new Error("Source tracker not initialized");
|
|
437522
|
-
}
|
|
437523
|
-
const scopeId = await this.sourceTracker.addApi({
|
|
437524
|
-
pageName: api.pageName,
|
|
437525
|
-
apiName: api.apiPb.metadata.name
|
|
437526
|
-
});
|
|
437527
|
-
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437528
|
-
await this.writeChanges(changes);
|
|
437529
|
-
return scopeId;
|
|
437530
|
-
};
|
|
437531
|
-
handleDeleteApi = async (payload) => {
|
|
437532
|
-
const logger3 = getLogger();
|
|
437533
|
-
const { apis } = payload;
|
|
437534
|
-
if (!this.rootDir) {
|
|
437535
|
-
throw new Error("Root directory not set");
|
|
437536
|
-
}
|
|
437537
|
-
const rootDir = this.rootDir;
|
|
437538
|
-
const executeDeleteApis = Promise.all(apis.map(({ apiName, pageName }) => {
|
|
437539
|
-
return new Promise(
|
|
437540
|
-
// eslint-disable-next-line no-async-promise-executor
|
|
437541
|
-
async (resolve9) => {
|
|
437542
|
-
const apiFilePath = path27.join(rootDir, "pages", pageName, "apis", apiName, "api.yaml");
|
|
437543
|
-
const api = this.apiFiles[apiFilePath];
|
|
437544
|
-
if (!api || !this.sourceTracker) {
|
|
437545
|
-
return resolve9(void 0);
|
|
437546
|
-
}
|
|
437547
|
-
const apiDir = path27.join(rootDir, "pages", pageName, "apis", apiName);
|
|
437548
|
-
try {
|
|
437549
|
-
const stats = await fs12.stat(apiDir);
|
|
437550
|
-
if (stats.isDirectory()) {
|
|
437551
|
-
await fs12.rmdir(apiDir, { recursive: true });
|
|
437552
|
-
}
|
|
437553
|
-
delete this.apiFiles[apiFilePath];
|
|
437554
|
-
const scopeId = this.sourceTracker.deleteApi({
|
|
437555
|
-
pageName,
|
|
437556
|
-
apiName
|
|
437557
|
-
});
|
|
437558
|
-
resolve9({
|
|
437559
|
-
apiName,
|
|
437560
|
-
pageName,
|
|
437561
|
-
scopeId
|
|
437562
|
-
});
|
|
437563
|
-
} catch (e) {
|
|
437564
|
-
logger3.warn(`Could not delete api ${apiFilePath} ${JSON.stringify(e)}`);
|
|
437565
|
-
resolve9(void 0);
|
|
437566
|
-
}
|
|
437567
|
-
resolve9(void 0);
|
|
437568
|
-
}
|
|
437569
|
-
);
|
|
437570
|
-
}));
|
|
437571
|
-
const deletedApis = (await executeDeleteApis).filter((api) => api !== void 0);
|
|
437572
|
-
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437573
|
-
await this.writeChanges(changes);
|
|
437574
|
-
this.emit("apiDelete", {
|
|
437575
|
-
apis: deletedApis.filter((api) => api !== void 0)
|
|
437576
|
-
});
|
|
437577
|
-
return { deletedApis };
|
|
437578
|
-
};
|
|
437579
|
-
handleRenameApi = async (payload) => {
|
|
437580
|
-
const { oldName, newName, pageName } = payload;
|
|
437581
|
-
if (!this.rootDir) {
|
|
437582
|
-
throw new Error("Root directory not set");
|
|
437583
|
-
}
|
|
437584
|
-
const pagePath = getPageFolder(this.rootDir, pageName);
|
|
437585
|
-
const existingApiFolder = path27.join(this.rootDir, "pages", pageName, "apis", oldName);
|
|
437586
|
-
const newApiFolder = path27.join(this.rootDir, "pages", pageName, "apis", newName);
|
|
437587
|
-
const files = this.sourceTracker?.getCurrentFiles();
|
|
437588
|
-
const file = files?.[path27.join(pagePath, "index.tsx")];
|
|
437589
|
-
if (!file || !file.ast) {
|
|
437590
|
-
throw new Error(`Page ${pageName} not found`);
|
|
437591
|
-
}
|
|
437592
|
-
const apiFilePath = path27.join(existingApiFolder, "api.yaml");
|
|
437593
|
-
const apiDef = this.apiFiles[apiFilePath];
|
|
437594
|
-
if (!apiDef) {
|
|
437595
|
-
throw new Error(`API ${oldName} not found`);
|
|
437596
|
-
}
|
|
437597
|
-
const otherPageAPIs = structuredClone(Object.keys(this.apiFiles).filter((path55) => path55.startsWith(pagePath) && path55 !== apiFilePath).map((path55) => ({
|
|
437598
|
-
api: { apiPb: this.apiFiles[path55]?.apiPb },
|
|
437599
|
-
filePath: path55
|
|
437600
|
-
})).filter((api) => !!api.api));
|
|
437601
|
-
const newApiFolderExists = await fs12.stat(newApiFolder).catch(() => false);
|
|
437602
|
-
if (newApiFolderExists) {
|
|
437603
|
-
throw new Error(`API ${newName} already exists`);
|
|
437604
|
-
}
|
|
437605
|
-
this.watcher?.unwatch(existingApiFolder);
|
|
437606
|
-
this.watcher?.unwatch(newApiFolder);
|
|
437607
|
-
apiDef.apiPb.metadata.name = newName;
|
|
437608
|
-
await fs12.rename(existingApiFolder, newApiFolder);
|
|
437609
|
-
const scopeDef = this.sourceTracker?.getScopeDefinitionForPage(pageName);
|
|
437610
|
-
if (!scopeDef) {
|
|
437611
|
-
throw new Error(`Scope definition not found for API`);
|
|
437612
|
-
}
|
|
437613
|
-
this.sourceTracker?.renameEntity({
|
|
437614
|
-
oldName,
|
|
437615
|
-
newName,
|
|
437616
|
-
entityId: scopeDef.scopeNameToEntityId[oldName]
|
|
437617
|
-
});
|
|
437618
|
-
delete this.apiFiles[apiFilePath];
|
|
437619
|
-
this.writeFile(path27.join(newApiFolder, "api.yaml"), import_yaml2.default.stringify(apiDef.apiPb), "api");
|
|
437620
|
-
this.watcher?.add(existingApiFolder);
|
|
437621
|
-
this.watcher?.add(newApiFolder);
|
|
437622
|
-
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437623
|
-
await this.writeChanges(changes);
|
|
437624
|
-
this.emit("apiManualUpdate", {
|
|
437625
|
-
api: this.createClientApi(apiDef),
|
|
437626
|
-
oldName,
|
|
437627
|
-
pageName,
|
|
437628
|
-
scopeId: scopeDef?.id ?? ""
|
|
437629
|
-
}, true);
|
|
437630
|
-
await this.renameManager.renameEntityInApis({
|
|
437631
|
-
oldName,
|
|
437632
|
-
newName,
|
|
437633
|
-
apis: otherPageAPIs
|
|
437634
|
-
});
|
|
437635
|
-
await Promise.all(otherPageAPIs.map(async ({ api, filePath }) => {
|
|
437636
|
-
if (isEqual_default(api?.apiPb, this.apiFiles[filePath]?.apiPb)) {
|
|
437637
|
-
return Promise.resolve();
|
|
437638
|
-
}
|
|
437639
|
-
await this.writeFile(filePath, import_yaml2.default.stringify(api?.apiPb), "api");
|
|
437640
|
-
this.emit("apiManualUpdate", {
|
|
437641
|
-
api: this.createClientApi(api),
|
|
437642
|
-
pageName,
|
|
437643
|
-
scopeId: scopeDef?.id ?? ""
|
|
437644
|
-
}, true);
|
|
437645
|
-
}));
|
|
437646
|
-
};
|
|
437493
|
+
// MARK: entity operations
|
|
437647
437494
|
handleAddEntity = async (payload) => {
|
|
437648
437495
|
this.sourceTracker?.addEntity({
|
|
437649
437496
|
scopeId: payload.scopeId,
|
|
@@ -437692,6 +437539,7 @@ export default registerPage(Page, { name: "${name18}" });
|
|
|
437692
437539
|
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437693
437540
|
await this.writeChanges(changes);
|
|
437694
437541
|
};
|
|
437542
|
+
// MARK: rename operations
|
|
437695
437543
|
handleRenameElement = async (payload) => {
|
|
437696
437544
|
if (payload.kind === "component") {
|
|
437697
437545
|
return this.handleRenameComponent(payload);
|
|
@@ -437767,93 +437615,195 @@ export default registerPage(Page, { name: "${name18}" });
|
|
|
437767
437615
|
this.watcher?.add(newPageFolder);
|
|
437768
437616
|
this.watcher?.add(oldPageFolder);
|
|
437769
437617
|
};
|
|
437770
|
-
|
|
437771
|
-
|
|
437772
|
-
|
|
437773
|
-
if (!currentFile) {
|
|
437774
|
-
return null;
|
|
437618
|
+
getRelativeRoutePath(filePath) {
|
|
437619
|
+
if (!this.rootDir) {
|
|
437620
|
+
throw new Error("Root directory not set");
|
|
437775
437621
|
}
|
|
437776
|
-
return
|
|
437622
|
+
return path27.relative(path27.join(this.rootDir, PAGES_DIRECTORY), filePath);
|
|
437777
437623
|
}
|
|
437778
|
-
|
|
437779
|
-
|
|
437780
|
-
const
|
|
437781
|
-
if (!
|
|
437782
|
-
|
|
437783
|
-
return null;
|
|
437624
|
+
// MARK: API operations
|
|
437625
|
+
handleUpdateApi = async (payload) => {
|
|
437626
|
+
const { api } = payload;
|
|
437627
|
+
if (!this.sourceTracker) {
|
|
437628
|
+
throw new Error("Source tracker not initialized");
|
|
437784
437629
|
}
|
|
437785
|
-
|
|
437786
|
-
|
|
437787
|
-
}
|
|
437788
|
-
getRoutes() {
|
|
437789
|
-
const routes = [];
|
|
437790
|
-
for (const [path55, { file }] of Object.entries(this.routes)) {
|
|
437791
|
-
routes.push({
|
|
437792
|
-
path: path55,
|
|
437793
|
-
component: file
|
|
437794
|
-
});
|
|
437630
|
+
if (!this.rootDir) {
|
|
437631
|
+
throw new Error("Root directory not set");
|
|
437795
437632
|
}
|
|
437796
|
-
|
|
437797
|
-
|
|
437798
|
-
|
|
437633
|
+
if (!api.pageName) {
|
|
437634
|
+
throw new Error("API page name is not set");
|
|
437635
|
+
}
|
|
437636
|
+
const apiName = api.apiPb.metadata.name;
|
|
437637
|
+
if (!apiName) {
|
|
437638
|
+
throw new Error("API name is not set");
|
|
437639
|
+
}
|
|
437640
|
+
const apiFilePath = getApiFilePath(this.rootDir, api.pageName, apiName);
|
|
437641
|
+
const apiDir = path27.dirname(apiFilePath);
|
|
437642
|
+
const isNewApi = !this.getApiFiles()[apiFilePath];
|
|
437643
|
+
try {
|
|
437644
|
+
const stats = await fs12.stat(apiDir);
|
|
437645
|
+
if (!stats.isDirectory()) {
|
|
437646
|
+
await this.fsOperationQueue.enqueue(async () => await fs12.mkdir(apiDir, { recursive: true }));
|
|
437647
|
+
}
|
|
437648
|
+
} catch {
|
|
437649
|
+
await this.fsOperationQueue.enqueue(async () => await fs12.mkdir(apiDir, { recursive: true }));
|
|
437650
|
+
}
|
|
437651
|
+
await this.writeFile(apiFilePath, import_yaml2.default.stringify(api.apiPb), "api");
|
|
437652
|
+
const generationNumber = this.generationNumberSequence.next();
|
|
437653
|
+
const apiDef = this.createClientApi(api);
|
|
437654
|
+
let scopeId = "";
|
|
437655
|
+
if (isNewApi) {
|
|
437656
|
+
scopeId = await this.addApiToScope(api);
|
|
437657
|
+
} else {
|
|
437658
|
+
const scopeDef = this.sourceTracker.getScopeDefinitionForPage(api.pageName);
|
|
437659
|
+
scopeId = scopeDef?.id ?? "";
|
|
437660
|
+
}
|
|
437661
|
+
this.emit("apiUpdate", { api: apiDef, scopeId });
|
|
437662
|
+
return { api: apiDef, scopeId, generationNumber };
|
|
437663
|
+
};
|
|
437664
|
+
handleDeleteApi = async (payload) => {
|
|
437665
|
+
const logger3 = getLogger();
|
|
437666
|
+
const { apis } = payload;
|
|
437799
437667
|
if (!this.rootDir) {
|
|
437800
437668
|
throw new Error("Root directory not set");
|
|
437801
437669
|
}
|
|
437802
|
-
|
|
437803
|
-
|
|
437804
|
-
|
|
437805
|
-
|
|
437670
|
+
const rootDir = this.rootDir;
|
|
437671
|
+
const deletedApis = [];
|
|
437672
|
+
for (const { apiName, pageName } of apis) {
|
|
437673
|
+
const apiFilePath = getApiFilePath(rootDir, pageName, apiName);
|
|
437674
|
+
const api = this.apiFiles[apiFilePath];
|
|
437675
|
+
if (!api || !this.sourceTracker) {
|
|
437676
|
+
continue;
|
|
437677
|
+
}
|
|
437678
|
+
const apiDir = path27.dirname(apiFilePath);
|
|
437679
|
+
try {
|
|
437680
|
+
const stats = await fs12.stat(apiDir);
|
|
437681
|
+
if (stats.isDirectory()) {
|
|
437682
|
+
await fs12.rmdir(apiDir, { recursive: true });
|
|
437683
|
+
}
|
|
437684
|
+
delete this.apiFiles[apiFilePath];
|
|
437685
|
+
const scopeId = this.sourceTracker.deleteApi({
|
|
437686
|
+
pageName,
|
|
437687
|
+
apiName
|
|
437688
|
+
});
|
|
437689
|
+
deletedApis.push({
|
|
437690
|
+
apiName,
|
|
437691
|
+
pageName,
|
|
437692
|
+
scopeId
|
|
437693
|
+
});
|
|
437694
|
+
} catch (e) {
|
|
437695
|
+
logger3.warn(`Could not delete api ${apiFilePath} ${JSON.stringify(e)}`);
|
|
437696
|
+
}
|
|
437697
|
+
}
|
|
437698
|
+
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437699
|
+
await this.writeChanges(changes);
|
|
437700
|
+
this.emit("apiDelete", {
|
|
437701
|
+
apis: deletedApis.filter((api) => api !== void 0)
|
|
437702
|
+
});
|
|
437703
|
+
return { deletedApis };
|
|
437704
|
+
};
|
|
437705
|
+
handleRenameApi = async (payload) => {
|
|
437706
|
+
const { oldName, newName, pageName } = payload;
|
|
437806
437707
|
if (!this.rootDir) {
|
|
437807
437708
|
throw new Error("Root directory not set");
|
|
437808
437709
|
}
|
|
437809
|
-
const
|
|
437810
|
-
|
|
437811
|
-
|
|
437812
|
-
|
|
437813
|
-
|
|
437814
|
-
|
|
437815
|
-
|
|
437816
|
-
return callback?.(fileName, source2);
|
|
437817
|
-
}));
|
|
437818
|
-
}
|
|
437819
|
-
getNodeForWidgetSourceId(id2) {
|
|
437820
|
-
return this.sourceTracker?.getElementToLocation(id2);
|
|
437821
|
-
}
|
|
437822
|
-
getAstForWidgetSourceId(id2) {
|
|
437823
|
-
const filePath = this.sourceTracker?.getElementToFilePath(id2);
|
|
437824
|
-
if (!filePath) {
|
|
437825
|
-
return null;
|
|
437710
|
+
const pagePath = getPageFolder(this.rootDir, pageName);
|
|
437711
|
+
const existingApiFolder = path27.join(this.rootDir, "pages", pageName, "apis", oldName);
|
|
437712
|
+
const newApiFolder = path27.join(this.rootDir, "pages", pageName, "apis", newName);
|
|
437713
|
+
const files = this.sourceTracker?.getCurrentFiles();
|
|
437714
|
+
const file = files?.[path27.join(pagePath, "index.tsx")];
|
|
437715
|
+
if (!file || !file.ast) {
|
|
437716
|
+
throw new Error(`Page ${pageName} not found`);
|
|
437826
437717
|
}
|
|
437827
|
-
|
|
437828
|
-
|
|
437829
|
-
|
|
437830
|
-
|
|
437718
|
+
const apiFilePath = path27.join(existingApiFolder, "api.yaml");
|
|
437719
|
+
const apiDef = this.apiFiles[apiFilePath];
|
|
437720
|
+
if (!apiDef) {
|
|
437721
|
+
throw new Error(`API ${oldName} not found`);
|
|
437722
|
+
}
|
|
437723
|
+
const otherPageAPIs = structuredClone(Object.keys(this.apiFiles).filter((path55) => path55.startsWith(pagePath) && path55 !== apiFilePath).map((path55) => ({
|
|
437724
|
+
api: { apiPb: this.apiFiles[path55]?.apiPb },
|
|
437725
|
+
filePath: path55
|
|
437726
|
+
})).filter((api) => !!api.api));
|
|
437727
|
+
const newApiFolderExists = await fs12.stat(newApiFolder).catch(() => false);
|
|
437728
|
+
if (newApiFolderExists) {
|
|
437729
|
+
throw new Error(`API ${newName} already exists`);
|
|
437730
|
+
}
|
|
437731
|
+
this.watcher?.unwatch(existingApiFolder);
|
|
437732
|
+
this.watcher?.unwatch(newApiFolder);
|
|
437733
|
+
apiDef.apiPb.metadata.name = newName;
|
|
437734
|
+
await fs12.rename(existingApiFolder, newApiFolder);
|
|
437735
|
+
const scopeDef = this.sourceTracker?.getScopeDefinitionForPage(pageName);
|
|
437736
|
+
if (!scopeDef) {
|
|
437737
|
+
throw new Error(`Scope definition not found for API`);
|
|
437738
|
+
}
|
|
437739
|
+
this.sourceTracker?.renameEntity({
|
|
437740
|
+
oldName,
|
|
437741
|
+
newName,
|
|
437742
|
+
entityId: scopeDef.scopeNameToEntityId[oldName]
|
|
437743
|
+
});
|
|
437744
|
+
delete this.apiFiles[apiFilePath];
|
|
437745
|
+
this.writeFile(path27.join(newApiFolder, "api.yaml"), import_yaml2.default.stringify(apiDef.apiPb), "api");
|
|
437746
|
+
this.watcher?.add(existingApiFolder);
|
|
437747
|
+
this.watcher?.add(newApiFolder);
|
|
437748
|
+
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437749
|
+
await this.writeChanges(changes);
|
|
437750
|
+
this.emit("apiManualUpdate", {
|
|
437751
|
+
api: this.createClientApi(apiDef),
|
|
437752
|
+
oldName,
|
|
437753
|
+
pageName,
|
|
437754
|
+
scopeId: scopeDef?.id ?? ""
|
|
437755
|
+
}, true);
|
|
437831
437756
|
await this.renameManager.renameEntityInApis({
|
|
437832
437757
|
oldName,
|
|
437833
437758
|
newName,
|
|
437834
|
-
|
|
437835
|
-
apis: apisInScope
|
|
437759
|
+
apis: otherPageAPIs
|
|
437836
437760
|
});
|
|
437837
|
-
await Promise.all(
|
|
437761
|
+
await Promise.all(otherPageAPIs.map(async ({ api, filePath }) => {
|
|
437838
437762
|
if (isEqual_default(api?.apiPb, this.apiFiles[filePath]?.apiPb)) {
|
|
437839
437763
|
return Promise.resolve();
|
|
437840
437764
|
}
|
|
437841
|
-
|
|
437765
|
+
await this.writeFile(filePath, import_yaml2.default.stringify(api?.apiPb), "api");
|
|
437766
|
+
this.emit("apiManualUpdate", {
|
|
437767
|
+
api: this.createClientApi(api),
|
|
437768
|
+
pageName,
|
|
437769
|
+
scopeId: scopeDef?.id ?? ""
|
|
437770
|
+
}, true);
|
|
437842
437771
|
}));
|
|
437843
437772
|
};
|
|
437844
|
-
|
|
437845
|
-
const
|
|
437846
|
-
if (!
|
|
437847
|
-
return
|
|
437848
|
-
}
|
|
437849
|
-
const pagePath = path27.dirname(filePath);
|
|
437850
|
-
return Object.entries(this.apiFiles).filter(([filePath2]) => filePath2.includes(pagePath)).map(([filePath2, api]) => ({ api, filePath: filePath2 }));
|
|
437851
|
-
};
|
|
437852
|
-
getRelativeRoutePath(filePath) {
|
|
437853
|
-
if (!this.rootDir) {
|
|
437854
|
-
throw new Error("Root directory not set");
|
|
437773
|
+
async removeApiData(filePath) {
|
|
437774
|
+
const api = this.apiFiles[filePath];
|
|
437775
|
+
if (!api) {
|
|
437776
|
+
return;
|
|
437855
437777
|
}
|
|
437856
|
-
|
|
437778
|
+
delete this.apiFiles[filePath];
|
|
437779
|
+
this.sourceTracker?.deleteApi({
|
|
437780
|
+
pageName: api.pageName,
|
|
437781
|
+
apiName: api.apiPb.metadata.name
|
|
437782
|
+
});
|
|
437783
|
+
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437784
|
+
await this.writeChanges(changes);
|
|
437785
|
+
const scopeId = this.sourceTracker?.getScopeDefinitionForPage(api.pageName)?.id;
|
|
437786
|
+
this.emit("apiManualDelete", {
|
|
437787
|
+
api: {
|
|
437788
|
+
id: getClientApiId(api.apiPb.metadata.name, api.pageName),
|
|
437789
|
+
apiName: api.apiPb.metadata.name,
|
|
437790
|
+
// TODO(saksham): get pagename more defensively
|
|
437791
|
+
pageName: getPageName2(filePath),
|
|
437792
|
+
scopeId
|
|
437793
|
+
}
|
|
437794
|
+
});
|
|
437795
|
+
}
|
|
437796
|
+
getApiFiles() {
|
|
437797
|
+
return Object.keys(this.apiFiles).reduce((acc, key2) => {
|
|
437798
|
+
if (!this.apiFiles[key2]) {
|
|
437799
|
+
return acc;
|
|
437800
|
+
}
|
|
437801
|
+
acc[key2] = {
|
|
437802
|
+
api: this.createClientApi(this.apiFiles[key2]),
|
|
437803
|
+
scopeId: this.apiFiles[key2].scopeId
|
|
437804
|
+
};
|
|
437805
|
+
return acc;
|
|
437806
|
+
}, {});
|
|
437857
437807
|
}
|
|
437858
437808
|
// Utilities for converting server API format to Client API format
|
|
437859
437809
|
// We internally save the API as the server does, but we return should always return it
|
|
@@ -437870,19 +437820,19 @@ export default registerPage(Page, { name: "${name18}" });
|
|
|
437870
437820
|
}
|
|
437871
437821
|
};
|
|
437872
437822
|
}
|
|
437873
|
-
|
|
437874
|
-
|
|
437875
|
-
|
|
437876
|
-
|
|
437877
|
-
|
|
437878
|
-
|
|
437879
|
-
|
|
437880
|
-
|
|
437881
|
-
|
|
437882
|
-
|
|
437883
|
-
|
|
437884
|
-
}
|
|
437885
|
-
async
|
|
437823
|
+
addApiToScope = async (api) => {
|
|
437824
|
+
if (!this.sourceTracker) {
|
|
437825
|
+
throw new Error("Source tracker not initialized");
|
|
437826
|
+
}
|
|
437827
|
+
const scopeId = await this.sourceTracker.addApi({
|
|
437828
|
+
pageName: api.pageName,
|
|
437829
|
+
apiName: api.apiPb.metadata.name
|
|
437830
|
+
});
|
|
437831
|
+
const changes = await this.sourceTracker?.getAndFlushChanges() ?? [];
|
|
437832
|
+
await this.writeChanges(changes);
|
|
437833
|
+
return scopeId;
|
|
437834
|
+
};
|
|
437835
|
+
async processApiFileUpdates(filePath, fileType) {
|
|
437886
437836
|
let yamlPath = filePath;
|
|
437887
437837
|
if (fileType.type === "python-api-step" || fileType.type === "js-api-step") {
|
|
437888
437838
|
const apiFolderPath = filePath.split("/").slice(0, -1).join("/");
|
|
@@ -437898,7 +437848,7 @@ export default registerPage(Page, { name: "${name18}" });
|
|
|
437898
437848
|
logger3.info(`API structure is valid: ${yamlPath}`);
|
|
437899
437849
|
const parsedData = { apiPb: apiContent?.api };
|
|
437900
437850
|
if (!(yamlPath in this.apiFiles && isEqual_default(this.apiFiles[yamlPath]?.apiPb, parsedData.apiPb))) {
|
|
437901
|
-
const { updatedApi, pageName, isNewApi } = this.
|
|
437851
|
+
const { updatedApi, pageName, isNewApi } = this.updateInternalApiData({
|
|
437902
437852
|
api: parsedData.apiPb,
|
|
437903
437853
|
stepPathMap: apiContent.stepPathMap
|
|
437904
437854
|
}, yamlPath);
|
|
@@ -437909,7 +437859,7 @@ export default registerPage(Page, { name: "${name18}" });
|
|
|
437909
437859
|
return;
|
|
437910
437860
|
}
|
|
437911
437861
|
if (isNewApi) {
|
|
437912
|
-
await this.
|
|
437862
|
+
await this.addApiToScope(updatedApi);
|
|
437913
437863
|
}
|
|
437914
437864
|
this.emit("apiManualUpdate", {
|
|
437915
437865
|
api: this.createClientApi(updatedApi),
|
|
@@ -437923,6 +437873,50 @@ export default registerPage(Page, { name: "${name18}" });
|
|
|
437923
437873
|
logger3.error(`Error updating API: ${yamlPath}, error: ${error}`);
|
|
437924
437874
|
}
|
|
437925
437875
|
}
|
|
437876
|
+
updateInternalApiData = (content2, path55) => {
|
|
437877
|
+
if (!this.rootDir) {
|
|
437878
|
+
throw new Error("Root directory not set");
|
|
437879
|
+
}
|
|
437880
|
+
const { api: apiContents, stepPathMap } = content2;
|
|
437881
|
+
const pageName = getPageName2(path55);
|
|
437882
|
+
let scopeId = this.sourceTracker?.getScopeDefinitionForPage(pageName)?.id;
|
|
437883
|
+
if (!scopeId) {
|
|
437884
|
+
console.warn("Scope ID not found for API", apiContents.metadata.name);
|
|
437885
|
+
scopeId = "";
|
|
437886
|
+
}
|
|
437887
|
+
const updatedApi = {
|
|
437888
|
+
apiPb: import_yaml2.default.parse(JSON.stringify(apiContents)),
|
|
437889
|
+
pageName,
|
|
437890
|
+
stepPathMap,
|
|
437891
|
+
scopeId
|
|
437892
|
+
};
|
|
437893
|
+
const isNewApi = !this.apiFiles[path55];
|
|
437894
|
+
this.apiFiles[path55] = updatedApi;
|
|
437895
|
+
return { updatedApi, pageName, isNewApi };
|
|
437896
|
+
};
|
|
437897
|
+
renameIdentifierInApis = async ({ elementId, oldName, newName, parentBinding }) => {
|
|
437898
|
+
const apisInScope = structuredClone(this.getApisInScope(elementId));
|
|
437899
|
+
await this.renameManager.renameEntityInApis({
|
|
437900
|
+
oldName,
|
|
437901
|
+
newName,
|
|
437902
|
+
parentBinding,
|
|
437903
|
+
apis: apisInScope
|
|
437904
|
+
});
|
|
437905
|
+
await Promise.all(apisInScope.map(({ api, filePath }) => {
|
|
437906
|
+
if (isEqual_default(api?.apiPb, this.apiFiles[filePath]?.apiPb)) {
|
|
437907
|
+
return Promise.resolve();
|
|
437908
|
+
}
|
|
437909
|
+
return this.writeFile(filePath, import_yaml2.default.stringify(api?.apiPb), "api");
|
|
437910
|
+
}));
|
|
437911
|
+
};
|
|
437912
|
+
getApisInScope = (elementId) => {
|
|
437913
|
+
const filePath = this.sourceTracker?.getElementToFilePath(elementId);
|
|
437914
|
+
if (!filePath) {
|
|
437915
|
+
return [];
|
|
437916
|
+
}
|
|
437917
|
+
const pagePath = path27.dirname(filePath);
|
|
437918
|
+
return Object.entries(this.apiFiles).filter(([filePath2]) => filePath2.includes(pagePath)).map(([filePath2, api]) => ({ api, filePath: filePath2 }));
|
|
437919
|
+
};
|
|
437926
437920
|
};
|
|
437927
437921
|
async function readFile6(path55) {
|
|
437928
437922
|
try {
|
|
@@ -442801,7 +442795,7 @@ var import_util30 = __toESM(require_dist3(), 1);
|
|
|
442801
442795
|
// ../sdk/package.json
|
|
442802
442796
|
var package_default = {
|
|
442803
442797
|
name: "@superblocksteam/sdk",
|
|
442804
|
-
version: "2.0.6-next.
|
|
442798
|
+
version: "2.0.6-next.24",
|
|
442805
442799
|
type: "module",
|
|
442806
442800
|
description: "Superblocks JS SDK",
|
|
442807
442801
|
homepage: "https://www.superblocks.com",
|
|
@@ -442842,11 +442836,11 @@ var package_default = {
|
|
|
442842
442836
|
"@opentelemetry/semantic-conventions": "^1.28.0",
|
|
442843
442837
|
"@rollup/wasm-node": "^4.35.0",
|
|
442844
442838
|
"@superblocksteam/bucketeer-sdk": "0.5.0",
|
|
442845
|
-
"@superblocksteam/library": "2.0.6-next.
|
|
442846
|
-
"@superblocksteam/library-shared": "2.0.6-next.
|
|
442839
|
+
"@superblocksteam/library": "2.0.6-next.24",
|
|
442840
|
+
"@superblocksteam/library-shared": "2.0.6-next.24",
|
|
442847
442841
|
"@superblocksteam/shared": "0.9198.0",
|
|
442848
|
-
"@superblocksteam/util": "2.0.6-next.
|
|
442849
|
-
"@superblocksteam/vite-plugin-file-sync": "2.0.6-next.
|
|
442842
|
+
"@superblocksteam/util": "2.0.6-next.24",
|
|
442843
|
+
"@superblocksteam/vite-plugin-file-sync": "2.0.6-next.24",
|
|
442850
442844
|
"@vitejs/plugin-react": "^4.3.4",
|
|
442851
442845
|
axios: "^1.4.0",
|
|
442852
442846
|
chokidar: "^4.0.3",
|
|
@@ -450418,7 +450412,7 @@ async function startVite({ app, httpServer: httpServer2, root: root2, mode, port
|
|
|
450418
450412
|
const isCustomBuildEnabled2 = await isCustomComponentsEnabled();
|
|
450419
450413
|
const customFolder = path37.join(root2, "custom");
|
|
450420
450414
|
const draftsFolder = path37.join(root2, ".superblocks");
|
|
450421
|
-
const cdnUrl = "https://assets-cdn.superblocks.com/library/2.0.6-next.
|
|
450415
|
+
const cdnUrl = "https://assets-cdn.superblocks.com/library/2.0.6-next.24";
|
|
450422
450416
|
const env3 = loadEnv(mode, root2, "");
|
|
450423
450417
|
const hmrPort = await getFreePort();
|
|
450424
450418
|
const hmrOptions = {
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superblocksteam/cli",
|
|
3
|
-
"version": "2.0.6-next.
|
|
3
|
+
"version": "2.0.6-next.24",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Official Superblocks CLI",
|
|
6
6
|
"homepage": "https://www.superblocks.com",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@eslint/js": "^9.16.0",
|
|
44
44
|
"@oclif/test": "^4.1.11",
|
|
45
|
-
"@superblocksteam/sdk": "2.0.6-next.
|
|
45
|
+
"@superblocksteam/sdk": "2.0.6-next.24",
|
|
46
46
|
"@superblocksteam/shared": "0.9198.0",
|
|
47
|
-
"@superblocksteam/util": "2.0.6-next.
|
|
47
|
+
"@superblocksteam/util": "2.0.6-next.24",
|
|
48
48
|
"@types/babel__core": "^7.20.0",
|
|
49
49
|
"@types/chai": "^4",
|
|
50
50
|
"@types/fs-extra": "^11.0.1",
|