@base44-preview/cli 0.1.32-pr.663.7602773 → 0.1.32-pr.663.8c44c88
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 +306 -64
- package/dist/cli/index.js.map +19 -18
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -249106,12 +249106,7 @@ var BOOST = { path: 8, summary: 5, description: 2, parameters: 0.5 };
|
|
|
249106
249106
|
var MIN_RELATIVE_SCORE = 0.2;
|
|
249107
249107
|
var TOKEN_SEPARATOR = /[\n\r\p{Z}\p{P}\p{S}]+/u;
|
|
249108
249108
|
function toOperationSummary(op) {
|
|
249109
|
-
return {
|
|
249110
|
-
method: op.method,
|
|
249111
|
-
path: op.path,
|
|
249112
|
-
summary: op.summary,
|
|
249113
|
-
readOnly: op.readOnly
|
|
249114
|
-
};
|
|
249109
|
+
return { endpoint: op.endpoint, summary: op.summary };
|
|
249115
249110
|
}
|
|
249116
249111
|
function buildSearchIndex(operations) {
|
|
249117
249112
|
const index = new MiniSearch({
|
|
@@ -249166,11 +249161,15 @@ function groupByArea(operations) {
|
|
|
249166
249161
|
}
|
|
249167
249162
|
return new Map([...areas].sort(([a], [b]) => byCodePoint(a, b)));
|
|
249168
249163
|
}
|
|
249164
|
+
function readsFirst(ops) {
|
|
249165
|
+
const isRead = (op) => op.method === "GET" ? 0 : 1;
|
|
249166
|
+
return [...ops].sort((a, b) => isRead(a) - isRead(b));
|
|
249167
|
+
}
|
|
249169
249168
|
function catalogIndex(operations) {
|
|
249170
249169
|
const areas = [...groupByArea(operations)].map(([area, ops]) => ops.length <= INLINE_AREA_MAX ? { area, operations: ops.map(toOperationSummary) } : {
|
|
249171
249170
|
area,
|
|
249172
249171
|
operationCount: ops.length,
|
|
249173
|
-
sample: ops.slice(0, AREA_SAMPLE_MAX).map((op) => op.summary)
|
|
249172
|
+
sample: readsFirst(ops).slice(0, AREA_SAMPLE_MAX).map((op) => op.summary)
|
|
249174
249173
|
});
|
|
249175
249174
|
return { areas, total: operations.length };
|
|
249176
249175
|
}
|
|
@@ -249178,12 +249177,15 @@ function catalogIndex(operations) {
|
|
|
249178
249177
|
var CONTEXT_CHARS = 40;
|
|
249179
249178
|
var MAX_SNIPPETS = 3;
|
|
249180
249179
|
var MAX_SNIPPET_CHARS = 200;
|
|
249180
|
+
function unescapeJson(snippet) {
|
|
249181
|
+
return snippet.replace(/\\[nrt]/g, " ").replace(/\\"/g, '"');
|
|
249182
|
+
}
|
|
249181
249183
|
function snippets(text, pattern) {
|
|
249182
249184
|
const found = [];
|
|
249183
249185
|
for (const match of text.matchAll(pattern)) {
|
|
249184
249186
|
const start = Math.max(0, match.index - CONTEXT_CHARS);
|
|
249185
249187
|
const end = match.index + match[0].length + CONTEXT_CHARS;
|
|
249186
|
-
found.push(text.slice(start, Math.min(end, start + MAX_SNIPPET_CHARS)));
|
|
249188
|
+
found.push(unescapeJson(text.slice(start, Math.min(end, start + MAX_SNIPPET_CHARS))));
|
|
249187
249189
|
if (found.length === MAX_SNIPPETS || match[0].length === 0) {
|
|
249188
249190
|
break;
|
|
249189
249191
|
}
|
|
@@ -249193,14 +249195,15 @@ function snippets(text, pattern) {
|
|
|
249193
249195
|
function grepSpec(spec, operations, pattern, options = {}) {
|
|
249194
249196
|
const regex = new RegExp(pattern, options.ignoreCase ? "gi" : "g");
|
|
249195
249197
|
const hits = [];
|
|
249196
|
-
const
|
|
249197
|
-
for (const op of operations.filter(
|
|
249198
|
-
const
|
|
249198
|
+
const selected = (op) => (options.area === undefined || areaOf(op.path) === options.area) && (!options.readOnly || op.readOnly);
|
|
249199
|
+
for (const op of operations.filter(selected)) {
|
|
249200
|
+
const { summary, description, parameters, requestBody, responses } = op.operation;
|
|
249201
|
+
const matches = snippets(`${op.endpoint} ${JSON.stringify({ summary, description, parameters, requestBody, responses })}`, regex);
|
|
249199
249202
|
if (matches.length > 0) {
|
|
249200
249203
|
hits.push({ ...toOperationSummary(op), matches });
|
|
249201
249204
|
}
|
|
249202
249205
|
}
|
|
249203
|
-
const schemas = options.area === undefined ? spec.components?.schemas : {};
|
|
249206
|
+
const schemas = options.area === undefined && !options.readOnly ? spec.components?.schemas : {};
|
|
249204
249207
|
for (const [schema, definition] of Object.entries(schemas ?? {})) {
|
|
249205
249208
|
const matches = snippets(JSON.stringify(definition), regex);
|
|
249206
249209
|
if (matches.length > 0) {
|
|
@@ -249225,7 +249228,16 @@ var ParameterSchema = looseObject({
|
|
|
249225
249228
|
in: string2(),
|
|
249226
249229
|
required: boolean2().optional(),
|
|
249227
249230
|
description: string2().optional(),
|
|
249228
|
-
schema: unknown().optional()
|
|
249231
|
+
schema: unknown().optional(),
|
|
249232
|
+
example: unknown().optional()
|
|
249233
|
+
});
|
|
249234
|
+
var MediaTypesSchema = record(string2(), looseObject({ schema: unknown().optional() }));
|
|
249235
|
+
var RequestBodySchema = looseObject({
|
|
249236
|
+
content: MediaTypesSchema.optional()
|
|
249237
|
+
});
|
|
249238
|
+
var ResponseObjectSchema = looseObject({
|
|
249239
|
+
description: string2().optional(),
|
|
249240
|
+
content: MediaTypesSchema.optional()
|
|
249229
249241
|
});
|
|
249230
249242
|
var SecurityRequirementSchema = record(string2(), array(string2()));
|
|
249231
249243
|
var OperationSchema = looseObject({
|
|
@@ -249268,6 +249280,7 @@ function listOperations(spec) {
|
|
|
249268
249280
|
}
|
|
249269
249281
|
return [
|
|
249270
249282
|
{
|
|
249283
|
+
endpoint: `${method.toUpperCase()} ${path}`,
|
|
249271
249284
|
method: method.toUpperCase(),
|
|
249272
249285
|
path,
|
|
249273
249286
|
summary: operation.summary ?? "",
|
|
@@ -249310,46 +249323,73 @@ function matchOperation(operations, method, concretePath) {
|
|
|
249310
249323
|
});
|
|
249311
249324
|
return candidates.sort((a, b) => compareSpecificity(specificity(pathSegments(a.path)), specificity(pathSegments(b.path))))[0];
|
|
249312
249325
|
}
|
|
249313
|
-
|
|
249314
|
-
|
|
249315
|
-
|
|
249316
|
-
|
|
249317
|
-
|
|
249318
|
-
return;
|
|
249326
|
+
var SCHEMA_REF_PREFIX = "#/components/schemas/";
|
|
249327
|
+
var MAX_REF_DEPTH = 4;
|
|
249328
|
+
var FRAMEWORK_VALIDATION_ERROR = "Validation Error";
|
|
249329
|
+
function inlineRefs(node, schemas, seen = new Set, depth = 0) {
|
|
249330
|
+
if (depth > MAX_REF_DEPTH) {
|
|
249331
|
+
return node;
|
|
249319
249332
|
}
|
|
249320
|
-
if (
|
|
249321
|
-
return;
|
|
249333
|
+
if (Array.isArray(node)) {
|
|
249334
|
+
return node.map((item) => inlineRefs(item, schemas, seen, depth));
|
|
249322
249335
|
}
|
|
249323
|
-
|
|
249324
|
-
|
|
249325
|
-
|
|
249326
|
-
|
|
249327
|
-
|
|
249328
|
-
|
|
249329
|
-
|
|
249336
|
+
if (node === null || typeof node !== "object") {
|
|
249337
|
+
return node;
|
|
249338
|
+
}
|
|
249339
|
+
const { $ref, ...siblings } = node;
|
|
249340
|
+
if (typeof $ref === "string" && $ref.startsWith(SCHEMA_REF_PREFIX)) {
|
|
249341
|
+
const name = $ref.slice(SCHEMA_REF_PREFIX.length);
|
|
249342
|
+
if (seen.has(name) || !(name in schemas)) {
|
|
249343
|
+
return node;
|
|
249330
249344
|
}
|
|
249345
|
+
const resolved = inlineRefs(schemas[name], schemas, new Set([...seen, name]), depth + 1);
|
|
249346
|
+
return resolved !== null && typeof resolved === "object" ? { ...resolved, ...siblings } : resolved;
|
|
249331
249347
|
}
|
|
249348
|
+
return Object.fromEntries(Object.entries(node).map(([key, value]) => [
|
|
249349
|
+
key,
|
|
249350
|
+
inlineRefs(value, schemas, seen, depth)
|
|
249351
|
+
]));
|
|
249332
249352
|
}
|
|
249333
|
-
function
|
|
249334
|
-
|
|
249335
|
-
|
|
249336
|
-
}
|
|
249337
|
-
return ref.slice(2).split("/").map((part) => part.replace(/~1/g, "/").replace(/~0/g, "~")).reduce((node, part) => node !== null && typeof node === "object" ? node[part] : undefined, spec);
|
|
249353
|
+
function jsonSchemaOf(value) {
|
|
249354
|
+
const parsed = RequestBodySchema.safeParse(value);
|
|
249355
|
+
return parsed.success ? parsed.data.content?.["application/json"]?.schema : undefined;
|
|
249338
249356
|
}
|
|
249339
249357
|
function getOperationContract(spec, op) {
|
|
249340
|
-
const
|
|
249341
|
-
const
|
|
249342
|
-
|
|
249358
|
+
const schemas = spec.components?.schemas ?? {};
|
|
249359
|
+
const inline = (node) => node === undefined ? null : inlineRefs(node, schemas);
|
|
249360
|
+
const responses = Object.entries(op.operation.responses ?? {}).flatMap(([status, response]) => {
|
|
249361
|
+
const parsed = ResponseObjectSchema.safeParse(response);
|
|
249362
|
+
return parsed.success ? [[status, parsed.data]] : [];
|
|
249363
|
+
});
|
|
249364
|
+
const success = responses.filter(([status]) => status.startsWith("2")).sort(([a], [b]) => a.localeCompare(b)).map(([, response]) => jsonSchemaOf(response)).find(Boolean);
|
|
249365
|
+
const errors = responses.filter(([status, response]) => !status.startsWith("2") && response.description !== FRAMEWORK_VALIDATION_ERROR);
|
|
249343
249366
|
return {
|
|
249367
|
+
endpoint: op.endpoint,
|
|
249344
249368
|
method: op.method,
|
|
249345
249369
|
path: op.path,
|
|
249346
249370
|
summary: op.summary,
|
|
249347
249371
|
description: op.description,
|
|
249348
|
-
|
|
249349
|
-
|
|
249350
|
-
|
|
249351
|
-
|
|
249352
|
-
|
|
249372
|
+
parameters: (op.operation.parameters ?? []).flatMap((parameter) => {
|
|
249373
|
+
const parsed = ParameterSchema.safeParse(parameter);
|
|
249374
|
+
if (!parsed.success) {
|
|
249375
|
+
return [];
|
|
249376
|
+
}
|
|
249377
|
+
const { name, in: location2, required, schema, description } = parsed.data;
|
|
249378
|
+
const inSchema = schema !== null && typeof schema === "object" && "description" in schema;
|
|
249379
|
+
return [
|
|
249380
|
+
{
|
|
249381
|
+
name,
|
|
249382
|
+
in: location2,
|
|
249383
|
+
required: required ?? false,
|
|
249384
|
+
schema: inline(schema ?? {}),
|
|
249385
|
+
...description && !inSchema ? { description } : {},
|
|
249386
|
+
..."example" in parsed.data ? { example: parsed.data.example } : {}
|
|
249387
|
+
}
|
|
249388
|
+
];
|
|
249389
|
+
}),
|
|
249390
|
+
requestBodySchema: inline(jsonSchemaOf(op.operation.requestBody)),
|
|
249391
|
+
responseSchema: inline(success),
|
|
249392
|
+
errors: Object.fromEntries(errors.map(([status, response]) => [status, response.description ?? ""]))
|
|
249353
249393
|
};
|
|
249354
249394
|
}
|
|
249355
249395
|
// src/core/api-spec/request.ts
|
|
@@ -249360,7 +249400,11 @@ async function sendApiRequest(method, path, body) {
|
|
|
249360
249400
|
body,
|
|
249361
249401
|
headers: body === undefined ? {} : { "Content-Type": "application/json" }
|
|
249362
249402
|
});
|
|
249363
|
-
return
|
|
249403
|
+
return {
|
|
249404
|
+
status: response.status,
|
|
249405
|
+
contentType: response.headers.get("content-type") ?? "",
|
|
249406
|
+
body: new Uint8Array(await response.arrayBuffer())
|
|
249407
|
+
};
|
|
249364
249408
|
} catch (error) {
|
|
249365
249409
|
throw await ApiError.fromHttpError(error, `calling ${method} ${path}`);
|
|
249366
249410
|
}
|
|
@@ -249421,18 +249465,6 @@ function formatJson(value) {
|
|
|
249421
249465
|
return `${JSON.stringify(value, null, process.stdout.isTTY ? 2 : undefined)}
|
|
249422
249466
|
`;
|
|
249423
249467
|
}
|
|
249424
|
-
function formatResponseBody(text) {
|
|
249425
|
-
if (!text) {
|
|
249426
|
-
return "";
|
|
249427
|
-
}
|
|
249428
|
-
try {
|
|
249429
|
-
return formatJson(JSON.parse(text));
|
|
249430
|
-
} catch {
|
|
249431
|
-
return text.endsWith(`
|
|
249432
|
-
`) ? text : `${text}
|
|
249433
|
-
`;
|
|
249434
|
-
}
|
|
249435
|
-
}
|
|
249436
249468
|
function parseLimit(value) {
|
|
249437
249469
|
if (value === undefined) {
|
|
249438
249470
|
return;
|
|
@@ -249443,6 +249475,7 @@ function parseLimit(value) {
|
|
|
249443
249475
|
}
|
|
249444
249476
|
return n;
|
|
249445
249477
|
}
|
|
249478
|
+
var READ_ONLY_FILTER_HELP = "Only read-only operations";
|
|
249446
249479
|
var REFRESH_OPTION_HELP = "Fetch the API spec again instead of using the cached copy (kept 1 hour)";
|
|
249447
249480
|
function loadSpecTask({ runTask }, refresh) {
|
|
249448
249481
|
return runTask("Loading the API spec", () => loadSpec({ refresh }), {
|
|
@@ -249480,7 +249513,7 @@ async function readRequestBody(method, flag) {
|
|
|
249480
249513
|
// src/cli/commands/api/catalog.ts
|
|
249481
249514
|
async function catalogAction(ctx, area, options) {
|
|
249482
249515
|
const { spec } = await loadSpecTask(ctx, options.refresh);
|
|
249483
|
-
const operations = listOperations(spec);
|
|
249516
|
+
const operations = listOperations(spec).filter((op) => !options.readOnly || op.readOnly);
|
|
249484
249517
|
if (area === undefined) {
|
|
249485
249518
|
return { stdout: formatJson(catalogIndex(operations)) };
|
|
249486
249519
|
}
|
|
@@ -249497,7 +249530,7 @@ function getApiCatalogCommand() {
|
|
|
249497
249530
|
return new Base44Command("catalog", {
|
|
249498
249531
|
requireAuth: false,
|
|
249499
249532
|
requireAppContext: false
|
|
249500
|
-
}).description("List the API's areas, or every operation in one area
|
|
249533
|
+
}).description("List the API's areas, or every operation in one area").argument("[area]", 'An area from the list, e.g. "workflows"').option("--read-only", READ_ONLY_FILTER_HELP).option("--refresh", REFRESH_OPTION_HELP).action(catalogAction);
|
|
249501
249534
|
}
|
|
249502
249535
|
|
|
249503
249536
|
// src/cli/commands/api/fetch.ts
|
|
@@ -249516,6 +249549,36 @@ async function findOperation(ctx, method, path, refresh) {
|
|
|
249516
249549
|
}
|
|
249517
249550
|
return { spec, op };
|
|
249518
249551
|
}
|
|
249552
|
+
var TEXT_CONTENT_TYPES = [
|
|
249553
|
+
"json",
|
|
249554
|
+
"text/",
|
|
249555
|
+
"xml",
|
|
249556
|
+
"javascript",
|
|
249557
|
+
"x-www-form-urlencoded"
|
|
249558
|
+
];
|
|
249559
|
+
function isText(contentType) {
|
|
249560
|
+
return !contentType || TEXT_CONTENT_TYPES.some((hint) => contentType.toLowerCase().includes(hint));
|
|
249561
|
+
}
|
|
249562
|
+
async function formatResponse({ status, contentType, body }, output) {
|
|
249563
|
+
if (output !== undefined) {
|
|
249564
|
+
await writeFile(output, body);
|
|
249565
|
+
return formatJson({ status, contentType, bytes: body.length, output });
|
|
249566
|
+
}
|
|
249567
|
+
if (body.length === 0) {
|
|
249568
|
+
return formatJson({ status });
|
|
249569
|
+
}
|
|
249570
|
+
if (!isText(contentType)) {
|
|
249571
|
+
throw new InvalidInputError(`The response is binary (${contentType}, ${body.length} bytes), so it was not printed. The request was sent; add --output <file> to save the response.`);
|
|
249572
|
+
}
|
|
249573
|
+
const text = new TextDecoder().decode(body);
|
|
249574
|
+
try {
|
|
249575
|
+
return formatJson(JSON.parse(text));
|
|
249576
|
+
} catch {
|
|
249577
|
+
return text.endsWith(`
|
|
249578
|
+
`) ? text : `${text}
|
|
249579
|
+
`;
|
|
249580
|
+
}
|
|
249581
|
+
}
|
|
249519
249582
|
async function fetchAction(ctx, methodArg, path, options, command) {
|
|
249520
249583
|
if (!methodArg || !path) {
|
|
249521
249584
|
if (options.help) {
|
|
@@ -249536,14 +249599,17 @@ async function fetchAction(ctx, methodArg, path, options, command) {
|
|
|
249536
249599
|
}
|
|
249537
249600
|
await ensureAuth(ctx);
|
|
249538
249601
|
const body = await readRequestBody(method, options.body);
|
|
249539
|
-
const
|
|
249540
|
-
|
|
249602
|
+
const response = await ctx.runTask(`Calling ${method} ${path}`, () => sendApiRequest(method, path, body), {
|
|
249603
|
+
successMessage: `Called ${method} ${path}`,
|
|
249604
|
+
errorMessage: "Request failed"
|
|
249605
|
+
});
|
|
249606
|
+
return { stdout: await formatResponse(response, options.output) };
|
|
249541
249607
|
}
|
|
249542
249608
|
function getApiFetchCommand() {
|
|
249543
249609
|
return new Base44Command("fetch", {
|
|
249544
249610
|
requireAuth: false,
|
|
249545
249611
|
requireAppContext: false
|
|
249546
|
-
}).description("Call a Base44 API operation, like curl; add --help after a path for its contract").helpOption(false).argument("[method]", "HTTP method, e.g. GET or POST").argument("[path]", 'Concrete path with any query string, e.g. "/api/apps/<app-id>/workflows/runs?status=failed"').option("--body <json>", "Request body: JSON, @file.json, or @- for stdin (piped stdin is read too)").option("--read-only", "Refuse, before sending, any operation the spec does not mark read-only").option("--refresh", REFRESH_OPTION_HELP).option("-h, --help", "With a method and path, print that operation's contract; otherwise this help").action(fetchAction);
|
|
249612
|
+
}).description("Call a Base44 API operation, like curl; add --help after a path for its contract").helpOption(false).argument("[method]", "HTTP method, e.g. GET or POST").argument("[path]", 'Concrete path with any query string, e.g. "/api/apps/<app-id>/workflows/runs?status=failed"').option("--body <json>", "Request body: JSON, @file.json, or @- for stdin (piped stdin is read too)").option("--output <file>", "Save the response body to a file").option("--read-only", "Refuse, before sending, any operation the spec does not mark read-only").option("--refresh", REFRESH_OPTION_HELP).option("-h, --help", "With a method and path, print that operation's contract; otherwise this help").action(fetchAction);
|
|
249547
249613
|
}
|
|
249548
249614
|
|
|
249549
249615
|
// src/cli/commands/api/grep.ts
|
|
@@ -249565,7 +249631,8 @@ async function grepAction(ctx, pattern, options) {
|
|
|
249565
249631
|
const hits = grepSpec(spec, operations, pattern, {
|
|
249566
249632
|
area: options.area,
|
|
249567
249633
|
ignoreCase: options.ignoreCase,
|
|
249568
|
-
limit
|
|
249634
|
+
limit,
|
|
249635
|
+
readOnly: options.readOnly
|
|
249569
249636
|
});
|
|
249570
249637
|
return { stdout: formatJson(hits) };
|
|
249571
249638
|
}
|
|
@@ -249573,7 +249640,7 @@ function getApiGrepCommand() {
|
|
|
249573
249640
|
return new Base44Command("grep", {
|
|
249574
249641
|
requireAuth: false,
|
|
249575
249642
|
requireAppContext: false
|
|
249576
|
-
}).description("Search the raw API spec with a regular expression, for when search misses").argument("<pattern>", 'Regular expression, e.g. "runs.*status"').option("--area <area>", "Search only one area's operations (see base44 api catalog)").option("-i, --ignore-case", "Case-insensitive match").option("--limit <n>", "Most operations or schemas to return (default 20)").option("--refresh", REFRESH_OPTION_HELP).action(grepAction);
|
|
249643
|
+
}).description("Search the raw API spec with a regular expression, for when search misses").argument("<pattern>", 'Regular expression, e.g. "runs.*status"').option("--area <area>", "Search only one area's operations (see base44 api catalog)").option("-i, --ignore-case", "Case-insensitive match").option("--limit <n>", "Most operations or schemas to return (default 20)").option("--read-only", READ_ONLY_FILTER_HELP).option("--refresh", REFRESH_OPTION_HELP).action(grepAction);
|
|
249577
249644
|
}
|
|
249578
249645
|
|
|
249579
249646
|
// src/cli/commands/api/search.ts
|
|
@@ -249590,7 +249657,7 @@ function getApiSearchCommand() {
|
|
|
249590
249657
|
return new Base44Command("search", {
|
|
249591
249658
|
requireAuth: false,
|
|
249592
249659
|
requireAppContext: false
|
|
249593
|
-
}).description("Search every Base44 API operation by what it does").argument("<text...>", 'What you are looking for, e.g. "failed workflow runs"').option("--limit <n>", "Most results to return (default 5)").option("--read-only",
|
|
249660
|
+
}).description("Search every Base44 API operation by what it does").argument("<text...>", 'What you are looking for, e.g. "failed workflow runs"').option("--limit <n>", "Most results to return (default 5)").option("--read-only", READ_ONLY_FILTER_HELP).option("--refresh", REFRESH_OPTION_HELP).action(searchAction);
|
|
249594
249661
|
}
|
|
249595
249662
|
|
|
249596
249663
|
// src/cli/commands/api/index.ts
|
|
@@ -254959,6 +255026,12 @@ var deno2 = Object.freeze({
|
|
|
254959
255026
|
});
|
|
254960
255027
|
globalThis.Deno = deno2;
|
|
254961
255028
|
globalThis.Buffer = Buffer2;
|
|
255029
|
+
try {
|
|
255030
|
+
new AsyncLocalStorage().enterWith(void 0);
|
|
255031
|
+
} catch {
|
|
255032
|
+
AsyncLocalStorage.prototype.enterWith = () => {
|
|
255033
|
+
};
|
|
255034
|
+
}
|
|
254962
255035
|
function getRegisteredHandler() {
|
|
254963
255036
|
return registeredHandler;
|
|
254964
255037
|
}
|
|
@@ -257924,7 +257997,7 @@ var TELEMETRY_PATCH = [
|
|
|
257924
257997
|
var TELEMETRY_STORE_FIELDS = "reqId: crypto.randomUUID(), respondedAt: null, inflight: new Map(), inflightTotal: 0, hadRejection: false, hadNonOk: false, logBudget: 5";
|
|
257925
257998
|
|
|
257926
257999
|
// ../functions-compiler/src/version.ts
|
|
257927
|
-
var COMPILER_VERSION = "0.1.
|
|
258000
|
+
var COMPILER_VERSION = "0.1.8";
|
|
257928
258001
|
|
|
257929
258002
|
// ../functions-compiler/src/worker-entry.ts
|
|
257930
258003
|
function denoShimSource() {
|
|
@@ -262548,6 +262621,174 @@ function runtimeVirtualPlugin() {
|
|
|
262548
262621
|
};
|
|
262549
262622
|
}
|
|
262550
262623
|
|
|
262624
|
+
// ../functions-compiler/src/esbuild/ws-native-virtual.ts
|
|
262625
|
+
var NAMESPACE4 = "base44-ws-native";
|
|
262626
|
+
var WS_SPECIFIER = /^(npm:)?ws(@[^/]+)?$/;
|
|
262627
|
+
var ADAPTER = `"use strict";
|
|
262628
|
+
const toBuffer = (value) => (globalThis.Buffer ? globalThis.Buffer.from(value) : value);
|
|
262629
|
+
const READY_STATES = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
|
|
262630
|
+
const later = (fn, ...args) => queueMicrotask(() => fn(...args));
|
|
262631
|
+
const upgradeHeaders = (options) => {
|
|
262632
|
+
const headers = new Headers(options?.headers);
|
|
262633
|
+
for (const name of headers.keys()) if (name !== "user-agent") return headers;
|
|
262634
|
+
return null;
|
|
262635
|
+
};
|
|
262636
|
+
class WebSocket {
|
|
262637
|
+
static CONNECTING = 0;
|
|
262638
|
+
static OPEN = 1;
|
|
262639
|
+
static CLOSING = 2;
|
|
262640
|
+
static CLOSED = 3;
|
|
262641
|
+
#socket = null;
|
|
262642
|
+
#state = 0;
|
|
262643
|
+
#url;
|
|
262644
|
+
#closeRequested = null;
|
|
262645
|
+
#terminated = false;
|
|
262646
|
+
#listeners = new Map();
|
|
262647
|
+
constructor(address, protocols, options) {
|
|
262648
|
+
if (protocols && typeof protocols === "object" && !Array.isArray(protocols)) {
|
|
262649
|
+
options = protocols;
|
|
262650
|
+
protocols = undefined;
|
|
262651
|
+
}
|
|
262652
|
+
this.#url = String(address);
|
|
262653
|
+
const headers = upgradeHeaders(options);
|
|
262654
|
+
if (headers) {
|
|
262655
|
+
this.#upgrade(headers, protocols);
|
|
262656
|
+
} else {
|
|
262657
|
+
this.#attach(new globalThis.WebSocket(this.#url, protocols));
|
|
262658
|
+
}
|
|
262659
|
+
}
|
|
262660
|
+
get readyState() {
|
|
262661
|
+
if (this.#terminated) return 3;
|
|
262662
|
+
return this.#socket ? this.#socket.readyState : this.#state;
|
|
262663
|
+
}
|
|
262664
|
+
get url() { return this.#url; }
|
|
262665
|
+
get protocol() { return this.#socket ? this.#socket.protocol ?? "" : ""; }
|
|
262666
|
+
on(name, listener) { return this.#add(name, listener, false); }
|
|
262667
|
+
addListener(name, listener) { return this.#add(name, listener, false); }
|
|
262668
|
+
once(name, listener) { return this.#add(name, listener, true); }
|
|
262669
|
+
off(name, listener) { return this.removeListener(name, listener); }
|
|
262670
|
+
removeListener(name, listener) {
|
|
262671
|
+
const listeners = this.#listeners.get(name);
|
|
262672
|
+
if (listeners) this.#listeners.set(name, listeners.filter((entry) => entry.listener !== listener));
|
|
262673
|
+
return this;
|
|
262674
|
+
}
|
|
262675
|
+
removeAllListeners(name) {
|
|
262676
|
+
if (name === undefined) this.#listeners.clear();
|
|
262677
|
+
else this.#listeners.delete(name);
|
|
262678
|
+
return this;
|
|
262679
|
+
}
|
|
262680
|
+
emit(name, ...args) {
|
|
262681
|
+
const listeners = this.#listeners.get(name) ?? [];
|
|
262682
|
+
this.#listeners.set(name, listeners.filter((entry) => !entry.once));
|
|
262683
|
+
for (const entry of listeners) entry.listener.apply(this, args);
|
|
262684
|
+
return listeners.length > 0;
|
|
262685
|
+
}
|
|
262686
|
+
send(data, options, callback) {
|
|
262687
|
+
const done = typeof options === "function" ? options : callback;
|
|
262688
|
+
try {
|
|
262689
|
+
if (!this.#socket) {
|
|
262690
|
+
throw new Error("WebSocket is not open: readyState " + this.#state + " (" + READY_STATES[this.#state] + ")");
|
|
262691
|
+
}
|
|
262692
|
+
this.#socket.send(data);
|
|
262693
|
+
done?.();
|
|
262694
|
+
} catch (error) {
|
|
262695
|
+
if (!done) throw error;
|
|
262696
|
+
done(error);
|
|
262697
|
+
}
|
|
262698
|
+
}
|
|
262699
|
+
close(code, reason) {
|
|
262700
|
+
if (this.#socket) this.#socket.close(code, reason);
|
|
262701
|
+
else if (this.#state === 0) {
|
|
262702
|
+
// Upgrade still in flight: close as soon as it lands.
|
|
262703
|
+
this.#closeRequested = [code, reason];
|
|
262704
|
+
this.#state = 2;
|
|
262705
|
+
}
|
|
262706
|
+
}
|
|
262707
|
+
// \`ws\` tears the connection down at once. workerd has no abrupt close, so the
|
|
262708
|
+
// socket is closed normally and "close" is reported now, not on the reply.
|
|
262709
|
+
terminate() {
|
|
262710
|
+
if (this.#terminated || this.readyState === 3) return;
|
|
262711
|
+
this.#terminated = true;
|
|
262712
|
+
if (this.#socket) {
|
|
262713
|
+
try { this.#socket.close(); } catch {}
|
|
262714
|
+
} else {
|
|
262715
|
+
// Upgrade still in flight: close it on arrival, without an "open".
|
|
262716
|
+
this.#closeRequested = [];
|
|
262717
|
+
this.#state = 3;
|
|
262718
|
+
}
|
|
262719
|
+
later(() => this.emit("close", 1006, toBuffer("")));
|
|
262720
|
+
}
|
|
262721
|
+
#attach(socket) {
|
|
262722
|
+
this.#socket = socket;
|
|
262723
|
+
try { socket.binaryType = "arraybuffer"; } catch {}
|
|
262724
|
+
socket.addEventListener("open", () => this.emit("open"));
|
|
262725
|
+
socket.addEventListener("message", (event) => {
|
|
262726
|
+
const isBinary = typeof event.data !== "string";
|
|
262727
|
+
this.emit("message", toBuffer(isBinary ? new Uint8Array(event.data) : event.data), isBinary);
|
|
262728
|
+
});
|
|
262729
|
+
socket.addEventListener("error", (event) => this.emit("error", event.error ?? new Error(event.message || "WebSocket error")));
|
|
262730
|
+
socket.addEventListener("close", (event) => {
|
|
262731
|
+
if (!this.#terminated) this.emit("close", event.code, toBuffer(event.reason ?? ""));
|
|
262732
|
+
});
|
|
262733
|
+
}
|
|
262734
|
+
#upgrade(headers, protocols) {
|
|
262735
|
+
headers.set("Upgrade", "websocket");
|
|
262736
|
+
if (protocols) headers.set("Sec-WebSocket-Protocol", [].concat(protocols).join(", "));
|
|
262737
|
+
const httpUrl = this.#url.replace(/^ws(s?):/i, "http$1:");
|
|
262738
|
+
const fail = (error) => {
|
|
262739
|
+
this.#state = 3;
|
|
262740
|
+
if (this.#terminated) return;
|
|
262741
|
+
this.emit("error", error);
|
|
262742
|
+
this.emit("close", 1006, toBuffer(""));
|
|
262743
|
+
};
|
|
262744
|
+
// Two-argument then(): an exception from an "open" listener must not be
|
|
262745
|
+
// reported as a failed upgrade.
|
|
262746
|
+
fetch(httpUrl, { headers }).then((response) => {
|
|
262747
|
+
const socket = response.webSocket;
|
|
262748
|
+
if (!socket) {
|
|
262749
|
+
response.body?.cancel();
|
|
262750
|
+
return fail(new Error("Unexpected server response: " + response.status));
|
|
262751
|
+
}
|
|
262752
|
+
socket.accept();
|
|
262753
|
+
this.#attach(socket);
|
|
262754
|
+
if (this.#closeRequested) return socket.close(...this.#closeRequested);
|
|
262755
|
+
// accept() opens the socket without dispatching an "open" event.
|
|
262756
|
+
this.emit("open");
|
|
262757
|
+
}, fail);
|
|
262758
|
+
}
|
|
262759
|
+
#add(name, listener, once) {
|
|
262760
|
+
const listeners = this.#listeners.get(name) ?? [];
|
|
262761
|
+
listeners.push({ listener, once });
|
|
262762
|
+
this.#listeners.set(name, listeners);
|
|
262763
|
+
return this;
|
|
262764
|
+
}
|
|
262765
|
+
}
|
|
262766
|
+
class WebSocketServer {
|
|
262767
|
+
constructor() {
|
|
262768
|
+
throw new Error("ws WebSocketServer is not available in Base44 functions: a function can open WebSocket connections but cannot listen for them.");
|
|
262769
|
+
}
|
|
262770
|
+
}
|
|
262771
|
+
module.exports = WebSocket;
|
|
262772
|
+
module.exports.WebSocket = WebSocket;
|
|
262773
|
+
module.exports.WebSocketServer = WebSocketServer;
|
|
262774
|
+
module.exports.default = WebSocket;
|
|
262775
|
+
`;
|
|
262776
|
+
function wsNativeVirtualPlugin() {
|
|
262777
|
+
return {
|
|
262778
|
+
name: "base44-ws-native",
|
|
262779
|
+
setup(build) {
|
|
262780
|
+
build.onResolve({ filter: WS_SPECIFIER }, () => ({
|
|
262781
|
+
path: "ws",
|
|
262782
|
+
namespace: NAMESPACE4
|
|
262783
|
+
}));
|
|
262784
|
+
build.onLoad({ filter: /.*/, namespace: NAMESPACE4 }, () => ({
|
|
262785
|
+
contents: ADAPTER,
|
|
262786
|
+
loader: "js"
|
|
262787
|
+
}));
|
|
262788
|
+
}
|
|
262789
|
+
};
|
|
262790
|
+
}
|
|
262791
|
+
|
|
262551
262792
|
// ../functions-compiler/src/deno-bundle.ts
|
|
262552
262793
|
async function bundleToModule(prepared, nodeModulesDir = "none") {
|
|
262553
262794
|
const dir = await mkdtemp(path21.join(tmpdir2(), "b44-bundle-"));
|
|
@@ -262571,6 +262812,7 @@ async function bundleToModule(prepared, nodeModulesDir = "none") {
|
|
|
262571
262812
|
sourcemap: false,
|
|
262572
262813
|
logLevel: "silent",
|
|
262573
262814
|
plugins: [
|
|
262815
|
+
wsNativeVirtualPlugin(),
|
|
262574
262816
|
nodeBuiltinRequirePlugin(),
|
|
262575
262817
|
userFilesPlugin(prepared.files, prepared.entry),
|
|
262576
262818
|
privateDataSourcesVirtualPlugin(),
|
|
@@ -272960,4 +273202,4 @@ export {
|
|
|
272960
273202
|
runCLI
|
|
272961
273203
|
};
|
|
272962
273204
|
|
|
272963
|
-
//# debugId=
|
|
273205
|
+
//# debugId=C89C416C808E439E64756E2164756E21
|