@base44-preview/cli 0.1.9-pr.595.21d640d → 0.1.9-pr.601.94a154c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/index.js
CHANGED
|
@@ -247872,133 +247872,6 @@ var functionResource = {
|
|
|
247872
247872
|
readAll: readAllFunctions,
|
|
247873
247873
|
push: (functions) => deployFunctionsSequentially(functions)
|
|
247874
247874
|
};
|
|
247875
|
-
// src/core/resources/function/stream-api.ts
|
|
247876
|
-
var StreamLogEventSchema = exports_external.object({
|
|
247877
|
-
time: exports_external.string(),
|
|
247878
|
-
level: exports_external.preprocess((value) => value === "warn" ? "warning" : value, LogLevelSchema),
|
|
247879
|
-
function: exports_external.string().nullable(),
|
|
247880
|
-
message: exports_external.string()
|
|
247881
|
-
});
|
|
247882
|
-
var StreamEndEventSchema = exports_external.object({
|
|
247883
|
-
reason: exports_external.string(),
|
|
247884
|
-
retriable: exports_external.boolean()
|
|
247885
|
-
});
|
|
247886
|
-
function buildStreamUrl(filters) {
|
|
247887
|
-
const { id } = getAppContext();
|
|
247888
|
-
const url2 = new URL(`/api/apps/${id}/functions-mgmt/logs/stream`, getBase44ApiUrl());
|
|
247889
|
-
if (filters.functions?.length) {
|
|
247890
|
-
url2.searchParams.set("function", filters.functions.join(","));
|
|
247891
|
-
}
|
|
247892
|
-
if (filters.env) {
|
|
247893
|
-
url2.searchParams.set("env", filters.env);
|
|
247894
|
-
}
|
|
247895
|
-
return url2.href;
|
|
247896
|
-
}
|
|
247897
|
-
async function buildStreamAuthHeaders() {
|
|
247898
|
-
const workspaceApiKey = getWorkspaceApiKeyFromEnv();
|
|
247899
|
-
if (workspaceApiKey && isWorkspaceApiKey(workspaceApiKey)) {
|
|
247900
|
-
return { api_key: workspaceApiKey };
|
|
247901
|
-
}
|
|
247902
|
-
const auth = await readAuth();
|
|
247903
|
-
if (isTokenExpired(auth)) {
|
|
247904
|
-
const refreshedToken = await refreshAndSaveTokens();
|
|
247905
|
-
if (refreshedToken) {
|
|
247906
|
-
return { Authorization: `Bearer ${refreshedToken}` };
|
|
247907
|
-
}
|
|
247908
|
-
}
|
|
247909
|
-
return { Authorization: `Bearer ${auth.accessToken}` };
|
|
247910
|
-
}
|
|
247911
|
-
function parseStreamEvent(eventName, data) {
|
|
247912
|
-
try {
|
|
247913
|
-
const payload = JSON.parse(data);
|
|
247914
|
-
if (eventName === "end") {
|
|
247915
|
-
const result = StreamEndEventSchema.safeParse(payload);
|
|
247916
|
-
return result.success ? { kind: "end", end: result.data } : null;
|
|
247917
|
-
}
|
|
247918
|
-
if (eventName === "") {
|
|
247919
|
-
const result = StreamLogEventSchema.safeParse(payload);
|
|
247920
|
-
return result.success ? { kind: "log", log: result.data } : null;
|
|
247921
|
-
}
|
|
247922
|
-
return null;
|
|
247923
|
-
} catch {
|
|
247924
|
-
return null;
|
|
247925
|
-
}
|
|
247926
|
-
}
|
|
247927
|
-
var STREAM_SILENCE_TIMEOUT_MS = 60000;
|
|
247928
|
-
async function readOrSilence(reader) {
|
|
247929
|
-
let timer;
|
|
247930
|
-
const silence = new Promise((resolve3) => {
|
|
247931
|
-
timer = setTimeout(() => resolve3("silence"), STREAM_SILENCE_TIMEOUT_MS);
|
|
247932
|
-
});
|
|
247933
|
-
try {
|
|
247934
|
-
return await Promise.race([reader.read(), silence]);
|
|
247935
|
-
} finally {
|
|
247936
|
-
clearTimeout(timer);
|
|
247937
|
-
}
|
|
247938
|
-
}
|
|
247939
|
-
async function* readLines(body) {
|
|
247940
|
-
const reader = body.getReader();
|
|
247941
|
-
const decoder = new TextDecoder;
|
|
247942
|
-
let buffered = "";
|
|
247943
|
-
try {
|
|
247944
|
-
while (true) {
|
|
247945
|
-
const result = await readOrSilence(reader);
|
|
247946
|
-
if (result === "silence") {
|
|
247947
|
-
await reader.cancel();
|
|
247948
|
-
return;
|
|
247949
|
-
}
|
|
247950
|
-
if (result.done || !result.value)
|
|
247951
|
-
return;
|
|
247952
|
-
buffered += decoder.decode(result.value, { stream: true });
|
|
247953
|
-
const lines = buffered.split(`
|
|
247954
|
-
`);
|
|
247955
|
-
buffered = lines.pop() ?? "";
|
|
247956
|
-
yield* lines;
|
|
247957
|
-
}
|
|
247958
|
-
} finally {
|
|
247959
|
-
reader.releaseLock();
|
|
247960
|
-
}
|
|
247961
|
-
}
|
|
247962
|
-
async function* readStreamEvents(body) {
|
|
247963
|
-
let eventName = "";
|
|
247964
|
-
for await (const line of readLines(body)) {
|
|
247965
|
-
if (line.startsWith("event:")) {
|
|
247966
|
-
eventName = line.slice(6).trim();
|
|
247967
|
-
continue;
|
|
247968
|
-
}
|
|
247969
|
-
if (line.startsWith("data:")) {
|
|
247970
|
-
const event = parseStreamEvent(eventName, line.slice(5));
|
|
247971
|
-
eventName = "";
|
|
247972
|
-
if (event)
|
|
247973
|
-
yield event;
|
|
247974
|
-
continue;
|
|
247975
|
-
}
|
|
247976
|
-
if (line.trim() === "")
|
|
247977
|
-
eventName = "";
|
|
247978
|
-
}
|
|
247979
|
-
}
|
|
247980
|
-
var STREAM_CONNECT_TIMEOUT_MS = 1e4;
|
|
247981
|
-
async function openLogStream(filters) {
|
|
247982
|
-
const connectPhase = new AbortController;
|
|
247983
|
-
const connectTimer = setTimeout(() => connectPhase.abort(), STREAM_CONNECT_TIMEOUT_MS);
|
|
247984
|
-
let response;
|
|
247985
|
-
try {
|
|
247986
|
-
response = await fetch(buildStreamUrl(filters), {
|
|
247987
|
-
headers: {
|
|
247988
|
-
Accept: "text/event-stream",
|
|
247989
|
-
...await buildStreamAuthHeaders()
|
|
247990
|
-
},
|
|
247991
|
-
signal: connectPhase.signal
|
|
247992
|
-
});
|
|
247993
|
-
} catch {
|
|
247994
|
-
return null;
|
|
247995
|
-
} finally {
|
|
247996
|
-
clearTimeout(connectTimer);
|
|
247997
|
-
}
|
|
247998
|
-
if (!response.ok || !response.body)
|
|
247999
|
-
return null;
|
|
248000
|
-
return readStreamEvents(response.body);
|
|
248001
|
-
}
|
|
248002
247875
|
// src/core/project/config.ts
|
|
248003
247876
|
class ProjectConfigReader {
|
|
248004
247877
|
pluginSourceByNamespace = new Map;
|
|
@@ -248287,6 +248160,9 @@ function getTemplatesIndexPath() {
|
|
|
248287
248160
|
function getBackendRuntimeDir() {
|
|
248288
248161
|
return join12(ASSETS_DIR, "backend-runtime");
|
|
248289
248162
|
}
|
|
248163
|
+
function getImportMapPath() {
|
|
248164
|
+
return join12(getBackendRuntimeDir(), "import-map.json");
|
|
248165
|
+
}
|
|
248290
248166
|
function getDenoWrapperPath() {
|
|
248291
248167
|
return join12(getBackendRuntimeDir(), "main.ts");
|
|
248292
248168
|
}
|
|
@@ -258581,73 +258457,9 @@ function writeFollowLine(entry, jsonMode) {
|
|
|
258581
258457
|
process.stdout.write(`${line}
|
|
258582
258458
|
`);
|
|
258583
258459
|
}
|
|
258584
|
-
|
|
258585
|
-
|
|
258586
|
-
|
|
258587
|
-
time: event.time,
|
|
258588
|
-
level: event.level,
|
|
258589
|
-
message: event.function ? `[${event.function}] ${event.message}` : event.message,
|
|
258590
|
-
source: event.function ?? ""
|
|
258591
|
-
};
|
|
258592
|
-
}
|
|
258593
|
-
async function printStreamUntilEnd(stream, levelFilter, jsonMode, startTime) {
|
|
258594
|
-
let lastTime = startTime;
|
|
258595
|
-
let producedEvents = false;
|
|
258596
|
-
try {
|
|
258597
|
-
for await (const event of stream) {
|
|
258598
|
-
producedEvents = true;
|
|
258599
|
-
if (event.kind === "end")
|
|
258600
|
-
return { lastTime, producedEvents, end: event.end };
|
|
258601
|
-
if (levelFilter && event.log.level !== levelFilter)
|
|
258602
|
-
continue;
|
|
258603
|
-
writeFollowLine(streamEventToLogEntry(event.log), jsonMode);
|
|
258604
|
-
if (event.log.time > lastTime)
|
|
258605
|
-
lastTime = event.log.time;
|
|
258606
|
-
}
|
|
258607
|
-
} catch {}
|
|
258608
|
-
return { lastTime, producedEvents, end: null };
|
|
258609
|
-
}
|
|
258610
|
-
var STREAM_RECONNECT_DELAY_MS = 1000;
|
|
258611
|
-
var MAX_DROPS_SINCE_LAST_EVENT = 2;
|
|
258612
|
-
async function streamUntilExhausted(options, jsonMode) {
|
|
258613
|
-
const filters = {
|
|
258614
|
-
functions: parseFunctionNames(options.function),
|
|
258615
|
-
env: options.env
|
|
258616
|
-
};
|
|
258617
|
-
let everConnected = false;
|
|
258618
|
-
let lastTime = "";
|
|
258619
|
-
let dropsSinceLastEvent = 0;
|
|
258620
|
-
while (true) {
|
|
258621
|
-
const stream = await openLogStream(filters);
|
|
258622
|
-
if (!stream)
|
|
258623
|
-
break;
|
|
258624
|
-
everConnected = true;
|
|
258625
|
-
const ending = await printStreamUntilEnd(stream, options.level, jsonMode, lastTime);
|
|
258626
|
-
lastTime = ending.lastTime;
|
|
258627
|
-
if (ending.end) {
|
|
258628
|
-
if (!ending.end.retriable)
|
|
258629
|
-
break;
|
|
258630
|
-
dropsSinceLastEvent = 0;
|
|
258631
|
-
} else {
|
|
258632
|
-
dropsSinceLastEvent = ending.producedEvents ? 1 : dropsSinceLastEvent + 1;
|
|
258633
|
-
if (dropsSinceLastEvent >= MAX_DROPS_SINCE_LAST_EVENT)
|
|
258634
|
-
break;
|
|
258635
|
-
}
|
|
258636
|
-
await delay2(STREAM_RECONNECT_DELAY_MS);
|
|
258637
|
-
}
|
|
258638
|
-
return { everConnected, lastTime };
|
|
258639
|
-
}
|
|
258640
|
-
async function followLogs(functionNames, options, availableFunctionNames, jsonMode, logger2) {
|
|
258641
|
-
const { everConnected, lastTime } = await streamUntilExhausted(options, jsonMode);
|
|
258642
|
-
logger2.warn(everConnected ? "Realtime stream disconnected — falling back to polling (lines may lag ~20-30s)." : "Realtime stream unavailable — falling back to polling (lines may lag ~20-30s).");
|
|
258643
|
-
return pollLogs(functionNames, options, availableFunctionNames, jsonMode, {
|
|
258644
|
-
lastTime,
|
|
258645
|
-
boundaryKeys: new Set
|
|
258646
|
-
});
|
|
258647
|
-
}
|
|
258648
|
-
async function pollLogs(functionNames, options, availableFunctionNames, jsonMode, initialState) {
|
|
258649
|
-
let state = initialState;
|
|
258650
|
-
let first = state.lastTime === "";
|
|
258460
|
+
async function followLogs(functionNames, options, availableFunctionNames, jsonMode) {
|
|
258461
|
+
let state = { lastTime: "", boundaryKeys: new Set };
|
|
258462
|
+
let first = true;
|
|
258651
258463
|
while (true) {
|
|
258652
258464
|
const pollOptions = first ? options : { ...options, since: state.lastTime };
|
|
258653
258465
|
const entries = await fetchLogsForFunctions(functionNames, pollOptions, availableFunctionNames);
|
|
@@ -258657,7 +258469,7 @@ async function pollLogs(functionNames, options, availableFunctionNames, jsonMode
|
|
|
258657
258469
|
for (const entry of fresh)
|
|
258658
258470
|
writeFollowLine(entry, jsonMode);
|
|
258659
258471
|
first = false;
|
|
258660
|
-
await
|
|
258472
|
+
await new Promise((resolve9) => setTimeout(resolve9, 2000));
|
|
258661
258473
|
}
|
|
258662
258474
|
}
|
|
258663
258475
|
function formatLogs(entries, env3) {
|
|
@@ -258743,9 +258555,6 @@ async function logsAction(ctx, options) {
|
|
|
258743
258555
|
};
|
|
258744
258556
|
}
|
|
258745
258557
|
if (options.follow) {
|
|
258746
|
-
if (options.since) {
|
|
258747
|
-
throw new InvalidInputError("--since cannot be combined with --follow yet (the realtime stream starts from now).");
|
|
258748
|
-
}
|
|
258749
258558
|
if (options.until) {
|
|
258750
258559
|
throw new InvalidInputError("--until cannot be combined with --follow (a stream has no end).");
|
|
258751
258560
|
}
|
|
@@ -258753,7 +258562,7 @@ async function logsAction(ctx, options) {
|
|
|
258753
258562
|
throw new InvalidInputError("--order cannot be combined with --follow (a live tail always streams oldest to newest).");
|
|
258754
258563
|
}
|
|
258755
258564
|
options.order = "asc";
|
|
258756
|
-
return followLogs(functionNames, options, availableFunctionNames, ctx.jsonMode
|
|
258565
|
+
return followLogs(functionNames, options, availableFunctionNames, ctx.jsonMode);
|
|
258757
258566
|
}
|
|
258758
258567
|
let entries = await fetchLogsForFunctions(functionNames, options, availableFunctionNames);
|
|
258759
258568
|
const limit = options.limit ? Number.parseInt(options.limit, 10) : undefined;
|
|
@@ -263901,9 +263710,17 @@ async function runScript(options8) {
|
|
|
263901
263710
|
const tempWrapper = await $file({ postfix: ".ts" });
|
|
263902
263711
|
cleanupFns.push(tempWrapper.cleanup);
|
|
263903
263712
|
copyFileSync(getExecWrapperPath(), tempWrapper.path);
|
|
263713
|
+
const importMapPath = getImportMapPath();
|
|
263904
263714
|
try {
|
|
263905
263715
|
const exitCode = await new Promise((resolvePromise) => {
|
|
263906
|
-
const child = spawn4("deno", [
|
|
263716
|
+
const child = spawn4("deno", [
|
|
263717
|
+
"run",
|
|
263718
|
+
"--allow-all",
|
|
263719
|
+
"--node-modules-dir=auto",
|
|
263720
|
+
"--import-map",
|
|
263721
|
+
importMapPath,
|
|
263722
|
+
tempWrapper.path
|
|
263723
|
+
], {
|
|
263907
263724
|
env: {
|
|
263908
263725
|
...process.env,
|
|
263909
263726
|
SCRIPT_PATH: scriptPath,
|
|
@@ -268402,4 +268219,4 @@ export {
|
|
|
268402
268219
|
CLIExitError
|
|
268403
268220
|
};
|
|
268404
268221
|
|
|
268405
|
-
//# debugId=
|
|
268222
|
+
//# debugId=E702492ECF74B8D164756E2164756E21
|