@malloy-publisher/server 0.0.197 → 0.0.198-dev1

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.
Files changed (54) hide show
  1. package/README.docker.md +47 -0
  2. package/build.ts +26 -1
  3. package/dist/app/api-doc.yaml +54 -20
  4. package/dist/app/assets/{EnvironmentPage-BVkQH_xQ.js → EnvironmentPage-Dpee_Kn6.js} +1 -1
  5. package/dist/app/assets/{HomePage-BgH9UkjK.js → HomePage-DLRWTNoL.js} +1 -1
  6. package/dist/app/assets/{MainPage-DiBxABem.js → MainPage-DsVt5QGM.js} +1 -1
  7. package/dist/app/assets/{ModelPage-oS70fj83.js → ModelPage-AwAugZ37.js} +1 -1
  8. package/dist/app/assets/{PackagePage-F_qLDAdv.js → PackagePage-XQ-EWGTC.js} +1 -1
  9. package/dist/app/assets/{RouteError-WqpffppN.js → RouteError-3Mv8JQw7.js} +1 -1
  10. package/dist/app/assets/{WorkbookPage-_YmC-ebR.js → WorkbookPage-DHYYpcYc.js} +1 -1
  11. package/dist/app/assets/{core-B8L9xCYT.es-BcRLJTnC.js → core-DfcpQGVP.es-DQggNOdX.js} +1 -1
  12. package/dist/app/assets/{index-C3XPaTaS.js → index-BUp81Qdm.js} +1 -1
  13. package/dist/app/assets/{index-rg8Ok8nl.js → index-D1pdwrUW.js} +1 -1
  14. package/dist/app/assets/{index-BMViiwtJ.js → index-Dv5bF4Ii.js} +4 -4
  15. package/dist/app/assets/{index.umd-CCAfKkxY.js → index.umd-CQH4LZU8.js} +1 -1
  16. package/dist/app/index.html +1 -1
  17. package/dist/compile_worker.mjs +628 -0
  18. package/dist/instrumentation.mjs +36 -36
  19. package/dist/server.mjs +1781 -809
  20. package/package.json +1 -1
  21. package/src/compile/compile_pool.spec.ts +227 -0
  22. package/src/compile/compile_pool.ts +729 -0
  23. package/src/compile/compile_worker.ts +683 -0
  24. package/src/compile/protocol.ts +251 -0
  25. package/src/config.spec.ts +81 -0
  26. package/src/config.ts +126 -0
  27. package/src/controller/compile.controller.ts +3 -1
  28. package/src/controller/model.controller.ts +8 -1
  29. package/src/controller/package.controller.ts +70 -29
  30. package/src/controller/query.controller.ts +3 -0
  31. package/src/errors.ts +13 -0
  32. package/src/health.spec.ts +90 -0
  33. package/src/health.ts +86 -71
  34. package/src/mcp/tools/discovery_tools.ts +6 -2
  35. package/src/mcp/tools/execute_query_tool.ts +12 -0
  36. package/src/path_safety.spec.ts +158 -0
  37. package/src/path_safety.ts +140 -0
  38. package/src/server.ts +29 -0
  39. package/src/service/environment.ts +616 -199
  40. package/src/service/environment_admission.spec.ts +180 -0
  41. package/src/service/environment_store.spec.ts +0 -19
  42. package/src/service/environment_store.ts +24 -21
  43. package/src/service/filter_integration.spec.ts +110 -0
  44. package/src/service/givens_integration.spec.ts +192 -0
  45. package/src/service/manifest_service.spec.ts +7 -2
  46. package/src/service/manifest_service.ts +8 -2
  47. package/src/service/materialization_service.ts +14 -3
  48. package/src/service/model.spec.ts +105 -0
  49. package/src/service/model.ts +317 -10
  50. package/src/service/model_worker_path.spec.ts +125 -0
  51. package/src/service/package_memory_governor.spec.ts +173 -0
  52. package/src/service/package_memory_governor.ts +233 -0
  53. package/src/service/package_race.spec.ts +208 -0
  54. package/tests/integration/concurrent_package/concurrent_package.integration.spec.ts +280 -0
package/dist/server.mjs CHANGED
@@ -44,6 +44,7 @@ var __export = (target, all) => {
44
44
  set: __exportSetter.bind(all, name)
45
45
  });
46
46
  };
47
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
47
48
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
48
49
 
49
50
  // ../../node_modules/@opentelemetry/api/build/src/platform/node/globalThis.js
@@ -115087,6 +115088,91 @@ var require_winston = __commonJS((exports) => {
115087
115088
  warn.forProperties(exports, "deprecated", ["emitErrs", "levelLength"]);
115088
115089
  });
115089
115090
 
115091
+ // src/logger.ts
115092
+ function extractTraceIdFromTraceparent(traceparent) {
115093
+ if (!traceparent) {
115094
+ return;
115095
+ }
115096
+ const parts = traceparent.split("-");
115097
+ const traceId = parts.length >= 2 ? parts[1] : parts.length == 1 ? parts[0] : undefined;
115098
+ if (traceId && traceId.length === 32 && /^[0-9a-fA-F]{32}$/.test(traceId)) {
115099
+ return traceId;
115100
+ }
115101
+ return;
115102
+ }
115103
+ function formatDuration(durationMs) {
115104
+ if (durationMs >= 1000) {
115105
+ const seconds = durationMs / 1000;
115106
+ return `${seconds.toFixed(2)}s`;
115107
+ }
115108
+ return `${durationMs.toFixed(2)}ms`;
115109
+ }
115110
+ var import_winston, isTelemetryEnabled, VALID_LOG_LEVELS, getLogLevel = () => {
115111
+ if (process.env.LOG_LEVEL) {
115112
+ const logLevel = process.env.LOG_LEVEL.toLowerCase();
115113
+ if (VALID_LOG_LEVELS.includes(logLevel)) {
115114
+ return logLevel;
115115
+ } else {
115116
+ console.error(`Invalid log level: ${process.env.LOG_LEVEL}. Valid log levels are: ${VALID_LOG_LEVELS.join(", ")}. Defaulting to "debug".`);
115117
+ }
115118
+ }
115119
+ return "debug";
115120
+ }, logger, DISABLE_RESPONSE_LOGGING, loggerMiddleware = (req, res, next) => {
115121
+ const startTime = performance.now();
115122
+ const resJson = res.json;
115123
+ res.json = (body) => {
115124
+ res.locals.body = body;
115125
+ return resJson.call(res, body);
115126
+ };
115127
+ res.on("finish", () => {
115128
+ const endTime = performance.now();
115129
+ const durationMs = endTime - startTime;
115130
+ const traceparent = req.headers["traceparent"];
115131
+ const traceId = extractTraceIdFromTraceparent(traceparent);
115132
+ const logMetadata = {
115133
+ statusCode: res.statusCode,
115134
+ duration: formatDuration(durationMs),
115135
+ payload: req.body,
115136
+ params: req.params,
115137
+ query: req.query
115138
+ };
115139
+ if (!DISABLE_RESPONSE_LOGGING) {
115140
+ logMetadata.response = res.locals.body;
115141
+ }
115142
+ if (traceId) {
115143
+ logMetadata.traceId = traceId;
115144
+ }
115145
+ if (req.url !== "/metrics" && req.url !== "/health" && req.url !== "/health/liveness" && req.url !== "/health/readiness") {
115146
+ logger.info(`${req.method} ${req.url}`, logMetadata);
115147
+ }
115148
+ });
115149
+ next();
115150
+ }, logAxiosError = (error) => {
115151
+ if (error.response) {
115152
+ logger.error("Axios server-side error", {
115153
+ url: error.response.config.url,
115154
+ status: error.response.status,
115155
+ headers: error.response.headers,
115156
+ data: error.response.data
115157
+ });
115158
+ } else if (error.request) {
115159
+ logger.error("Axios client-side error", { error: error.request });
115160
+ } else {
115161
+ logger.error("Axios unknown error", { error });
115162
+ }
115163
+ };
115164
+ var init_logger = __esm(() => {
115165
+ import_winston = __toESM(require_winston(), 1);
115166
+ isTelemetryEnabled = Boolean(process.env.OTEL_EXPORTER_OTLP_ENDPOINT);
115167
+ VALID_LOG_LEVELS = ["error", "warn", "info", "verbose", "debug", "silly"];
115168
+ logger = import_winston.default.createLogger({
115169
+ level: getLogLevel(),
115170
+ format: isTelemetryEnabled ? import_winston.default.format.combine(import_winston.default.format.uncolorize(), import_winston.default.format.timestamp(), import_winston.default.format.errors({ stack: true }), import_winston.default.format.json()) : import_winston.default.format.combine(import_winston.default.format.colorize(), import_winston.default.format.simple()),
115171
+ transports: [new import_winston.default.transports.Console]
115172
+ });
115173
+ DISABLE_RESPONSE_LOGGING = process.env.DISABLE_RESPONSE_LOGGING === "true" || process.env.DISABLE_RESPONSE_LOGGING === "1";
115174
+ });
115175
+
115090
115176
  // ../../node_modules/bytes/index.js
115091
115177
  var require_bytes = __commonJS((exports, module) => {
115092
115178
  /*!
@@ -147228,6 +147314,132 @@ var require_dist4 = __commonJS((exports) => {
147228
147314
  __exportStar(require_legacy2(), exports);
147229
147315
  });
147230
147316
 
147317
+ // src/constants.ts
147318
+ import os from "os";
147319
+ var API_PREFIX = "/api/v0", README_NAME = "README.md", PUBLISHER_CONFIG_NAME = "publisher.config.json", PACKAGE_MANIFEST_NAME = "publisher.json", MODEL_FILE_SUFFIX = ".malloy", NOTEBOOK_FILE_SUFFIX = ".malloynb", ROW_LIMIT = 1000, TEMP_DIR_PATH, PUBLISHER_DATA_DIR = "publisher_data";
147320
+ var init_constants = __esm(() => {
147321
+ TEMP_DIR_PATH = os.tmpdir();
147322
+ });
147323
+
147324
+ // src/errors.ts
147325
+ import { MalloyError } from "@malloydata/malloy";
147326
+ function internalErrorToHttpError(error) {
147327
+ if (error instanceof BadRequestError) {
147328
+ return httpError(400, error.message);
147329
+ } else if (error instanceof FrozenConfigError) {
147330
+ return httpError(403, error.message);
147331
+ } else if (error instanceof EnvironmentNotFoundError) {
147332
+ return httpError(404, error.message);
147333
+ } else if (error instanceof PackageNotFoundError) {
147334
+ return httpError(404, error.message);
147335
+ } else if (error instanceof ModelNotFoundError) {
147336
+ return httpError(404, error.message);
147337
+ } else if (error instanceof MalloyError) {
147338
+ return httpError(400, error.message);
147339
+ } else if (error instanceof ConnectionNotFoundError) {
147340
+ return httpError(404, error.message);
147341
+ } else if (error instanceof ConnectionAuthError) {
147342
+ return httpError(422, error.message);
147343
+ } else if (error instanceof ModelCompilationError) {
147344
+ return httpError(424, error.message);
147345
+ } else if (error instanceof ConnectionError) {
147346
+ return httpError(502, error.message);
147347
+ } else if (error instanceof MaterializationNotFoundError) {
147348
+ return httpError(404, error.message);
147349
+ } else if (error instanceof MaterializationConflictError) {
147350
+ return httpError(409, error.message);
147351
+ } else if (error instanceof InvalidStateTransitionError) {
147352
+ return httpError(409, error.message);
147353
+ } else if (error instanceof ServiceUnavailableError) {
147354
+ return httpError(503, error.message);
147355
+ } else {
147356
+ return httpError(500, error.message);
147357
+ }
147358
+ }
147359
+ function httpError(code, message) {
147360
+ return {
147361
+ status: code,
147362
+ json: {
147363
+ code,
147364
+ message
147365
+ }
147366
+ };
147367
+ }
147368
+ var NotImplementedError, BadRequestError, EnvironmentNotFoundError, PackageNotFoundError, ModelNotFoundError, ConnectionNotFoundError, ConnectionError, ConnectionAuthError, ModelCompilationError, FrozenConfigError, MaterializationNotFoundError, MaterializationConflictError, InvalidStateTransitionError, ServiceUnavailableError;
147369
+ var init_errors = __esm(() => {
147370
+ init_constants();
147371
+ NotImplementedError = class NotImplementedError extends Error {
147372
+ constructor(message) {
147373
+ super(message);
147374
+ }
147375
+ };
147376
+ BadRequestError = class BadRequestError extends Error {
147377
+ constructor(message) {
147378
+ super(message);
147379
+ }
147380
+ };
147381
+ EnvironmentNotFoundError = class EnvironmentNotFoundError extends Error {
147382
+ constructor(message) {
147383
+ super(message);
147384
+ }
147385
+ };
147386
+ PackageNotFoundError = class PackageNotFoundError extends Error {
147387
+ constructor(message) {
147388
+ super(message);
147389
+ }
147390
+ };
147391
+ ModelNotFoundError = class ModelNotFoundError extends Error {
147392
+ constructor(message) {
147393
+ super(message);
147394
+ }
147395
+ };
147396
+ ConnectionNotFoundError = class ConnectionNotFoundError extends Error {
147397
+ constructor(message) {
147398
+ super(message);
147399
+ }
147400
+ };
147401
+ ConnectionError = class ConnectionError extends Error {
147402
+ constructor(message) {
147403
+ super(message);
147404
+ }
147405
+ };
147406
+ ConnectionAuthError = class ConnectionAuthError extends Error {
147407
+ constructor(message) {
147408
+ super(message);
147409
+ }
147410
+ };
147411
+ ModelCompilationError = class ModelCompilationError extends Error {
147412
+ constructor(error) {
147413
+ super(error.message);
147414
+ }
147415
+ };
147416
+ FrozenConfigError = class FrozenConfigError extends Error {
147417
+ constructor(message = `Publisher config can't be updated when ${PUBLISHER_CONFIG_NAME} has { "frozenConfig": true }`) {
147418
+ super(message);
147419
+ }
147420
+ };
147421
+ MaterializationNotFoundError = class MaterializationNotFoundError extends Error {
147422
+ constructor(message) {
147423
+ super(message);
147424
+ }
147425
+ };
147426
+ MaterializationConflictError = class MaterializationConflictError extends Error {
147427
+ constructor(message) {
147428
+ super(message);
147429
+ }
147430
+ };
147431
+ InvalidStateTransitionError = class InvalidStateTransitionError extends Error {
147432
+ constructor(message) {
147433
+ super(message);
147434
+ }
147435
+ };
147436
+ ServiceUnavailableError = class ServiceUnavailableError extends Error {
147437
+ constructor(message) {
147438
+ super(message);
147439
+ }
147440
+ };
147441
+ });
147442
+
147231
147443
  // ../../node_modules/delayed-stream/lib/delayed_stream.js
147232
147444
  var require_delayed_stream = __commonJS((exports, module) => {
147233
147445
  var Stream = __require("stream").Stream;
@@ -196989,26 +197201,26 @@ var require_utils74 = __commonJS((exports, module) => {
196989
197201
  }
196990
197202
  mkdirSync(folder);
196991
197203
  };
196992
- Utils.prototype.writeFileTo = function(path4, content, overwrite, attr) {
197204
+ Utils.prototype.writeFileTo = function(path3, content, overwrite, attr) {
196993
197205
  const self2 = this;
196994
- if (self2.fs.existsSync(path4)) {
197206
+ if (self2.fs.existsSync(path3)) {
196995
197207
  if (!overwrite)
196996
197208
  return false;
196997
- var stat4 = self2.fs.statSync(path4);
197209
+ var stat4 = self2.fs.statSync(path3);
196998
197210
  if (stat4.isDirectory()) {
196999
197211
  return false;
197000
197212
  }
197001
197213
  }
197002
- var folder = pth.dirname(path4);
197214
+ var folder = pth.dirname(path3);
197003
197215
  if (!self2.fs.existsSync(folder)) {
197004
197216
  self2.makeDir(folder);
197005
197217
  }
197006
197218
  var fd;
197007
197219
  try {
197008
- fd = self2.fs.openSync(path4, "w", 438);
197220
+ fd = self2.fs.openSync(path3, "w", 438);
197009
197221
  } catch (e) {
197010
- self2.fs.chmodSync(path4, 438);
197011
- fd = self2.fs.openSync(path4, "w", 438);
197222
+ self2.fs.chmodSync(path3, 438);
197223
+ fd = self2.fs.openSync(path3, "w", 438);
197012
197224
  }
197013
197225
  if (fd) {
197014
197226
  try {
@@ -197017,33 +197229,33 @@ var require_utils74 = __commonJS((exports, module) => {
197017
197229
  self2.fs.closeSync(fd);
197018
197230
  }
197019
197231
  }
197020
- self2.fs.chmodSync(path4, attr || 438);
197232
+ self2.fs.chmodSync(path3, attr || 438);
197021
197233
  return true;
197022
197234
  };
197023
- Utils.prototype.writeFileToAsync = function(path4, content, overwrite, attr, callback) {
197235
+ Utils.prototype.writeFileToAsync = function(path3, content, overwrite, attr, callback) {
197024
197236
  if (typeof attr === "function") {
197025
197237
  callback = attr;
197026
197238
  attr = undefined;
197027
197239
  }
197028
197240
  const self2 = this;
197029
- self2.fs.exists(path4, function(exist) {
197241
+ self2.fs.exists(path3, function(exist) {
197030
197242
  if (exist && !overwrite)
197031
197243
  return callback(false);
197032
- self2.fs.stat(path4, function(err, stat4) {
197244
+ self2.fs.stat(path3, function(err, stat4) {
197033
197245
  if (exist && stat4.isDirectory()) {
197034
197246
  return callback(false);
197035
197247
  }
197036
- var folder = pth.dirname(path4);
197248
+ var folder = pth.dirname(path3);
197037
197249
  self2.fs.exists(folder, function(exists) {
197038
197250
  if (!exists)
197039
197251
  self2.makeDir(folder);
197040
- self2.fs.open(path4, "w", 438, function(err2, fd) {
197252
+ self2.fs.open(path3, "w", 438, function(err2, fd) {
197041
197253
  if (err2) {
197042
- self2.fs.chmod(path4, 438, function() {
197043
- self2.fs.open(path4, "w", 438, function(err3, fd2) {
197254
+ self2.fs.chmod(path3, 438, function() {
197255
+ self2.fs.open(path3, "w", 438, function(err3, fd2) {
197044
197256
  self2.fs.write(fd2, content, 0, content.length, 0, function() {
197045
197257
  self2.fs.close(fd2, function() {
197046
- self2.fs.chmod(path4, attr || 438, function() {
197258
+ self2.fs.chmod(path3, attr || 438, function() {
197047
197259
  callback(true);
197048
197260
  });
197049
197261
  });
@@ -197053,13 +197265,13 @@ var require_utils74 = __commonJS((exports, module) => {
197053
197265
  } else if (fd) {
197054
197266
  self2.fs.write(fd, content, 0, content.length, 0, function() {
197055
197267
  self2.fs.close(fd, function() {
197056
- self2.fs.chmod(path4, attr || 438, function() {
197268
+ self2.fs.chmod(path3, attr || 438, function() {
197057
197269
  callback(true);
197058
197270
  });
197059
197271
  });
197060
197272
  });
197061
197273
  } else {
197062
- self2.fs.chmod(path4, attr || 438, function() {
197274
+ self2.fs.chmod(path3, attr || 438, function() {
197063
197275
  callback(true);
197064
197276
  });
197065
197277
  }
@@ -197068,7 +197280,7 @@ var require_utils74 = __commonJS((exports, module) => {
197068
197280
  });
197069
197281
  });
197070
197282
  };
197071
- Utils.prototype.findFiles = function(path4) {
197283
+ Utils.prototype.findFiles = function(path3) {
197072
197284
  const self2 = this;
197073
197285
  function findSync(dir, pattern, recursive) {
197074
197286
  if (typeof pattern === "boolean") {
@@ -197077,17 +197289,17 @@ var require_utils74 = __commonJS((exports, module) => {
197077
197289
  }
197078
197290
  let files = [];
197079
197291
  self2.fs.readdirSync(dir).forEach(function(file) {
197080
- const path5 = pth.join(dir, file);
197081
- const stat4 = self2.fs.statSync(path5);
197082
- if (!pattern || pattern.test(path5)) {
197083
- files.push(pth.normalize(path5) + (stat4.isDirectory() ? self2.sep : ""));
197292
+ const path4 = pth.join(dir, file);
197293
+ const stat4 = self2.fs.statSync(path4);
197294
+ if (!pattern || pattern.test(path4)) {
197295
+ files.push(pth.normalize(path4) + (stat4.isDirectory() ? self2.sep : ""));
197084
197296
  }
197085
197297
  if (stat4.isDirectory() && recursive)
197086
- files = files.concat(findSync(path5, pattern, recursive));
197298
+ files = files.concat(findSync(path4, pattern, recursive));
197087
197299
  });
197088
197300
  return files;
197089
197301
  }
197090
- return findSync(path4, undefined, true);
197302
+ return findSync(path3, undefined, true);
197091
197303
  };
197092
197304
  Utils.prototype.findFilesAsync = function(dir, cb) {
197093
197305
  const self2 = this;
@@ -197147,16 +197359,16 @@ var require_utils74 = __commonJS((exports, module) => {
197147
197359
  return "UNSUPPORTED (" + method + ")";
197148
197360
  }
197149
197361
  };
197150
- Utils.canonical = function(path4) {
197151
- if (!path4)
197362
+ Utils.canonical = function(path3) {
197363
+ if (!path3)
197152
197364
  return "";
197153
- const safeSuffix = pth.posix.normalize("/" + path4.split("\\").join("/"));
197365
+ const safeSuffix = pth.posix.normalize("/" + path3.split("\\").join("/"));
197154
197366
  return pth.join(".", safeSuffix);
197155
197367
  };
197156
- Utils.zipnamefix = function(path4) {
197157
- if (!path4)
197368
+ Utils.zipnamefix = function(path3) {
197369
+ if (!path3)
197158
197370
  return "";
197159
- const safeSuffix = pth.posix.normalize("/" + path4.split("\\").join("/"));
197371
+ const safeSuffix = pth.posix.normalize("/" + path3.split("\\").join("/"));
197160
197372
  return pth.posix.join(".", safeSuffix);
197161
197373
  };
197162
197374
  Utils.findLast = function(arr, callback) {
@@ -197174,9 +197386,9 @@ var require_utils74 = __commonJS((exports, module) => {
197174
197386
  prefix = pth.resolve(pth.normalize(prefix));
197175
197387
  var parts = name.split("/");
197176
197388
  for (var i = 0, l = parts.length;i < l; i++) {
197177
- var path4 = pth.normalize(pth.join(prefix, parts.slice(i, l).join(pth.sep)));
197178
- if (path4.indexOf(prefix) === 0) {
197179
- return path4;
197389
+ var path3 = pth.normalize(pth.join(prefix, parts.slice(i, l).join(pth.sep)));
197390
+ if (path3.indexOf(prefix) === 0) {
197391
+ return path3;
197180
197392
  }
197181
197393
  }
197182
197394
  return pth.normalize(pth.join(prefix, pth.basename(name)));
@@ -197214,8 +197426,8 @@ var require_utils74 = __commonJS((exports, module) => {
197214
197426
  // ../../node_modules/adm-zip/util/fattr.js
197215
197427
  var require_fattr = __commonJS((exports, module) => {
197216
197428
  var pth = __require("path");
197217
- module.exports = function(path4, { fs: fs2 }) {
197218
- var _path = path4 || "", _obj = newAttr(), _stat = null;
197429
+ module.exports = function(path3, { fs: fs2 }) {
197430
+ var _path = path3 || "", _obj = newAttr(), _stat = null;
197219
197431
  function newAttr() {
197220
197432
  return {
197221
197433
  directory: false,
@@ -198545,8 +198757,8 @@ var require_adm_zip = __commonJS((exports, module) => {
198545
198757
  return null;
198546
198758
  }
198547
198759
  function fixPath(zipPath) {
198548
- const { join: join4, normalize: normalize2, sep } = pth.posix;
198549
- return join4(".", normalize2(sep + zipPath.split("\\").join(sep) + sep));
198760
+ const { join: join3, normalize: normalize2, sep } = pth.posix;
198761
+ return join3(".", normalize2(sep + zipPath.split("\\").join(sep) + sep));
198550
198762
  }
198551
198763
  function filenameFilter(filterfn) {
198552
198764
  if (filterfn instanceof RegExp) {
@@ -199074,10 +199286,10 @@ var require_src122 = __commonJS((exports) => {
199074
199286
  var fs_1 = __require("fs");
199075
199287
  var debug_1 = __importDefault(require_src5());
199076
199288
  var log = debug_1.default("@kwsites/file-exists");
199077
- function check(path4, isFile2, isDirectory) {
199078
- log(`checking %s`, path4);
199289
+ function check(path3, isFile2, isDirectory) {
199290
+ log(`checking %s`, path3);
199079
199291
  try {
199080
- const stat4 = fs_1.statSync(path4);
199292
+ const stat4 = fs_1.statSync(path3);
199081
199293
  if (stat4.isFile() && isFile2) {
199082
199294
  log(`[OK] path represents a file`);
199083
199295
  return true;
@@ -199097,8 +199309,8 @@ var require_src122 = __commonJS((exports) => {
199097
199309
  throw e;
199098
199310
  }
199099
199311
  }
199100
- function exists(path4, type = exports.READABLE) {
199101
- return check(path4, (type & exports.FILE) > 0, (type & exports.FOLDER) > 0);
199312
+ function exists(path3, type = exports.READABLE) {
199313
+ return check(path3, (type & exports.FILE) > 0, (type & exports.FOLDER) > 0);
199102
199314
  }
199103
199315
  exports.exists = exists;
199104
199316
  exports.FILE = 1;
@@ -199156,6 +199368,441 @@ var require_dist12 = __commonJS((exports) => {
199156
199368
  exports.default = deferred;
199157
199369
  });
199158
199370
 
199371
+ // src/compile/compile_pool.ts
199372
+ var exports_compile_pool = {};
199373
+ __export(exports_compile_pool, {
199374
+ getCompileWorkerCount: () => getCompileWorkerCount,
199375
+ getCompilePool: () => getCompilePool,
199376
+ __setCompilePoolForTests: () => __setCompilePoolForTests,
199377
+ CompileWorkerPool: () => CompileWorkerPool
199378
+ });
199379
+ import { fileURLToPath as fileURLToPath2 } from "url";
199380
+ import { dirname as dirname3, join as join3 } from "path";
199381
+ import { Worker } from "node:worker_threads";
199382
+ function getCompileWorkerCount() {
199383
+ const raw = process.env.MALLOY_COMPILE_WORKERS;
199384
+ if (raw === undefined)
199385
+ return 0;
199386
+ const parsed = Number.parseInt(raw, 10);
199387
+ if (!Number.isFinite(parsed) || parsed < 0)
199388
+ return 0;
199389
+ return parsed;
199390
+ }
199391
+ function resolveWorkerScript() {
199392
+ const thisFile = fileURLToPath2(import.meta.url);
199393
+ const thisDir = dirname3(thisFile);
199394
+ const distCandidate = join3(thisDir, "compile_worker.mjs");
199395
+ if (thisFile.endsWith(".mjs") || thisFile.endsWith(".js")) {
199396
+ return new URL(`file://${distCandidate}`);
199397
+ }
199398
+ const tsCandidate = join3(thisDir, "compile_worker.ts");
199399
+ return new URL(`file://${tsCandidate}`);
199400
+ }
199401
+
199402
+ class CompileWorkerPool {
199403
+ workers = [];
199404
+ maxWorkers;
199405
+ nextWorkerId = 0;
199406
+ jobs = new Map;
199407
+ nextJobId = 0;
199408
+ shuttingDown = false;
199409
+ workerScript;
199410
+ constructor(maxWorkers, workerScript) {
199411
+ this.maxWorkers = maxWorkers;
199412
+ this.workerScript = workerScript ?? resolveWorkerScript();
199413
+ }
199414
+ get enabled() {
199415
+ return this.maxWorkers > 0;
199416
+ }
199417
+ get size() {
199418
+ return this.workers.filter((w) => !w.exited).length;
199419
+ }
199420
+ async compile(request) {
199421
+ if (!this.enabled) {
199422
+ throw new Error("CompileWorkerPool.compile called while disabled (MALLOY_COMPILE_WORKERS=0)");
199423
+ }
199424
+ if (this.shuttingDown) {
199425
+ throw new Error("CompileWorkerPool is shutting down");
199426
+ }
199427
+ const worker = await this.acquireWorker();
199428
+ this.nextJobId += 1;
199429
+ const jobId = `job-${this.nextJobId}`;
199430
+ return new Promise((resolve3, reject) => {
199431
+ const timeout = setTimeout(() => {
199432
+ this.failJob(jobId, new Error(`Compile job timed out after ${COMPILE_JOB_TIMEOUT_MS}ms (model=${request.modelPath})`));
199433
+ }, COMPILE_JOB_TIMEOUT_MS);
199434
+ this.jobs.set(jobId, {
199435
+ jobId,
199436
+ connections: request.malloyConfig.connections,
199437
+ urlReader: request.urlReader ?? defaultUrlReader,
199438
+ resolve: (result) => {
199439
+ clearTimeout(timeout);
199440
+ resolve3(adaptResult(result));
199441
+ },
199442
+ reject: (err) => {
199443
+ clearTimeout(timeout);
199444
+ reject(err);
199445
+ },
199446
+ timeout
199447
+ });
199448
+ worker.inFlight.add(jobId);
199449
+ const message = {
199450
+ type: "compile",
199451
+ requestId: jobId,
199452
+ packagePath: request.packagePath,
199453
+ modelPath: request.modelPath,
199454
+ defaultConnectionName: request.defaultConnectionName,
199455
+ buildManifest: request.buildManifest
199456
+ };
199457
+ worker.worker.postMessage(message);
199458
+ });
199459
+ }
199460
+ async shutdown() {
199461
+ if (this.shuttingDown)
199462
+ return;
199463
+ this.shuttingDown = true;
199464
+ const exits = this.workers.map((pw) => new Promise((resolve3) => {
199465
+ if (pw.exited) {
199466
+ resolve3();
199467
+ return;
199468
+ }
199469
+ pw.worker.once("exit", () => resolve3());
199470
+ const msg = { type: "shutdown" };
199471
+ pw.worker.postMessage(msg);
199472
+ setTimeout(() => {
199473
+ if (!pw.exited) {
199474
+ pw.worker.terminate().finally(() => resolve3());
199475
+ }
199476
+ }, 1e4);
199477
+ }));
199478
+ await Promise.all(exits);
199479
+ }
199480
+ async acquireWorker() {
199481
+ this.workers.splice(0, this.workers.length, ...this.workers.filter((w) => !w.exited));
199482
+ if (this.workers.length < this.maxWorkers) {
199483
+ const pw = this.spawnWorker();
199484
+ this.workers.push(pw);
199485
+ await pw.ready;
199486
+ return pw;
199487
+ }
199488
+ const alive = this.workers.filter((w) => !w.exited);
199489
+ let best = alive[0];
199490
+ for (const candidate of alive) {
199491
+ if (candidate.inFlight.size < best.inFlight.size) {
199492
+ best = candidate;
199493
+ }
199494
+ }
199495
+ await best.ready;
199496
+ return best;
199497
+ }
199498
+ spawnWorker() {
199499
+ this.nextWorkerId += 1;
199500
+ const id = this.nextWorkerId;
199501
+ logger.info(`CompileWorkerPool: spawning worker #${id} (script=${this.workerScript.toString()})`);
199502
+ const worker = new Worker(this.workerScript, {
199503
+ name: `malloy-compile-worker-${id}`
199504
+ });
199505
+ let readyResolve;
199506
+ const ready = new Promise((r) => readyResolve = r);
199507
+ const pw = {
199508
+ id,
199509
+ worker,
199510
+ ready,
199511
+ inFlight: new Set,
199512
+ exited: false
199513
+ };
199514
+ worker.on("message", (msg) => {
199515
+ this.handleWorkerMessage(pw, msg, readyResolve);
199516
+ });
199517
+ worker.on("error", (err) => {
199518
+ logger.error(`CompileWorkerPool: worker #${id} errored`, {
199519
+ error: err
199520
+ });
199521
+ });
199522
+ worker.on("exit", (code) => {
199523
+ pw.exited = true;
199524
+ logger.warn(`CompileWorkerPool: worker #${id} exited (code=${code}, inFlight=${pw.inFlight.size})`);
199525
+ for (const jobId of pw.inFlight) {
199526
+ this.failJob(jobId, new Error(`Compile worker #${id} exited unexpectedly (code=${code})`));
199527
+ }
199528
+ pw.inFlight.clear();
199529
+ });
199530
+ return pw;
199531
+ }
199532
+ handleWorkerMessage(pw, msg, markReady) {
199533
+ switch (msg.type) {
199534
+ case "ready":
199535
+ markReady();
199536
+ return;
199537
+ case "compile-result":
199538
+ this.completeJob(pw, msg);
199539
+ return;
199540
+ case "compile-error":
199541
+ this.errorJob(pw, msg);
199542
+ return;
199543
+ case "connection-metadata":
199544
+ this.handleConnectionMetadata(pw, msg);
199545
+ return;
199546
+ case "schema-for-tables":
199547
+ this.handleSchemaForTables(pw, msg);
199548
+ return;
199549
+ case "schema-for-sql":
199550
+ this.handleSchemaForSql(pw, msg);
199551
+ return;
199552
+ case "read-url":
199553
+ this.handleReadUrl(pw, msg);
199554
+ return;
199555
+ default: {
199556
+ const exhaustive = msg;
199557
+ return;
199558
+ }
199559
+ }
199560
+ }
199561
+ async handleConnectionMetadata(pw, msg) {
199562
+ const ctx = this.jobs.get(msg.jobId);
199563
+ const reply = (response) => {
199564
+ pw.worker.postMessage(response);
199565
+ };
199566
+ if (!ctx) {
199567
+ reply({
199568
+ type: "rpc-error",
199569
+ requestId: msg.requestId,
199570
+ ok: false,
199571
+ error: { name: "Error", message: `Unknown jobId ${msg.jobId}` }
199572
+ });
199573
+ return;
199574
+ }
199575
+ try {
199576
+ const conn = await ctx.connections.lookupConnection(msg.connectionName);
199577
+ reply({
199578
+ type: "connection-metadata-response",
199579
+ requestId: msg.requestId,
199580
+ ok: true,
199581
+ metadata: {
199582
+ name: msg.connectionName,
199583
+ dialectName: conn.dialectName,
199584
+ digest: typeof conn.getDigest === "function" ? conn.getDigest() : msg.connectionName
199585
+ }
199586
+ });
199587
+ } catch (error) {
199588
+ reply({
199589
+ type: "rpc-error",
199590
+ requestId: msg.requestId,
199591
+ ok: false,
199592
+ error: serializeError(error)
199593
+ });
199594
+ }
199595
+ }
199596
+ completeJob(pw, msg) {
199597
+ const ctx = this.jobs.get(msg.requestId);
199598
+ if (!ctx)
199599
+ return;
199600
+ this.jobs.delete(msg.requestId);
199601
+ pw.inFlight.delete(msg.requestId);
199602
+ ctx.resolve(msg);
199603
+ }
199604
+ errorJob(pw, msg) {
199605
+ const ctx = this.jobs.get(msg.requestId);
199606
+ if (!ctx)
199607
+ return;
199608
+ this.jobs.delete(msg.requestId);
199609
+ pw.inFlight.delete(msg.requestId);
199610
+ ctx.reject(deserializeError(msg.error));
199611
+ }
199612
+ failJob(jobId, error) {
199613
+ const ctx = this.jobs.get(jobId);
199614
+ if (!ctx)
199615
+ return;
199616
+ this.jobs.delete(jobId);
199617
+ ctx.reject(error);
199618
+ }
199619
+ async handleSchemaForTables(pw, msg) {
199620
+ const ctx = this.jobs.get(msg.jobId);
199621
+ const reply = (response) => {
199622
+ pw.worker.postMessage(response);
199623
+ };
199624
+ if (!ctx) {
199625
+ reply({
199626
+ type: "rpc-error",
199627
+ requestId: msg.requestId,
199628
+ ok: false,
199629
+ error: { name: "Error", message: `Unknown jobId ${msg.jobId}` }
199630
+ });
199631
+ return;
199632
+ }
199633
+ try {
199634
+ const conn = await ctx.connections.lookupConnection(msg.connectionName);
199635
+ const result = await conn.fetchSchemaForTables(msg.tables, buildFetchOptions(msg.options));
199636
+ reply({
199637
+ type: "schema-for-tables-response",
199638
+ requestId: msg.requestId,
199639
+ ok: true,
199640
+ schemas: result.schemas,
199641
+ errors: result.errors
199642
+ });
199643
+ } catch (error) {
199644
+ reply({
199645
+ type: "rpc-error",
199646
+ requestId: msg.requestId,
199647
+ ok: false,
199648
+ error: serializeError(error)
199649
+ });
199650
+ }
199651
+ }
199652
+ async handleSchemaForSql(pw, msg) {
199653
+ const ctx = this.jobs.get(msg.jobId);
199654
+ const reply = (response) => {
199655
+ pw.worker.postMessage(response);
199656
+ };
199657
+ if (!ctx) {
199658
+ reply({
199659
+ type: "rpc-error",
199660
+ requestId: msg.requestId,
199661
+ ok: false,
199662
+ error: { name: "Error", message: `Unknown jobId ${msg.jobId}` }
199663
+ });
199664
+ return;
199665
+ }
199666
+ try {
199667
+ const conn = await ctx.connections.lookupConnection(msg.connectionName);
199668
+ const result = await conn.fetchSchemaForSQLStruct(msg.sentence, buildFetchOptions(msg.options));
199669
+ if (result.error !== undefined) {
199670
+ reply({
199671
+ type: "schema-for-sql-response",
199672
+ requestId: msg.requestId,
199673
+ ok: true,
199674
+ error: result.error
199675
+ });
199676
+ } else {
199677
+ reply({
199678
+ type: "schema-for-sql-response",
199679
+ requestId: msg.requestId,
199680
+ ok: true,
199681
+ structDef: result.structDef
199682
+ });
199683
+ }
199684
+ } catch (error) {
199685
+ reply({
199686
+ type: "rpc-error",
199687
+ requestId: msg.requestId,
199688
+ ok: false,
199689
+ error: serializeError(error)
199690
+ });
199691
+ }
199692
+ }
199693
+ async handleReadUrl(pw, msg) {
199694
+ const ctx = this.jobs.get(msg.jobId);
199695
+ const reply = (response) => {
199696
+ pw.worker.postMessage(response);
199697
+ };
199698
+ if (!ctx) {
199699
+ reply({
199700
+ type: "rpc-error",
199701
+ requestId: msg.requestId,
199702
+ ok: false,
199703
+ error: { name: "Error", message: `Unknown jobId ${msg.jobId}` }
199704
+ });
199705
+ return;
199706
+ }
199707
+ try {
199708
+ const raw = await ctx.urlReader.readURL(new URL(msg.url));
199709
+ const contents = typeof raw === "string" ? raw : raw.contents;
199710
+ reply({
199711
+ type: "read-url-response",
199712
+ requestId: msg.requestId,
199713
+ ok: true,
199714
+ contents
199715
+ });
199716
+ } catch (error) {
199717
+ reply({
199718
+ type: "rpc-error",
199719
+ requestId: msg.requestId,
199720
+ ok: false,
199721
+ error: serializeError(error)
199722
+ });
199723
+ }
199724
+ }
199725
+ }
199726
+ function buildFetchOptions(options) {
199727
+ const out = {};
199728
+ if (options.refreshTimestamp !== undefined) {
199729
+ out.refreshTimestamp = options.refreshTimestamp;
199730
+ }
199731
+ if (options.modelAnnotation !== undefined) {
199732
+ out.modelAnnotation = options.modelAnnotation;
199733
+ }
199734
+ return out;
199735
+ }
199736
+ function adaptResult(result) {
199737
+ return {
199738
+ modelDef: result.modelDef,
199739
+ sourceInfos: result.sourceInfos,
199740
+ sources: result.sources,
199741
+ queries: result.queries,
199742
+ filterMap: new Map(result.filterMap.map(([k, v]) => [k, v])),
199743
+ givens: result.givens,
199744
+ compileDurationMs: result.compileDurationMs
199745
+ };
199746
+ }
199747
+ function serializeError(error) {
199748
+ if (error instanceof Error) {
199749
+ return {
199750
+ name: error.name,
199751
+ message: error.message,
199752
+ stack: error.stack
199753
+ };
199754
+ }
199755
+ return { name: "Error", message: String(error) };
199756
+ }
199757
+ function deserializeError(serialized) {
199758
+ const err = new Error(serialized.message);
199759
+ err.name = serialized.name;
199760
+ if (serialized.stack)
199761
+ err.stack = serialized.stack;
199762
+ if (serialized.malloyProblems) {
199763
+ err.problems = serialized.malloyProblems;
199764
+ }
199765
+ if (serialized.isCompilationError) {
199766
+ const wrapped = new ModelCompilationError(err);
199767
+ if (serialized.stack)
199768
+ wrapped.stack = serialized.stack;
199769
+ return wrapped;
199770
+ }
199771
+ return err;
199772
+ }
199773
+ function getCompilePool() {
199774
+ if (singleton === null) {
199775
+ const n = getCompileWorkerCount();
199776
+ singleton = new CompileWorkerPool(n);
199777
+ if (n > 0) {
199778
+ logger.info(`Malloy compile worker pool enabled (size=${n}). Set MALLOY_COMPILE_WORKERS=0 to disable.`);
199779
+ } else {
199780
+ logger.info("Malloy compile worker pool DISABLED (MALLOY_COMPILE_WORKERS=0). Compile runs on the main event loop.");
199781
+ }
199782
+ }
199783
+ return singleton;
199784
+ }
199785
+ async function __setCompilePoolForTests(pool) {
199786
+ if (singleton && singleton !== pool) {
199787
+ await singleton.shutdown();
199788
+ }
199789
+ singleton = pool;
199790
+ }
199791
+ var COMPILE_JOB_TIMEOUT_MS, defaultUrlReader, singleton = null;
199792
+ var init_compile_pool = __esm(() => {
199793
+ init_errors();
199794
+ init_logger();
199795
+ COMPILE_JOB_TIMEOUT_MS = Number.parseInt(process.env.MALLOY_COMPILE_JOB_TIMEOUT_MS ?? "120000", 10);
199796
+ defaultUrlReader = {
199797
+ readURL: async (url2) => {
199798
+ const { promises: fs3 } = await import("fs");
199799
+ const { fileURLToPath: fileURLToPath3 } = await import("url");
199800
+ const filePath = url2.protocol === "file:" ? fileURLToPath3(url2) : url2.toString();
199801
+ return fs3.readFile(filePath, "utf8");
199802
+ }
199803
+ };
199804
+ });
199805
+
199159
199806
  // ../../node_modules/concat-map/index.js
199160
199807
  var require_concat_map = __commonJS((exports, module) => {
199161
199808
  module.exports = function(xs, fn) {
@@ -199984,12 +200631,12 @@ var require_recursive_readdir = __commonJS((exports, module) => {
199984
200631
  ignores = [];
199985
200632
  }
199986
200633
  if (!callback) {
199987
- return new Promise(function(resolve3, reject) {
200634
+ return new Promise(function(resolve4, reject) {
199988
200635
  readdir3(path7, ignores || [], function(err, data) {
199989
200636
  if (err) {
199990
200637
  reject(err);
199991
200638
  } else {
199992
- resolve3(data);
200639
+ resolve4(data);
199993
200640
  }
199994
200641
  });
199995
200642
  });
@@ -200771,7 +201418,7 @@ var require_uri_all = __commonJS((exports, module) => {
200771
201418
  target.fragment = relative4.fragment;
200772
201419
  return target;
200773
201420
  }
200774
- function resolve3(baseURI, relativeURI, options) {
201421
+ function resolve4(baseURI, relativeURI, options) {
200775
201422
  var schemelessOptions = assign({ scheme: "null" }, options);
200776
201423
  return serialize(resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
200777
201424
  }
@@ -201039,7 +201686,7 @@ var require_uri_all = __commonJS((exports, module) => {
201039
201686
  exports2.removeDotSegments = removeDotSegments;
201040
201687
  exports2.serialize = serialize;
201041
201688
  exports2.resolveComponents = resolveComponents;
201042
- exports2.resolve = resolve3;
201689
+ exports2.resolve = resolve4;
201043
201690
  exports2.normalize = normalize2;
201044
201691
  exports2.equal = equal;
201045
201692
  exports2.escapeComponent = escapeComponent;
@@ -201405,20 +202052,20 @@ var require_resolve2 = __commonJS((exports, module) => {
201405
202052
  var util5 = require_util13();
201406
202053
  var SchemaObject = require_schema_obj();
201407
202054
  var traverse = require_json_schema_traverse();
201408
- module.exports = resolve3;
201409
- resolve3.normalizeId = normalizeId;
201410
- resolve3.fullPath = getFullPath;
201411
- resolve3.url = resolveUrl;
201412
- resolve3.ids = resolveIds;
201413
- resolve3.inlineRef = inlineRef;
201414
- resolve3.schema = resolveSchema;
201415
- function resolve3(compile, root, ref) {
202055
+ module.exports = resolve4;
202056
+ resolve4.normalizeId = normalizeId;
202057
+ resolve4.fullPath = getFullPath;
202058
+ resolve4.url = resolveUrl;
202059
+ resolve4.ids = resolveIds;
202060
+ resolve4.inlineRef = inlineRef;
202061
+ resolve4.schema = resolveSchema;
202062
+ function resolve4(compile, root, ref) {
201416
202063
  var refVal = this._refs[ref];
201417
202064
  if (typeof refVal == "string") {
201418
202065
  if (this._refs[refVal])
201419
202066
  refVal = this._refs[refVal];
201420
202067
  else
201421
- return resolve3.call(this, compile, root, refVal);
202068
+ return resolve4.call(this, compile, root, refVal);
201422
202069
  }
201423
202070
  refVal = refVal || this._schemas[ref];
201424
202071
  if (refVal instanceof SchemaObject) {
@@ -201641,7 +202288,7 @@ var require_resolve2 = __commonJS((exports, module) => {
201641
202288
 
201642
202289
  // ../../node_modules/@modelcontextprotocol/sdk/node_modules/ajv/lib/compile/error_classes.js
201643
202290
  var require_error_classes = __commonJS((exports, module) => {
201644
- var resolve3 = require_resolve2();
202291
+ var resolve4 = require_resolve2();
201645
202292
  module.exports = {
201646
202293
  Validation: errorSubclass(ValidationError),
201647
202294
  MissingRef: errorSubclass(MissingRefError)
@@ -201656,8 +202303,8 @@ var require_error_classes = __commonJS((exports, module) => {
201656
202303
  };
201657
202304
  function MissingRefError(baseId, ref, message) {
201658
202305
  this.message = message || MissingRefError.message(baseId, ref);
201659
- this.missingRef = resolve3.url(baseId, ref);
201660
- this.missingSchema = resolve3.normalizeId(resolve3.fullPath(this.missingRef));
202306
+ this.missingRef = resolve4.url(baseId, ref);
202307
+ this.missingSchema = resolve4.normalizeId(resolve4.fullPath(this.missingRef));
201661
202308
  }
201662
202309
  function errorSubclass(Subclass) {
201663
202310
  Subclass.prototype = Object.create(Error.prototype);
@@ -202199,7 +202846,7 @@ var require_validate4 = __commonJS((exports, module) => {
202199
202846
 
202200
202847
  // ../../node_modules/@modelcontextprotocol/sdk/node_modules/ajv/lib/compile/index.js
202201
202848
  var require_compile2 = __commonJS((exports, module) => {
202202
- var resolve3 = require_resolve2();
202849
+ var resolve4 = require_resolve2();
202203
202850
  var util5 = require_util13();
202204
202851
  var errorClasses = require_error_classes();
202205
202852
  var stableStringify = require_fast_json_stable_stringify();
@@ -202259,7 +202906,7 @@ var require_compile2 = __commonJS((exports, module) => {
202259
202906
  RULES,
202260
202907
  validate: validateGenerator,
202261
202908
  util: util5,
202262
- resolve: resolve3,
202909
+ resolve: resolve4,
202263
202910
  resolveRef,
202264
202911
  usePattern,
202265
202912
  useDefault,
@@ -202298,7 +202945,7 @@ var require_compile2 = __commonJS((exports, module) => {
202298
202945
  return validate;
202299
202946
  }
202300
202947
  function resolveRef(baseId2, ref, isRoot) {
202301
- ref = resolve3.url(baseId2, ref);
202948
+ ref = resolve4.url(baseId2, ref);
202302
202949
  var refIndex = refs[ref];
202303
202950
  var _refVal, refCode;
202304
202951
  if (refIndex !== undefined) {
@@ -202315,11 +202962,11 @@ var require_compile2 = __commonJS((exports, module) => {
202315
202962
  }
202316
202963
  }
202317
202964
  refCode = addLocalRef(ref);
202318
- var v2 = resolve3.call(self2, localCompile, root, ref);
202965
+ var v2 = resolve4.call(self2, localCompile, root, ref);
202319
202966
  if (v2 === undefined) {
202320
202967
  var localSchema = localRefs && localRefs[ref];
202321
202968
  if (localSchema) {
202322
- v2 = resolve3.inlineRef(localSchema, opts.inlineRefs) ? localSchema : compile.call(self2, localSchema, root, localRefs, baseId2);
202969
+ v2 = resolve4.inlineRef(localSchema, opts.inlineRefs) ? localSchema : compile.call(self2, localSchema, root, localRefs, baseId2);
202323
202970
  }
202324
202971
  }
202325
202972
  if (v2 === undefined) {
@@ -205836,7 +206483,7 @@ var require_data2 = __commonJS((exports, module) => {
205836
206483
  // ../../node_modules/@modelcontextprotocol/sdk/node_modules/ajv/lib/ajv.js
205837
206484
  var require_ajv = __commonJS((exports, module) => {
205838
206485
  var compileSchema = require_compile2();
205839
- var resolve3 = require_resolve2();
206486
+ var resolve4 = require_resolve2();
205840
206487
  var Cache = require_cache();
205841
206488
  var SchemaObject = require_schema_obj();
205842
206489
  var stableStringify = require_fast_json_stable_stringify();
@@ -205928,7 +206575,7 @@ var require_ajv = __commonJS((exports, module) => {
205928
206575
  var id = this._getId(schema);
205929
206576
  if (id !== undefined && typeof id != "string")
205930
206577
  throw new Error("schema id must be string");
205931
- key = resolve3.normalizeId(key || id);
206578
+ key = resolve4.normalizeId(key || id);
205932
206579
  checkUnique(this, key);
205933
206580
  this._schemas[key] = this._addSchema(schema, _skipValidation, _meta, true);
205934
206581
  return this;
@@ -205974,7 +206621,7 @@ var require_ajv = __commonJS((exports, module) => {
205974
206621
  }
205975
206622
  }
205976
206623
  function _getSchemaFragment(self2, ref) {
205977
- var res = resolve3.schema.call(self2, { schema: {} }, ref);
206624
+ var res = resolve4.schema.call(self2, { schema: {} }, ref);
205978
206625
  if (res) {
205979
206626
  var { schema, root, baseId } = res;
205980
206627
  var v = compileSchema.call(self2, schema, root, undefined, baseId);
@@ -205990,7 +206637,7 @@ var require_ajv = __commonJS((exports, module) => {
205990
206637
  }
205991
206638
  }
205992
206639
  function _getSchemaObj(self2, keyRef) {
205993
- keyRef = resolve3.normalizeId(keyRef);
206640
+ keyRef = resolve4.normalizeId(keyRef);
205994
206641
  return self2._schemas[keyRef] || self2._refs[keyRef] || self2._fragments[keyRef];
205995
206642
  }
205996
206643
  function removeSchema(schemaKeyRef) {
@@ -206018,7 +206665,7 @@ var require_ajv = __commonJS((exports, module) => {
206018
206665
  this._cache.del(cacheKey);
206019
206666
  var id = this._getId(schemaKeyRef);
206020
206667
  if (id) {
206021
- id = resolve3.normalizeId(id);
206668
+ id = resolve4.normalizeId(id);
206022
206669
  delete this._schemas[id];
206023
206670
  delete this._refs[id];
206024
206671
  }
@@ -206043,14 +206690,14 @@ var require_ajv = __commonJS((exports, module) => {
206043
206690
  if (cached)
206044
206691
  return cached;
206045
206692
  shouldAddSchema = shouldAddSchema || this._opts.addUsedSchema !== false;
206046
- var id = resolve3.normalizeId(this._getId(schema));
206693
+ var id = resolve4.normalizeId(this._getId(schema));
206047
206694
  if (id && shouldAddSchema)
206048
206695
  checkUnique(this, id);
206049
206696
  var willValidate = this._opts.validateSchema !== false && !skipValidation;
206050
206697
  var recursiveMeta;
206051
- if (willValidate && !(recursiveMeta = id && id == resolve3.normalizeId(schema.$schema)))
206698
+ if (willValidate && !(recursiveMeta = id && id == resolve4.normalizeId(schema.$schema)))
206052
206699
  this.validateSchema(schema, true);
206053
- var localRefs = resolve3.ids.call(this, schema);
206700
+ var localRefs = resolve4.ids.call(this, schema);
206054
206701
  var schemaObj = new SchemaObject({
206055
206702
  id,
206056
206703
  schema,
@@ -209093,7 +209740,7 @@ var require_util14 = __commonJS((exports) => {
209093
209740
  }
209094
209741
  path12 = url2.path;
209095
209742
  }
209096
- var isAbsolute3 = exports.isAbsolute(path12);
209743
+ var isAbsolute4 = exports.isAbsolute(path12);
209097
209744
  var parts = path12.split(/\/+/);
209098
209745
  for (var part, up = 0, i = parts.length - 1;i >= 0; i--) {
209099
209746
  part = parts[i];
@@ -209113,7 +209760,7 @@ var require_util14 = __commonJS((exports) => {
209113
209760
  }
209114
209761
  path12 = parts.join("/");
209115
209762
  if (path12 === "") {
209116
- path12 = isAbsolute3 ? "/" : ".";
209763
+ path12 = isAbsolute4 ? "/" : ".";
209117
209764
  }
209118
209765
  if (url2) {
209119
209766
  url2.path = path12;
@@ -211725,6 +212372,7 @@ var require_lib8 = __commonJS((exports, module) => {
211725
212372
  });
211726
212373
 
211727
212374
  // src/instrumentation.ts
212375
+ init_logger();
211728
212376
  var import_api = __toESM(require_src(), 1);
211729
212377
  var import_auto_instrumentations_node = __toESM(require_src59(), 1);
211730
212378
  var import_exporter_logs_otlp_proto = __toESM(require_src66(), 1);
@@ -211736,93 +212384,6 @@ var import_sdk_logs = __toESM(require_src75(), 1);
211736
212384
  var import_sdk_node = __toESM(require_src106(), 1);
211737
212385
  var import_sdk_trace_base = __toESM(require_src82(), 1);
211738
212386
  var import_semantic_conventions = __toESM(require_src2(), 1);
211739
-
211740
- // src/logger.ts
211741
- var import_winston = __toESM(require_winston(), 1);
211742
- var isTelemetryEnabled = Boolean(process.env.OTEL_EXPORTER_OTLP_ENDPOINT);
211743
- var VALID_LOG_LEVELS = ["error", "warn", "info", "verbose", "debug", "silly"];
211744
- var getLogLevel = () => {
211745
- if (process.env.LOG_LEVEL) {
211746
- const logLevel = process.env.LOG_LEVEL.toLowerCase();
211747
- if (VALID_LOG_LEVELS.includes(logLevel)) {
211748
- return logLevel;
211749
- } else {
211750
- console.error(`Invalid log level: ${process.env.LOG_LEVEL}. Valid log levels are: ${VALID_LOG_LEVELS.join(", ")}. Defaulting to "debug".`);
211751
- }
211752
- }
211753
- return "debug";
211754
- };
211755
- var logger = import_winston.default.createLogger({
211756
- level: getLogLevel(),
211757
- format: isTelemetryEnabled ? import_winston.default.format.combine(import_winston.default.format.uncolorize(), import_winston.default.format.timestamp(), import_winston.default.format.errors({ stack: true }), import_winston.default.format.json()) : import_winston.default.format.combine(import_winston.default.format.colorize(), import_winston.default.format.simple()),
211758
- transports: [new import_winston.default.transports.Console]
211759
- });
211760
- function extractTraceIdFromTraceparent(traceparent) {
211761
- if (!traceparent) {
211762
- return;
211763
- }
211764
- const parts = traceparent.split("-");
211765
- const traceId = parts.length >= 2 ? parts[1] : parts.length == 1 ? parts[0] : undefined;
211766
- if (traceId && traceId.length === 32 && /^[0-9a-fA-F]{32}$/.test(traceId)) {
211767
- return traceId;
211768
- }
211769
- return;
211770
- }
211771
- var DISABLE_RESPONSE_LOGGING = process.env.DISABLE_RESPONSE_LOGGING === "true" || process.env.DISABLE_RESPONSE_LOGGING === "1";
211772
- function formatDuration(durationMs) {
211773
- if (durationMs >= 1000) {
211774
- const seconds = durationMs / 1000;
211775
- return `${seconds.toFixed(2)}s`;
211776
- }
211777
- return `${durationMs.toFixed(2)}ms`;
211778
- }
211779
- var loggerMiddleware = (req, res, next) => {
211780
- const startTime = performance.now();
211781
- const resJson = res.json;
211782
- res.json = (body) => {
211783
- res.locals.body = body;
211784
- return resJson.call(res, body);
211785
- };
211786
- res.on("finish", () => {
211787
- const endTime = performance.now();
211788
- const durationMs = endTime - startTime;
211789
- const traceparent = req.headers["traceparent"];
211790
- const traceId = extractTraceIdFromTraceparent(traceparent);
211791
- const logMetadata = {
211792
- statusCode: res.statusCode,
211793
- duration: formatDuration(durationMs),
211794
- payload: req.body,
211795
- params: req.params,
211796
- query: req.query
211797
- };
211798
- if (!DISABLE_RESPONSE_LOGGING) {
211799
- logMetadata.response = res.locals.body;
211800
- }
211801
- if (traceId) {
211802
- logMetadata.traceId = traceId;
211803
- }
211804
- if (req.url !== "/metrics" && req.url !== "/health" && req.url !== "/health/liveness" && req.url !== "/health/readiness") {
211805
- logger.info(`${req.method} ${req.url}`, logMetadata);
211806
- }
211807
- });
211808
- next();
211809
- };
211810
- var logAxiosError = (error) => {
211811
- if (error.response) {
211812
- logger.error("Axios server-side error", {
211813
- url: error.response.config.url,
211814
- status: error.response.status,
211815
- headers: error.response.headers,
211816
- data: error.response.data
211817
- });
211818
- } else if (error.request) {
211819
- logger.error("Axios client-side error", { error: error.request });
211820
- } else {
211821
- logger.error("Axios unknown error", { error });
211822
- }
211823
- };
211824
-
211825
- // src/instrumentation.ts
211826
212387
  var prometheusExporter = null;
211827
212388
  var sdk = null;
211828
212389
  function getPrometheusMetricsHandler() {
@@ -216945,7 +217506,7 @@ var import_express = __toESM(require_express(), 1);
216945
217506
  var import_http_proxy_middleware = __toESM(require_dist4(), 1);
216946
217507
  import * as http2 from "http";
216947
217508
  import * as path12 from "path";
216948
- import { fileURLToPath as fileURLToPath3 } from "url";
217509
+ import { fileURLToPath as fileURLToPath4 } from "url";
216949
217510
 
216950
217511
  // src/controller/compile.controller.ts
216951
217512
  class CompileController {
@@ -216953,9 +217514,9 @@ class CompileController {
216953
217514
  constructor(environmentStore) {
216954
217515
  this.environmentStore = environmentStore;
216955
217516
  }
216956
- async compile(environmentName, packageName, modelName, source, includeSql = false) {
217517
+ async compile(environmentName, packageName, modelName, source, includeSql = false, givens) {
216957
217518
  const environment = await this.environmentStore.getEnvironment(environmentName, false);
216958
- const { problems, sql } = await environment.compileSource(packageName, modelName, source, includeSql);
217519
+ const { problems, sql } = await environment.compileSource(packageName, modelName, source, includeSql, givens);
216959
217520
  const hasErrors = problems.some((p) => p.severity === "error");
216960
217521
  return {
216961
217522
  status: hasErrors ? "error" : "success",
@@ -216965,140 +217526,9 @@ class CompileController {
216965
217526
  }
216966
217527
  }
216967
217528
 
216968
- // src/errors.ts
216969
- import { MalloyError } from "@malloydata/malloy";
216970
-
216971
- // src/constants.ts
216972
- import os from "os";
216973
- var API_PREFIX = "/api/v0";
216974
- var README_NAME = "README.md";
216975
- var PUBLISHER_CONFIG_NAME = "publisher.config.json";
216976
- var PACKAGE_MANIFEST_NAME = "publisher.json";
216977
- var MODEL_FILE_SUFFIX = ".malloy";
216978
- var NOTEBOOK_FILE_SUFFIX = ".malloynb";
216979
- var ROW_LIMIT = 1000;
216980
- var TEMP_DIR_PATH = os.tmpdir();
216981
- var PUBLISHER_DATA_DIR = "publisher_data";
216982
-
216983
- // src/errors.ts
216984
- function internalErrorToHttpError(error) {
216985
- if (error instanceof BadRequestError) {
216986
- return httpError(400, error.message);
216987
- } else if (error instanceof FrozenConfigError) {
216988
- return httpError(403, error.message);
216989
- } else if (error instanceof EnvironmentNotFoundError) {
216990
- return httpError(404, error.message);
216991
- } else if (error instanceof PackageNotFoundError) {
216992
- return httpError(404, error.message);
216993
- } else if (error instanceof ModelNotFoundError) {
216994
- return httpError(404, error.message);
216995
- } else if (error instanceof MalloyError) {
216996
- return httpError(400, error.message);
216997
- } else if (error instanceof ConnectionNotFoundError) {
216998
- return httpError(404, error.message);
216999
- } else if (error instanceof ConnectionAuthError) {
217000
- return httpError(422, error.message);
217001
- } else if (error instanceof ModelCompilationError) {
217002
- return httpError(424, error.message);
217003
- } else if (error instanceof ConnectionError) {
217004
- return httpError(502, error.message);
217005
- } else if (error instanceof MaterializationNotFoundError) {
217006
- return httpError(404, error.message);
217007
- } else if (error instanceof MaterializationConflictError) {
217008
- return httpError(409, error.message);
217009
- } else if (error instanceof InvalidStateTransitionError) {
217010
- return httpError(409, error.message);
217011
- } else {
217012
- return httpError(500, error.message);
217013
- }
217014
- }
217015
- function httpError(code, message) {
217016
- return {
217017
- status: code,
217018
- json: {
217019
- code,
217020
- message
217021
- }
217022
- };
217023
- }
217024
-
217025
- class NotImplementedError extends Error {
217026
- constructor(message) {
217027
- super(message);
217028
- }
217029
- }
217030
-
217031
- class BadRequestError extends Error {
217032
- constructor(message) {
217033
- super(message);
217034
- }
217035
- }
217036
-
217037
- class EnvironmentNotFoundError extends Error {
217038
- constructor(message) {
217039
- super(message);
217040
- }
217041
- }
217042
-
217043
- class PackageNotFoundError extends Error {
217044
- constructor(message) {
217045
- super(message);
217046
- }
217047
- }
217048
-
217049
- class ModelNotFoundError extends Error {
217050
- constructor(message) {
217051
- super(message);
217052
- }
217053
- }
217054
-
217055
- class ConnectionNotFoundError extends Error {
217056
- constructor(message) {
217057
- super(message);
217058
- }
217059
- }
217060
-
217061
- class ConnectionError extends Error {
217062
- constructor(message) {
217063
- super(message);
217064
- }
217065
- }
217066
-
217067
- class ConnectionAuthError extends Error {
217068
- constructor(message) {
217069
- super(message);
217070
- }
217071
- }
217072
-
217073
- class ModelCompilationError extends Error {
217074
- constructor(error) {
217075
- super(error.message);
217076
- }
217077
- }
217078
-
217079
- class FrozenConfigError extends Error {
217080
- constructor(message = `Publisher config can't be updated when ${PUBLISHER_CONFIG_NAME} has { "frozenConfig": true }`) {
217081
- super(message);
217082
- }
217083
- }
217084
-
217085
- class MaterializationNotFoundError extends Error {
217086
- constructor(message) {
217087
- super(message);
217088
- }
217089
- }
217090
-
217091
- class MaterializationConflictError extends Error {
217092
- constructor(message) {
217093
- super(message);
217094
- }
217095
- }
217096
-
217097
- class InvalidStateTransitionError extends Error {
217098
- constructor(message) {
217099
- super(message);
217100
- }
217101
- }
217529
+ // src/controller/connection.controller.ts
217530
+ init_errors();
217531
+ init_logger();
217102
217532
 
217103
217533
  // src/service/connection.ts
217104
217534
  import"@malloydata/db-bigquery";
@@ -220383,10 +220813,12 @@ var {
220383
220813
  } = axios_default;
220384
220814
 
220385
220815
  // src/service/connection.ts
220816
+ init_logger();
220386
220817
  import fs from "fs/promises";
220387
220818
  import path2 from "path";
220388
220819
 
220389
220820
  // src/pg_helpers.ts
220821
+ init_errors();
220390
220822
  function pgConnectTimeoutSeconds() {
220391
220823
  const raw = process.env.PG_CONNECT_TIMEOUT_SECONDS;
220392
220824
  if (!raw)
@@ -221637,6 +222069,8 @@ async function testConnectionConfig(connectionConfig) {
221637
222069
  }
221638
222070
 
221639
222071
  // src/service/connection_service.ts
222072
+ init_errors();
222073
+ init_logger();
221640
222074
  async function runEnvironmentConnectionUpdate(environment, fn) {
221641
222075
  if (environment.runConnectionUpdateExclusive) {
221642
222076
  return environment.runConnectionUpdateExclusive(fn);
@@ -221748,11 +222182,13 @@ class ConnectionService {
221748
222182
  }
221749
222183
 
221750
222184
  // src/service/db_utils.ts
222185
+ init_logger();
221751
222186
  var import_bigquery = __toESM(require_src121(), 1);
221752
222187
  import { ClientSecretCredential } from "@azure/identity";
221753
222188
  import { ContainerClient } from "@azure/storage-blob";
221754
222189
 
221755
222190
  // src/service/gcs_s3_utils.ts
222191
+ init_logger();
221756
222192
  var import_client_s3 = __toESM(require_dist_cjs75(), 1);
221757
222193
  function gcsConnectionToCredentials(gcsConnection) {
221758
222194
  return {
@@ -223100,6 +223536,8 @@ class DatabaseController {
223100
223536
  }
223101
223537
 
223102
223538
  // src/controller/model.controller.ts
223539
+ init_errors();
223540
+
223103
223541
  class ModelController {
223104
223542
  environmentStore;
223105
223543
  constructor(environmentStore) {
@@ -223146,7 +223584,7 @@ class ModelController {
223146
223584
  }
223147
223585
  return model.getNotebook();
223148
223586
  }
223149
- async executeNotebookCell(environmentName, packageName, notebookPath, cellIndex, filterParams, bypassFilters) {
223587
+ async executeNotebookCell(environmentName, packageName, notebookPath, cellIndex, filterParams, bypassFilters, givens) {
223150
223588
  const environment = await this.environmentStore.getEnvironment(environmentName, false);
223151
223589
  const p = await environment.getPackage(packageName, false);
223152
223590
  const model = p.getModel(notebookPath);
@@ -223156,12 +223594,14 @@ class ModelController {
223156
223594
  if (model.getType() === "model") {
223157
223595
  throw new ModelNotFoundError(`${notebookPath} is a model`);
223158
223596
  }
223159
- return model.executeNotebookCell(cellIndex, filterParams, bypassFilters);
223597
+ return model.executeNotebookCell(cellIndex, filterParams, bypassFilters, givens);
223160
223598
  }
223161
223599
  }
223162
223600
 
223163
223601
  // src/controller/package.controller.ts
223164
- import * as path3 from "path";
223602
+ init_errors();
223603
+ init_logger();
223604
+
223165
223605
  class PackageController {
223166
223606
  environmentStore;
223167
223607
  manifestService;
@@ -223175,11 +223615,20 @@ class PackageController {
223175
223615
  }
223176
223616
  async getPackage(environmentName, packageName, reload) {
223177
223617
  const environment = await this.environmentStore.getEnvironment(environmentName, false);
223178
- const _package = await environment.getPackage(packageName, reload);
223179
- const packageLocation = _package.getPackageMetadata().location;
223180
- if (reload && packageLocation) {
223181
- await this.downloadPackage(environmentName, packageName, packageLocation);
223618
+ if (reload) {
223619
+ let location;
223620
+ try {
223621
+ const cached = await environment.getPackage(packageName, false);
223622
+ location = cached.getPackageMetadata().location;
223623
+ } catch {}
223624
+ if (location) {
223625
+ const reinstalled = await environment.installPackage(packageName, (stagingPath) => this.downloadInto(environmentName, packageName, location, stagingPath));
223626
+ return reinstalled.getPackageMetadata();
223627
+ }
223628
+ const _package2 = await environment.getPackage(packageName, true);
223629
+ return _package2.getPackageMetadata();
223182
223630
  }
223631
+ const _package = await environment.getPackage(packageName, false);
223183
223632
  return _package.getPackageMetadata();
223184
223633
  }
223185
223634
  async addPackage(environmentName, body, options) {
@@ -223189,14 +223638,18 @@ class PackageController {
223189
223638
  if (!body.name) {
223190
223639
  throw new BadRequestError("Package name is required");
223191
223640
  }
223641
+ const packageName = body.name;
223192
223642
  const environment = await this.environmentStore.getEnvironment(environmentName, false);
223643
+ let result;
223193
223644
  if (body.location) {
223194
- await this.downloadPackage(environmentName, body.name, body.location);
223645
+ const bodyLocation = body.location;
223646
+ result = await environment.installPackage(packageName, (stagingPath) => this.downloadInto(environmentName, packageName, bodyLocation, stagingPath));
223647
+ } else {
223648
+ result = await environment.addPackage(packageName);
223195
223649
  }
223196
- const result = await environment.addPackage(body.name);
223197
- await this.environmentStore.addPackageToDatabase(environmentName, body.name);
223650
+ await this.environmentStore.addPackageToDatabase(environmentName, packageName);
223198
223651
  if (options?.autoLoadManifest === true) {
223199
- await this.tryLoadExistingManifest(environmentName, body.name);
223652
+ await this.tryLoadExistingManifest(environmentName, packageName);
223200
223653
  }
223201
223654
  return result;
223202
223655
  }
@@ -223238,29 +223691,31 @@ class PackageController {
223238
223691
  }
223239
223692
  const environment = await this.environmentStore.getEnvironment(environmentName, false);
223240
223693
  if (body.location) {
223241
- await this.downloadPackage(environmentName, packageName, body.location);
223694
+ const bodyLocation = body.location;
223695
+ await environment.installPackage(packageName, (stagingPath) => this.downloadInto(environmentName, packageName, bodyLocation, stagingPath));
223242
223696
  }
223243
223697
  const result = await environment.updatePackage(packageName, body);
223244
223698
  await this.environmentStore.addPackageToDatabase(environmentName, packageName);
223245
223699
  return result;
223246
223700
  }
223247
- async downloadPackage(environmentName, packageName, packageLocation) {
223248
- const absoluteTargetPath = path3.join(this.environmentStore.serverRootPath, PUBLISHER_DATA_DIR, environmentName, packageName);
223701
+ async downloadInto(environmentName, packageName, packageLocation, targetPath) {
223249
223702
  const isCompressedFile = packageLocation.endsWith(".zip");
223250
223703
  if (packageLocation.startsWith("https://") || packageLocation.startsWith("git@")) {
223251
- await this.environmentStore.downloadGitHubDirectory(packageLocation, absoluteTargetPath);
223704
+ await this.environmentStore.downloadGitHubDirectory(packageLocation, targetPath);
223252
223705
  } else if (packageLocation.startsWith("gs://")) {
223253
- await this.environmentStore.downloadGcsDirectory(packageLocation, environmentName, absoluteTargetPath, isCompressedFile);
223706
+ await this.environmentStore.downloadGcsDirectory(packageLocation, environmentName, targetPath, isCompressedFile);
223254
223707
  } else if (packageLocation.startsWith("s3://")) {
223255
- await this.environmentStore.downloadS3Directory(packageLocation, environmentName, absoluteTargetPath, isCompressedFile);
223708
+ await this.environmentStore.downloadS3Directory(packageLocation, environmentName, targetPath, isCompressedFile);
223256
223709
  }
223257
223710
  if (packageLocation.startsWith("/")) {
223258
- await this.environmentStore.mountLocalDirectory(packageLocation, absoluteTargetPath, environmentName, packageName);
223711
+ await this.environmentStore.mountLocalDirectory(packageLocation, targetPath, environmentName, packageName);
223259
223712
  }
223260
223713
  }
223261
223714
  }
223262
223715
 
223263
223716
  // src/controller/query.controller.ts
223717
+ init_constants();
223718
+ init_errors();
223264
223719
  var import_render_validator = __toESM(require_dist10(), 1);
223265
223720
  function bigIntReplacer(_key, value) {
223266
223721
  if (typeof value === "bigint") {
@@ -223274,14 +223729,14 @@ class QueryController {
223274
223729
  constructor(environmentStore) {
223275
223730
  this.environmentStore = environmentStore;
223276
223731
  }
223277
- async getQuery(environmentName, packageName, modelPath, sourceName, queryName, query, compactJson = false, filterParams, bypassFilters) {
223732
+ async getQuery(environmentName, packageName, modelPath, sourceName, queryName, query, compactJson = false, filterParams, bypassFilters, givens) {
223278
223733
  const environment = await this.environmentStore.getEnvironment(environmentName, false);
223279
223734
  const p = await environment.getPackage(packageName, false);
223280
223735
  const model = p.getModel(modelPath);
223281
223736
  if (!model) {
223282
223737
  throw new ModelNotFoundError(`${modelPath} does not exist`);
223283
223738
  } else {
223284
- const { result, compactResult } = await model.getQueryResults(sourceName, queryName, query, filterParams, bypassFilters);
223739
+ const { result, compactResult } = await model.getQueryResults(sourceName, queryName, query, filterParams, bypassFilters, givens);
223285
223740
  const renderLogs = import_render_validator.validateRenderTags(result);
223286
223741
  return {
223287
223742
  result: compactJson ? JSON.stringify(compactResult, bigIntReplacer) : JSON.stringify(result),
@@ -223369,7 +223824,7 @@ class ReaddirpStream extends Readable2 {
223369
223824
  this._directoryFilter = normalizeFilter(opts.directoryFilter);
223370
223825
  const statMethod = opts.lstat ? lstat : stat;
223371
223826
  if (wantBigintFsStats) {
223372
- this._stat = (path4) => statMethod(path4, { bigint: true });
223827
+ this._stat = (path3) => statMethod(path3, { bigint: true });
223373
223828
  } else {
223374
223829
  this._stat = statMethod;
223375
223830
  }
@@ -223394,8 +223849,8 @@ class ReaddirpStream extends Readable2 {
223394
223849
  const par = this.parent;
223395
223850
  const fil = par && par.files;
223396
223851
  if (fil && fil.length > 0) {
223397
- const { path: path4, depth } = par;
223398
- const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path4));
223852
+ const { path: path3, depth } = par;
223853
+ const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path3));
223399
223854
  const awaited = await Promise.all(slice);
223400
223855
  for (const entry of awaited) {
223401
223856
  if (!entry)
@@ -223435,20 +223890,20 @@ class ReaddirpStream extends Readable2 {
223435
223890
  this.reading = false;
223436
223891
  }
223437
223892
  }
223438
- async _exploreDir(path4, depth) {
223893
+ async _exploreDir(path3, depth) {
223439
223894
  let files;
223440
223895
  try {
223441
- files = await readdir(path4, this._rdOptions);
223896
+ files = await readdir(path3, this._rdOptions);
223442
223897
  } catch (error) {
223443
223898
  this._onError(error);
223444
223899
  }
223445
- return { files, depth, path: path4 };
223900
+ return { files, depth, path: path3 };
223446
223901
  }
223447
- async _formatEntry(dirent, path4) {
223902
+ async _formatEntry(dirent, path3) {
223448
223903
  let entry;
223449
223904
  const basename = this._isDirent ? dirent.name : dirent;
223450
223905
  try {
223451
- const fullPath = presolve(pjoin(path4, basename));
223906
+ const fullPath = presolve(pjoin(path3, basename));
223452
223907
  entry = { path: prelative(this._root, fullPath), fullPath, basename };
223453
223908
  entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
223454
223909
  } catch (err) {
@@ -223847,16 +224302,16 @@ var delFromSet = (main, prop, item) => {
223847
224302
  };
223848
224303
  var isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
223849
224304
  var FsWatchInstances = new Map;
223850
- function createFsWatchInstance(path4, options, listener, errHandler, emitRaw) {
224305
+ function createFsWatchInstance(path3, options, listener, errHandler, emitRaw) {
223851
224306
  const handleEvent = (rawEvent, evPath) => {
223852
- listener(path4);
223853
- emitRaw(rawEvent, evPath, { watchedPath: path4 });
223854
- if (evPath && path4 !== evPath) {
223855
- fsWatchBroadcast(sysPath.resolve(path4, evPath), KEY_LISTENERS, sysPath.join(path4, evPath));
224307
+ listener(path3);
224308
+ emitRaw(rawEvent, evPath, { watchedPath: path3 });
224309
+ if (evPath && path3 !== evPath) {
224310
+ fsWatchBroadcast(sysPath.resolve(path3, evPath), KEY_LISTENERS, sysPath.join(path3, evPath));
223856
224311
  }
223857
224312
  };
223858
224313
  try {
223859
- return fs_watch(path4, {
224314
+ return fs_watch(path3, {
223860
224315
  persistent: options.persistent
223861
224316
  }, handleEvent);
223862
224317
  } catch (error) {
@@ -223872,12 +224327,12 @@ var fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
223872
224327
  listener(val1, val2, val3);
223873
224328
  });
223874
224329
  };
223875
- var setFsWatchListener = (path4, fullPath, options, handlers) => {
224330
+ var setFsWatchListener = (path3, fullPath, options, handlers) => {
223876
224331
  const { listener, errHandler, rawEmitter } = handlers;
223877
224332
  let cont = FsWatchInstances.get(fullPath);
223878
224333
  let watcher;
223879
224334
  if (!options.persistent) {
223880
- watcher = createFsWatchInstance(path4, options, listener, errHandler, rawEmitter);
224335
+ watcher = createFsWatchInstance(path3, options, listener, errHandler, rawEmitter);
223881
224336
  if (!watcher)
223882
224337
  return;
223883
224338
  return watcher.close.bind(watcher);
@@ -223887,7 +224342,7 @@ var setFsWatchListener = (path4, fullPath, options, handlers) => {
223887
224342
  addAndConvert(cont, KEY_ERR, errHandler);
223888
224343
  addAndConvert(cont, KEY_RAW, rawEmitter);
223889
224344
  } else {
223890
- watcher = createFsWatchInstance(path4, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, fsWatchBroadcast.bind(null, fullPath, KEY_RAW));
224345
+ watcher = createFsWatchInstance(path3, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, fsWatchBroadcast.bind(null, fullPath, KEY_RAW));
223891
224346
  if (!watcher)
223892
224347
  return;
223893
224348
  watcher.on(EV.ERROR, async (error) => {
@@ -223896,7 +224351,7 @@ var setFsWatchListener = (path4, fullPath, options, handlers) => {
223896
224351
  cont.watcherUnusable = true;
223897
224352
  if (isWindows && error.code === "EPERM") {
223898
224353
  try {
223899
- const fd = await open(path4, "r");
224354
+ const fd = await open(path3, "r");
223900
224355
  await fd.close();
223901
224356
  broadcastErr(error);
223902
224357
  } catch (err) {}
@@ -223926,7 +224381,7 @@ var setFsWatchListener = (path4, fullPath, options, handlers) => {
223926
224381
  };
223927
224382
  };
223928
224383
  var FsWatchFileInstances = new Map;
223929
- var setFsWatchFileListener = (path4, fullPath, options, handlers) => {
224384
+ var setFsWatchFileListener = (path3, fullPath, options, handlers) => {
223930
224385
  const { listener, rawEmitter } = handlers;
223931
224386
  let cont = FsWatchFileInstances.get(fullPath);
223932
224387
  const copts = cont && cont.options;
@@ -223948,7 +224403,7 @@ var setFsWatchFileListener = (path4, fullPath, options, handlers) => {
223948
224403
  });
223949
224404
  const currmtime = curr.mtimeMs;
223950
224405
  if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
223951
- foreach(cont.listeners, (listener2) => listener2(path4, curr));
224406
+ foreach(cont.listeners, (listener2) => listener2(path3, curr));
223952
224407
  }
223953
224408
  })
223954
224409
  };
@@ -223971,13 +224426,13 @@ class NodeFsHandler {
223971
224426
  this.fsw = fsW;
223972
224427
  this._boundHandleError = (error) => fsW._handleError(error);
223973
224428
  }
223974
- _watchWithNodeFs(path4, listener) {
224429
+ _watchWithNodeFs(path3, listener) {
223975
224430
  const opts = this.fsw.options;
223976
- const directory = sysPath.dirname(path4);
223977
- const basename2 = sysPath.basename(path4);
224431
+ const directory = sysPath.dirname(path3);
224432
+ const basename2 = sysPath.basename(path3);
223978
224433
  const parent = this.fsw._getWatchedDir(directory);
223979
224434
  parent.add(basename2);
223980
- const absolutePath = sysPath.resolve(path4);
224435
+ const absolutePath = sysPath.resolve(path3);
223981
224436
  const options = {
223982
224437
  persistent: opts.persistent
223983
224438
  };
@@ -223987,12 +224442,12 @@ class NodeFsHandler {
223987
224442
  if (opts.usePolling) {
223988
224443
  const enableBin = opts.interval !== opts.binaryInterval;
223989
224444
  options.interval = enableBin && isBinaryPath(basename2) ? opts.binaryInterval : opts.interval;
223990
- closer = setFsWatchFileListener(path4, absolutePath, options, {
224445
+ closer = setFsWatchFileListener(path3, absolutePath, options, {
223991
224446
  listener,
223992
224447
  rawEmitter: this.fsw._emitRaw
223993
224448
  });
223994
224449
  } else {
223995
- closer = setFsWatchListener(path4, absolutePath, options, {
224450
+ closer = setFsWatchListener(path3, absolutePath, options, {
223996
224451
  listener,
223997
224452
  errHandler: this._boundHandleError,
223998
224453
  rawEmitter: this.fsw._emitRaw
@@ -224010,7 +224465,7 @@ class NodeFsHandler {
224010
224465
  let prevStats = stats;
224011
224466
  if (parent.has(basename2))
224012
224467
  return;
224013
- const listener = async (path4, newStats) => {
224468
+ const listener = async (path3, newStats) => {
224014
224469
  if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
224015
224470
  return;
224016
224471
  if (!newStats || newStats.mtimeMs === 0) {
@@ -224024,11 +224479,11 @@ class NodeFsHandler {
224024
224479
  this.fsw._emit(EV.CHANGE, file, newStats2);
224025
224480
  }
224026
224481
  if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
224027
- this.fsw._closeFile(path4);
224482
+ this.fsw._closeFile(path3);
224028
224483
  prevStats = newStats2;
224029
224484
  const closer2 = this._watchWithNodeFs(file, listener);
224030
224485
  if (closer2)
224031
- this.fsw._addPathCloser(path4, closer2);
224486
+ this.fsw._addPathCloser(path3, closer2);
224032
224487
  } else {
224033
224488
  prevStats = newStats2;
224034
224489
  }
@@ -224052,7 +224507,7 @@ class NodeFsHandler {
224052
224507
  }
224053
224508
  return closer;
224054
224509
  }
224055
- async _handleSymlink(entry, directory, path4, item) {
224510
+ async _handleSymlink(entry, directory, path3, item) {
224056
224511
  if (this.fsw.closed) {
224057
224512
  return;
224058
224513
  }
@@ -224062,7 +224517,7 @@ class NodeFsHandler {
224062
224517
  this.fsw._incrReadyCount();
224063
224518
  let linkPath;
224064
224519
  try {
224065
- linkPath = await fsrealpath(path4);
224520
+ linkPath = await fsrealpath(path3);
224066
224521
  } catch (e) {
224067
224522
  this.fsw._emitReady();
224068
224523
  return true;
@@ -224072,12 +224527,12 @@ class NodeFsHandler {
224072
224527
  if (dir.has(item)) {
224073
224528
  if (this.fsw._symlinkPaths.get(full) !== linkPath) {
224074
224529
  this.fsw._symlinkPaths.set(full, linkPath);
224075
- this.fsw._emit(EV.CHANGE, path4, entry.stats);
224530
+ this.fsw._emit(EV.CHANGE, path3, entry.stats);
224076
224531
  }
224077
224532
  } else {
224078
224533
  dir.add(item);
224079
224534
  this.fsw._symlinkPaths.set(full, linkPath);
224080
- this.fsw._emit(EV.ADD, path4, entry.stats);
224535
+ this.fsw._emit(EV.ADD, path3, entry.stats);
224081
224536
  }
224082
224537
  this.fsw._emitReady();
224083
224538
  return true;
@@ -224106,9 +224561,9 @@ class NodeFsHandler {
224106
224561
  return;
224107
224562
  }
224108
224563
  const item = entry.path;
224109
- let path4 = sysPath.join(directory, item);
224564
+ let path3 = sysPath.join(directory, item);
224110
224565
  current.add(item);
224111
- if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path4, item)) {
224566
+ if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path3, item)) {
224112
224567
  return;
224113
224568
  }
224114
224569
  if (this.fsw.closed) {
@@ -224117,8 +224572,8 @@ class NodeFsHandler {
224117
224572
  }
224118
224573
  if (item === target || !target && !previous.has(item)) {
224119
224574
  this.fsw._incrReadyCount();
224120
- path4 = sysPath.join(dir, sysPath.relative(dir, path4));
224121
- this._addToNodeFs(path4, initialAdd, wh, depth + 1);
224575
+ path3 = sysPath.join(dir, sysPath.relative(dir, path3));
224576
+ this._addToNodeFs(path3, initialAdd, wh, depth + 1);
224122
224577
  }
224123
224578
  }).on(EV.ERROR, this._boundHandleError);
224124
224579
  return new Promise((resolve2, reject) => {
@@ -224167,13 +224622,13 @@ class NodeFsHandler {
224167
224622
  }
224168
224623
  return closer;
224169
224624
  }
224170
- async _addToNodeFs(path4, initialAdd, priorWh, depth, target) {
224625
+ async _addToNodeFs(path3, initialAdd, priorWh, depth, target) {
224171
224626
  const ready = this.fsw._emitReady;
224172
- if (this.fsw._isIgnored(path4) || this.fsw.closed) {
224627
+ if (this.fsw._isIgnored(path3) || this.fsw.closed) {
224173
224628
  ready();
224174
224629
  return false;
224175
224630
  }
224176
- const wh = this.fsw._getWatchHelpers(path4);
224631
+ const wh = this.fsw._getWatchHelpers(path3);
224177
224632
  if (priorWh) {
224178
224633
  wh.filterPath = (entry) => priorWh.filterPath(entry);
224179
224634
  wh.filterDir = (entry) => priorWh.filterDir(entry);
@@ -224189,8 +224644,8 @@ class NodeFsHandler {
224189
224644
  const follow = this.fsw.options.followSymlinks;
224190
224645
  let closer;
224191
224646
  if (stats.isDirectory()) {
224192
- const absPath = sysPath.resolve(path4);
224193
- const targetPath = follow ? await fsrealpath(path4) : path4;
224647
+ const absPath = sysPath.resolve(path3);
224648
+ const targetPath = follow ? await fsrealpath(path3) : path3;
224194
224649
  if (this.fsw.closed)
224195
224650
  return;
224196
224651
  closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
@@ -224200,29 +224655,29 @@ class NodeFsHandler {
224200
224655
  this.fsw._symlinkPaths.set(absPath, targetPath);
224201
224656
  }
224202
224657
  } else if (stats.isSymbolicLink()) {
224203
- const targetPath = follow ? await fsrealpath(path4) : path4;
224658
+ const targetPath = follow ? await fsrealpath(path3) : path3;
224204
224659
  if (this.fsw.closed)
224205
224660
  return;
224206
224661
  const parent = sysPath.dirname(wh.watchPath);
224207
224662
  this.fsw._getWatchedDir(parent).add(wh.watchPath);
224208
224663
  this.fsw._emit(EV.ADD, wh.watchPath, stats);
224209
- closer = await this._handleDir(parent, stats, initialAdd, depth, path4, wh, targetPath);
224664
+ closer = await this._handleDir(parent, stats, initialAdd, depth, path3, wh, targetPath);
224210
224665
  if (this.fsw.closed)
224211
224666
  return;
224212
224667
  if (targetPath !== undefined) {
224213
- this.fsw._symlinkPaths.set(sysPath.resolve(path4), targetPath);
224668
+ this.fsw._symlinkPaths.set(sysPath.resolve(path3), targetPath);
224214
224669
  }
224215
224670
  } else {
224216
224671
  closer = this._handleFile(wh.watchPath, stats, initialAdd);
224217
224672
  }
224218
224673
  ready();
224219
224674
  if (closer)
224220
- this.fsw._addPathCloser(path4, closer);
224675
+ this.fsw._addPathCloser(path3, closer);
224221
224676
  return false;
224222
224677
  } catch (error) {
224223
224678
  if (this.fsw._handleError(error)) {
224224
224679
  ready();
224225
- return path4;
224680
+ return path3;
224226
224681
  }
224227
224682
  }
224228
224683
  }
@@ -224266,26 +224721,26 @@ function createPattern(matcher) {
224266
224721
  }
224267
224722
  return () => false;
224268
224723
  }
224269
- function normalizePath(path4) {
224270
- if (typeof path4 !== "string")
224724
+ function normalizePath(path3) {
224725
+ if (typeof path3 !== "string")
224271
224726
  throw new Error("string expected");
224272
- path4 = sysPath2.normalize(path4);
224273
- path4 = path4.replace(/\\/g, "/");
224727
+ path3 = sysPath2.normalize(path3);
224728
+ path3 = path3.replace(/\\/g, "/");
224274
224729
  let prepend = false;
224275
- if (path4.startsWith("//"))
224730
+ if (path3.startsWith("//"))
224276
224731
  prepend = true;
224277
224732
  const DOUBLE_SLASH_RE2 = /\/\//;
224278
- while (path4.match(DOUBLE_SLASH_RE2))
224279
- path4 = path4.replace(DOUBLE_SLASH_RE2, "/");
224733
+ while (path3.match(DOUBLE_SLASH_RE2))
224734
+ path3 = path3.replace(DOUBLE_SLASH_RE2, "/");
224280
224735
  if (prepend)
224281
- path4 = "/" + path4;
224282
- return path4;
224736
+ path3 = "/" + path3;
224737
+ return path3;
224283
224738
  }
224284
224739
  function matchPatterns(patterns, testString, stats) {
224285
- const path4 = normalizePath(testString);
224740
+ const path3 = normalizePath(testString);
224286
224741
  for (let index = 0;index < patterns.length; index++) {
224287
224742
  const pattern = patterns[index];
224288
- if (pattern(path4, stats)) {
224743
+ if (pattern(path3, stats)) {
224289
224744
  return true;
224290
224745
  }
224291
224746
  }
@@ -224325,19 +224780,19 @@ var toUnix = (string) => {
224325
224780
  }
224326
224781
  return str;
224327
224782
  };
224328
- var normalizePathToUnix = (path4) => toUnix(sysPath2.normalize(toUnix(path4)));
224329
- var normalizeIgnored = (cwd = "") => (path4) => {
224330
- if (typeof path4 === "string") {
224331
- return normalizePathToUnix(sysPath2.isAbsolute(path4) ? path4 : sysPath2.join(cwd, path4));
224783
+ var normalizePathToUnix = (path3) => toUnix(sysPath2.normalize(toUnix(path3)));
224784
+ var normalizeIgnored = (cwd = "") => (path3) => {
224785
+ if (typeof path3 === "string") {
224786
+ return normalizePathToUnix(sysPath2.isAbsolute(path3) ? path3 : sysPath2.join(cwd, path3));
224332
224787
  } else {
224333
- return path4;
224788
+ return path3;
224334
224789
  }
224335
224790
  };
224336
- var getAbsolutePath = (path4, cwd) => {
224337
- if (sysPath2.isAbsolute(path4)) {
224338
- return path4;
224791
+ var getAbsolutePath = (path3, cwd) => {
224792
+ if (sysPath2.isAbsolute(path3)) {
224793
+ return path3;
224339
224794
  }
224340
- return sysPath2.join(cwd, path4);
224795
+ return sysPath2.join(cwd, path3);
224341
224796
  };
224342
224797
  var EMPTY_SET = Object.freeze(new Set);
224343
224798
 
@@ -224394,10 +224849,10 @@ var STAT_METHOD_F = "stat";
224394
224849
  var STAT_METHOD_L = "lstat";
224395
224850
 
224396
224851
  class WatchHelper {
224397
- constructor(path4, follow, fsw) {
224852
+ constructor(path3, follow, fsw) {
224398
224853
  this.fsw = fsw;
224399
- const watchPath = path4;
224400
- this.path = path4 = path4.replace(REPLACER_RE, "");
224854
+ const watchPath = path3;
224855
+ this.path = path3 = path3.replace(REPLACER_RE, "");
224401
224856
  this.watchPath = watchPath;
224402
224857
  this.fullWatchPath = sysPath2.resolve(watchPath);
224403
224858
  this.dirParts = [];
@@ -224510,20 +224965,20 @@ class FSWatcher extends EventEmitter2 {
224510
224965
  this._closePromise = undefined;
224511
224966
  let paths = unifyPaths(paths_);
224512
224967
  if (cwd) {
224513
- paths = paths.map((path4) => {
224514
- const absPath = getAbsolutePath(path4, cwd);
224968
+ paths = paths.map((path3) => {
224969
+ const absPath = getAbsolutePath(path3, cwd);
224515
224970
  return absPath;
224516
224971
  });
224517
224972
  }
224518
- paths.forEach((path4) => {
224519
- this._removeIgnoredPath(path4);
224973
+ paths.forEach((path3) => {
224974
+ this._removeIgnoredPath(path3);
224520
224975
  });
224521
224976
  this._userIgnored = undefined;
224522
224977
  if (!this._readyCount)
224523
224978
  this._readyCount = 0;
224524
224979
  this._readyCount += paths.length;
224525
- Promise.all(paths.map(async (path4) => {
224526
- const res = await this._nodeFsHandler._addToNodeFs(path4, !_internal, undefined, 0, _origAdd);
224980
+ Promise.all(paths.map(async (path3) => {
224981
+ const res = await this._nodeFsHandler._addToNodeFs(path3, !_internal, undefined, 0, _origAdd);
224527
224982
  if (res)
224528
224983
  this._emitReady();
224529
224984
  return res;
@@ -224542,17 +224997,17 @@ class FSWatcher extends EventEmitter2 {
224542
224997
  return this;
224543
224998
  const paths = unifyPaths(paths_);
224544
224999
  const { cwd } = this.options;
224545
- paths.forEach((path4) => {
224546
- if (!sysPath2.isAbsolute(path4) && !this._closers.has(path4)) {
225000
+ paths.forEach((path3) => {
225001
+ if (!sysPath2.isAbsolute(path3) && !this._closers.has(path3)) {
224547
225002
  if (cwd)
224548
- path4 = sysPath2.join(cwd, path4);
224549
- path4 = sysPath2.resolve(path4);
225003
+ path3 = sysPath2.join(cwd, path3);
225004
+ path3 = sysPath2.resolve(path3);
224550
225005
  }
224551
- this._closePath(path4);
224552
- this._addIgnoredPath(path4);
224553
- if (this._watched.has(path4)) {
225006
+ this._closePath(path3);
225007
+ this._addIgnoredPath(path3);
225008
+ if (this._watched.has(path3)) {
224554
225009
  this._addIgnoredPath({
224555
- path: path4,
225010
+ path: path3,
224556
225011
  recursive: true
224557
225012
  });
224558
225013
  }
@@ -224601,38 +225056,38 @@ class FSWatcher extends EventEmitter2 {
224601
225056
  if (event !== EVENTS.ERROR)
224602
225057
  this.emit(EVENTS.ALL, event, ...args);
224603
225058
  }
224604
- async _emit(event, path4, stats) {
225059
+ async _emit(event, path3, stats) {
224605
225060
  if (this.closed)
224606
225061
  return;
224607
225062
  const opts = this.options;
224608
225063
  if (isWindows)
224609
- path4 = sysPath2.normalize(path4);
225064
+ path3 = sysPath2.normalize(path3);
224610
225065
  if (opts.cwd)
224611
- path4 = sysPath2.relative(opts.cwd, path4);
224612
- const args = [path4];
225066
+ path3 = sysPath2.relative(opts.cwd, path3);
225067
+ const args = [path3];
224613
225068
  if (stats != null)
224614
225069
  args.push(stats);
224615
225070
  const awf = opts.awaitWriteFinish;
224616
225071
  let pw;
224617
- if (awf && (pw = this._pendingWrites.get(path4))) {
225072
+ if (awf && (pw = this._pendingWrites.get(path3))) {
224618
225073
  pw.lastChange = new Date;
224619
225074
  return this;
224620
225075
  }
224621
225076
  if (opts.atomic) {
224622
225077
  if (event === EVENTS.UNLINK) {
224623
- this._pendingUnlinks.set(path4, [event, ...args]);
225078
+ this._pendingUnlinks.set(path3, [event, ...args]);
224624
225079
  setTimeout(() => {
224625
- this._pendingUnlinks.forEach((entry, path5) => {
225080
+ this._pendingUnlinks.forEach((entry, path4) => {
224626
225081
  this.emit(...entry);
224627
225082
  this.emit(EVENTS.ALL, ...entry);
224628
- this._pendingUnlinks.delete(path5);
225083
+ this._pendingUnlinks.delete(path4);
224629
225084
  });
224630
225085
  }, typeof opts.atomic === "number" ? opts.atomic : 100);
224631
225086
  return this;
224632
225087
  }
224633
- if (event === EVENTS.ADD && this._pendingUnlinks.has(path4)) {
225088
+ if (event === EVENTS.ADD && this._pendingUnlinks.has(path3)) {
224634
225089
  event = EVENTS.CHANGE;
224635
- this._pendingUnlinks.delete(path4);
225090
+ this._pendingUnlinks.delete(path3);
224636
225091
  }
224637
225092
  }
224638
225093
  if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
@@ -224650,16 +225105,16 @@ class FSWatcher extends EventEmitter2 {
224650
225105
  this.emitWithAll(event, args);
224651
225106
  }
224652
225107
  };
224653
- this._awaitWriteFinish(path4, awf.stabilityThreshold, event, awfEmit);
225108
+ this._awaitWriteFinish(path3, awf.stabilityThreshold, event, awfEmit);
224654
225109
  return this;
224655
225110
  }
224656
225111
  if (event === EVENTS.CHANGE) {
224657
- const isThrottled = !this._throttle(EVENTS.CHANGE, path4, 50);
225112
+ const isThrottled = !this._throttle(EVENTS.CHANGE, path3, 50);
224658
225113
  if (isThrottled)
224659
225114
  return this;
224660
225115
  }
224661
225116
  if (opts.alwaysStat && stats === undefined && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
224662
- const fullPath = opts.cwd ? sysPath2.join(opts.cwd, path4) : path4;
225117
+ const fullPath = opts.cwd ? sysPath2.join(opts.cwd, path3) : path3;
224663
225118
  let stats2;
224664
225119
  try {
224665
225120
  stats2 = await stat3(fullPath);
@@ -224678,23 +225133,23 @@ class FSWatcher extends EventEmitter2 {
224678
225133
  }
224679
225134
  return error || this.closed;
224680
225135
  }
224681
- _throttle(actionType, path4, timeout) {
225136
+ _throttle(actionType, path3, timeout) {
224682
225137
  if (!this._throttled.has(actionType)) {
224683
225138
  this._throttled.set(actionType, new Map);
224684
225139
  }
224685
225140
  const action = this._throttled.get(actionType);
224686
225141
  if (!action)
224687
225142
  throw new Error("invalid throttle");
224688
- const actionPath = action.get(path4);
225143
+ const actionPath = action.get(path3);
224689
225144
  if (actionPath) {
224690
225145
  actionPath.count++;
224691
225146
  return false;
224692
225147
  }
224693
225148
  let timeoutObject;
224694
225149
  const clear = () => {
224695
- const item = action.get(path4);
225150
+ const item = action.get(path3);
224696
225151
  const count = item ? item.count : 0;
224697
- action.delete(path4);
225152
+ action.delete(path3);
224698
225153
  clearTimeout(timeoutObject);
224699
225154
  if (item)
224700
225155
  clearTimeout(item.timeoutObject);
@@ -224702,50 +225157,50 @@ class FSWatcher extends EventEmitter2 {
224702
225157
  };
224703
225158
  timeoutObject = setTimeout(clear, timeout);
224704
225159
  const thr = { timeoutObject, clear, count: 0 };
224705
- action.set(path4, thr);
225160
+ action.set(path3, thr);
224706
225161
  return thr;
224707
225162
  }
224708
225163
  _incrReadyCount() {
224709
225164
  return this._readyCount++;
224710
225165
  }
224711
- _awaitWriteFinish(path4, threshold, event, awfEmit) {
225166
+ _awaitWriteFinish(path3, threshold, event, awfEmit) {
224712
225167
  const awf = this.options.awaitWriteFinish;
224713
225168
  if (typeof awf !== "object")
224714
225169
  return;
224715
225170
  const pollInterval = awf.pollInterval;
224716
225171
  let timeoutHandler;
224717
- let fullPath = path4;
224718
- if (this.options.cwd && !sysPath2.isAbsolute(path4)) {
224719
- fullPath = sysPath2.join(this.options.cwd, path4);
225172
+ let fullPath = path3;
225173
+ if (this.options.cwd && !sysPath2.isAbsolute(path3)) {
225174
+ fullPath = sysPath2.join(this.options.cwd, path3);
224720
225175
  }
224721
225176
  const now = new Date;
224722
225177
  const writes = this._pendingWrites;
224723
225178
  function awaitWriteFinishFn(prevStat) {
224724
225179
  statcb(fullPath, (err, curStat) => {
224725
- if (err || !writes.has(path4)) {
225180
+ if (err || !writes.has(path3)) {
224726
225181
  if (err && err.code !== "ENOENT")
224727
225182
  awfEmit(err);
224728
225183
  return;
224729
225184
  }
224730
225185
  const now2 = Number(new Date);
224731
225186
  if (prevStat && curStat.size !== prevStat.size) {
224732
- writes.get(path4).lastChange = now2;
225187
+ writes.get(path3).lastChange = now2;
224733
225188
  }
224734
- const pw = writes.get(path4);
225189
+ const pw = writes.get(path3);
224735
225190
  const df = now2 - pw.lastChange;
224736
225191
  if (df >= threshold) {
224737
- writes.delete(path4);
225192
+ writes.delete(path3);
224738
225193
  awfEmit(undefined, curStat);
224739
225194
  } else {
224740
225195
  timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
224741
225196
  }
224742
225197
  });
224743
225198
  }
224744
- if (!writes.has(path4)) {
224745
- writes.set(path4, {
225199
+ if (!writes.has(path3)) {
225200
+ writes.set(path3, {
224746
225201
  lastChange: now,
224747
225202
  cancelWait: () => {
224748
- writes.delete(path4);
225203
+ writes.delete(path3);
224749
225204
  clearTimeout(timeoutHandler);
224750
225205
  return event;
224751
225206
  }
@@ -224753,8 +225208,8 @@ class FSWatcher extends EventEmitter2 {
224753
225208
  timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
224754
225209
  }
224755
225210
  }
224756
- _isIgnored(path4, stats) {
224757
- if (this.options.atomic && DOT_RE.test(path4))
225211
+ _isIgnored(path3, stats) {
225212
+ if (this.options.atomic && DOT_RE.test(path3))
224758
225213
  return true;
224759
225214
  if (!this._userIgnored) {
224760
225215
  const { cwd } = this.options;
@@ -224764,13 +225219,13 @@ class FSWatcher extends EventEmitter2 {
224764
225219
  const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
224765
225220
  this._userIgnored = anymatch(list, undefined);
224766
225221
  }
224767
- return this._userIgnored(path4, stats);
225222
+ return this._userIgnored(path3, stats);
224768
225223
  }
224769
- _isntIgnored(path4, stat4) {
224770
- return !this._isIgnored(path4, stat4);
225224
+ _isntIgnored(path3, stat4) {
225225
+ return !this._isIgnored(path3, stat4);
224771
225226
  }
224772
- _getWatchHelpers(path4) {
224773
- return new WatchHelper(path4, this.options.followSymlinks, this);
225227
+ _getWatchHelpers(path3) {
225228
+ return new WatchHelper(path3, this.options.followSymlinks, this);
224774
225229
  }
224775
225230
  _getWatchedDir(directory) {
224776
225231
  const dir = sysPath2.resolve(directory);
@@ -224784,57 +225239,57 @@ class FSWatcher extends EventEmitter2 {
224784
225239
  return Boolean(Number(stats.mode) & 256);
224785
225240
  }
224786
225241
  _remove(directory, item, isDirectory) {
224787
- const path4 = sysPath2.join(directory, item);
224788
- const fullPath = sysPath2.resolve(path4);
224789
- isDirectory = isDirectory != null ? isDirectory : this._watched.has(path4) || this._watched.has(fullPath);
224790
- if (!this._throttle("remove", path4, 100))
225242
+ const path3 = sysPath2.join(directory, item);
225243
+ const fullPath = sysPath2.resolve(path3);
225244
+ isDirectory = isDirectory != null ? isDirectory : this._watched.has(path3) || this._watched.has(fullPath);
225245
+ if (!this._throttle("remove", path3, 100))
224791
225246
  return;
224792
225247
  if (!isDirectory && this._watched.size === 1) {
224793
225248
  this.add(directory, item, true);
224794
225249
  }
224795
- const wp = this._getWatchedDir(path4);
225250
+ const wp = this._getWatchedDir(path3);
224796
225251
  const nestedDirectoryChildren = wp.getChildren();
224797
- nestedDirectoryChildren.forEach((nested) => this._remove(path4, nested));
225252
+ nestedDirectoryChildren.forEach((nested) => this._remove(path3, nested));
224798
225253
  const parent = this._getWatchedDir(directory);
224799
225254
  const wasTracked = parent.has(item);
224800
225255
  parent.remove(item);
224801
225256
  if (this._symlinkPaths.has(fullPath)) {
224802
225257
  this._symlinkPaths.delete(fullPath);
224803
225258
  }
224804
- let relPath = path4;
225259
+ let relPath = path3;
224805
225260
  if (this.options.cwd)
224806
- relPath = sysPath2.relative(this.options.cwd, path4);
225261
+ relPath = sysPath2.relative(this.options.cwd, path3);
224807
225262
  if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
224808
225263
  const event = this._pendingWrites.get(relPath).cancelWait();
224809
225264
  if (event === EVENTS.ADD)
224810
225265
  return;
224811
225266
  }
224812
- this._watched.delete(path4);
225267
+ this._watched.delete(path3);
224813
225268
  this._watched.delete(fullPath);
224814
225269
  const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
224815
- if (wasTracked && !this._isIgnored(path4))
224816
- this._emit(eventName, path4);
224817
- this._closePath(path4);
225270
+ if (wasTracked && !this._isIgnored(path3))
225271
+ this._emit(eventName, path3);
225272
+ this._closePath(path3);
224818
225273
  }
224819
- _closePath(path4) {
224820
- this._closeFile(path4);
224821
- const dir = sysPath2.dirname(path4);
224822
- this._getWatchedDir(dir).remove(sysPath2.basename(path4));
225274
+ _closePath(path3) {
225275
+ this._closeFile(path3);
225276
+ const dir = sysPath2.dirname(path3);
225277
+ this._getWatchedDir(dir).remove(sysPath2.basename(path3));
224823
225278
  }
224824
- _closeFile(path4) {
224825
- const closers = this._closers.get(path4);
225279
+ _closeFile(path3) {
225280
+ const closers = this._closers.get(path3);
224826
225281
  if (!closers)
224827
225282
  return;
224828
225283
  closers.forEach((closer) => closer());
224829
- this._closers.delete(path4);
225284
+ this._closers.delete(path3);
224830
225285
  }
224831
- _addPathCloser(path4, closer) {
225286
+ _addPathCloser(path3, closer) {
224832
225287
  if (!closer)
224833
225288
  return;
224834
- let list = this._closers.get(path4);
225289
+ let list = this._closers.get(path3);
224835
225290
  if (!list) {
224836
225291
  list = [];
224837
- this._closers.set(path4, list);
225292
+ this._closers.set(path3, list);
224838
225293
  }
224839
225294
  list.push(closer);
224840
225295
  }
@@ -224864,6 +225319,7 @@ function watch(paths, options = {}) {
224864
225319
  var esm_default = { watch, FSWatcher };
224865
225320
 
224866
225321
  // src/controller/watch-mode.controller.ts
225322
+ init_logger();
224867
225323
  import path11 from "path";
224868
225324
 
224869
225325
  // src/service/environment_store.ts
@@ -225080,7 +225536,7 @@ class Mutex {
225080
225536
  }
225081
225537
 
225082
225538
  // src/service/environment_store.ts
225083
- import crypto4 from "crypto";
225539
+ import crypto5 from "crypto";
225084
225540
  import * as fs7 from "fs";
225085
225541
  import * as path10 from "path";
225086
225542
 
@@ -225096,7 +225552,7 @@ var __defProp2 = Object.defineProperty;
225096
225552
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
225097
225553
  var __getOwnPropNames2 = Object.getOwnPropertyNames;
225098
225554
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
225099
- var __esm = (fn, res) => function __init() {
225555
+ var __esm2 = (fn, res) => function __init() {
225100
225556
  return fn && (res = (0, fn[__getOwnPropNames2(fn)[0]])(fn = 0)), res;
225101
225557
  };
225102
225558
  var __commonJS2 = (cb, mod2) => function __require2() {
@@ -225120,20 +225576,20 @@ function pathspec(...paths) {
225120
225576
  cache.set(key, paths);
225121
225577
  return key;
225122
225578
  }
225123
- function isPathSpec(path4) {
225124
- return path4 instanceof String && cache.has(path4);
225579
+ function isPathSpec(path3) {
225580
+ return path3 instanceof String && cache.has(path3);
225125
225581
  }
225126
225582
  function toPaths(pathSpec) {
225127
225583
  return cache.get(pathSpec) || [];
225128
225584
  }
225129
225585
  var cache;
225130
- var init_pathspec = __esm({
225586
+ var init_pathspec = __esm2({
225131
225587
  "src/lib/args/pathspec.ts"() {
225132
225588
  cache = /* @__PURE__ */ new WeakMap;
225133
225589
  }
225134
225590
  });
225135
225591
  var GitError;
225136
- var init_git_error = __esm({
225592
+ var init_git_error = __esm2({
225137
225593
  "src/lib/errors/git-error.ts"() {
225138
225594
  GitError = class extends Error {
225139
225595
  constructor(task, message) {
@@ -225145,7 +225601,7 @@ var init_git_error = __esm({
225145
225601
  }
225146
225602
  });
225147
225603
  var GitResponseError;
225148
- var init_git_response_error = __esm({
225604
+ var init_git_response_error = __esm2({
225149
225605
  "src/lib/errors/git-response-error.ts"() {
225150
225606
  init_git_error();
225151
225607
  GitResponseError = class extends GitError {
@@ -225157,7 +225613,7 @@ var init_git_response_error = __esm({
225157
225613
  }
225158
225614
  });
225159
225615
  var TaskConfigurationError;
225160
- var init_task_configuration_error = __esm({
225616
+ var init_task_configuration_error = __esm2({
225161
225617
  "src/lib/errors/task-configuration-error.ts"() {
225162
225618
  init_git_error();
225163
225619
  TaskConfigurationError = class extends GitError {
@@ -225207,8 +225663,8 @@ function toLinesWithContent(input = "", trimmed2 = true, separator = `
225207
225663
  function forEachLineWithContent(input, callback) {
225208
225664
  return toLinesWithContent(input, true).map((line) => callback(line));
225209
225665
  }
225210
- function folderExists(path4) {
225211
- return import_file_exists.exists(path4, import_file_exists.FOLDER);
225666
+ function folderExists(path3) {
225667
+ return import_file_exists.exists(path3, import_file_exists.FOLDER);
225212
225668
  }
225213
225669
  function append2(target, item) {
225214
225670
  if (Array.isArray(target)) {
@@ -225280,7 +225736,7 @@ function orVoid(input) {
225280
225736
  var NULL;
225281
225737
  var NOOP;
225282
225738
  var objectToString;
225283
- var init_util = __esm({
225739
+ var init_util = __esm2({
225284
225740
  "src/lib/utils/util.ts"() {
225285
225741
  NULL = "\x00";
225286
225742
  NOOP = () => {};
@@ -225308,7 +225764,7 @@ var filterString;
225308
225764
  var filterStringArray;
225309
225765
  var filterStringOrStringArray;
225310
225766
  var filterHasLength;
225311
- var init_argument_filters = __esm({
225767
+ var init_argument_filters = __esm2({
225312
225768
  "src/lib/utils/argument-filters.ts"() {
225313
225769
  init_util();
225314
225770
  init_pathspec();
@@ -225333,7 +225789,7 @@ var init_argument_filters = __esm({
225333
225789
  }
225334
225790
  });
225335
225791
  var ExitCodes;
225336
- var init_exit_codes = __esm({
225792
+ var init_exit_codes = __esm2({
225337
225793
  "src/lib/utils/exit-codes.ts"() {
225338
225794
  ExitCodes = /* @__PURE__ */ ((ExitCodes2) => {
225339
225795
  ExitCodes2[ExitCodes2["SUCCESS"] = 0] = "SUCCESS";
@@ -225345,7 +225801,7 @@ var init_exit_codes = __esm({
225345
225801
  }
225346
225802
  });
225347
225803
  var GitOutputStreams;
225348
- var init_git_output_streams = __esm({
225804
+ var init_git_output_streams = __esm2({
225349
225805
  "src/lib/utils/git-output-streams.ts"() {
225350
225806
  GitOutputStreams = class _GitOutputStreams {
225351
225807
  constructor(stdOut, stdErr) {
@@ -225360,7 +225816,7 @@ var init_git_output_streams = __esm({
225360
225816
  });
225361
225817
  var LineParser;
225362
225818
  var RemoteLineParser;
225363
- var init_line_parser = __esm({
225819
+ var init_line_parser = __esm2({
225364
225820
  "src/lib/utils/line-parser.ts"() {
225365
225821
  LineParser = class {
225366
225822
  constructor(regExp, useMatches) {
@@ -225417,7 +225873,7 @@ function createInstanceConfig(...options) {
225417
225873
  return config;
225418
225874
  }
225419
225875
  var defaultOptions2;
225420
- var init_simple_git_options = __esm({
225876
+ var init_simple_git_options = __esm2({
225421
225877
  "src/lib/utils/simple-git-options.ts"() {
225422
225878
  defaultOptions2 = {
225423
225879
  binary: "git",
@@ -225474,7 +225930,7 @@ function trailingFunctionArgument(args, includeNoop = true) {
225474
225930
  const callback = asFunction(last(args));
225475
225931
  return includeNoop || isUserFunction(callback) ? callback : undefined;
225476
225932
  }
225477
- var init_task_options = __esm({
225933
+ var init_task_options = __esm2({
225478
225934
  "src/lib/utils/task-options.ts"() {
225479
225935
  init_argument_filters();
225480
225936
  init_util();
@@ -225498,7 +225954,7 @@ function parseStringResponse(result, parsers12, texts, trim2 = true) {
225498
225954
  });
225499
225955
  return result;
225500
225956
  }
225501
- var init_task_parser = __esm({
225957
+ var init_task_parser = __esm2({
225502
225958
  "src/lib/utils/task-parser.ts"() {
225503
225959
  init_util();
225504
225960
  }
@@ -225549,7 +226005,7 @@ __export2(utils_exports, {
225549
226005
  trailingFunctionArgument: () => trailingFunctionArgument,
225550
226006
  trailingOptionsArgument: () => trailingOptionsArgument
225551
226007
  });
225552
- var init_utils = __esm({
226008
+ var init_utils = __esm2({
225553
226009
  "src/lib/utils/index.ts"() {
225554
226010
  init_argument_filters();
225555
226011
  init_exit_codes();
@@ -225589,8 +226045,8 @@ function checkIsRepoRootTask() {
225589
226045
  commands,
225590
226046
  format: "utf-8",
225591
226047
  onError,
225592
- parser(path4) {
225593
- return /^\.(git)?$/.test(path4.trim());
226048
+ parser(path3) {
226049
+ return /^\.(git)?$/.test(path3.trim());
225594
226050
  }
225595
226051
  };
225596
226052
  }
@@ -225609,7 +226065,7 @@ function isNotRepoMessage(error) {
225609
226065
  var CheckRepoActions;
225610
226066
  var onError;
225611
226067
  var parser;
225612
- var init_check_is_repo = __esm({
226068
+ var init_check_is_repo = __esm2({
225613
226069
  "src/lib/tasks/check-is-repo.ts"() {
225614
226070
  init_utils();
225615
226071
  CheckRepoActions = /* @__PURE__ */ ((CheckRepoActions2) => {
@@ -225643,7 +226099,7 @@ var CleanResponse;
225643
226099
  var removalRegexp;
225644
226100
  var dryRunRemovalRegexp;
225645
226101
  var isFolderRegexp;
225646
- var init_CleanSummary = __esm({
226102
+ var init_CleanSummary = __esm2({
225647
226103
  "src/lib/responses/CleanSummary.ts"() {
225648
226104
  init_utils();
225649
226105
  CleanResponse = class {
@@ -225710,7 +226166,7 @@ function isEmptyTask(task) {
225710
226166
  return task.format === "empty" || !task.commands.length;
225711
226167
  }
225712
226168
  var EMPTY_COMMANDS;
225713
- var init_task = __esm({
226169
+ var init_task = __esm2({
225714
226170
  "src/lib/tasks/task.ts"() {
225715
226171
  init_task_configuration_error();
225716
226172
  EMPTY_COMMANDS = [];
@@ -225788,7 +226244,7 @@ var CONFIG_ERROR_MODE_REQUIRED;
225788
226244
  var CONFIG_ERROR_UNKNOWN_OPTION;
225789
226245
  var CleanOptions;
225790
226246
  var CleanOptionValues;
225791
- var init_clean = __esm({
226247
+ var init_clean = __esm2({
225792
226248
  "src/lib/tasks/clean.ts"() {
225793
226249
  init_CleanSummary();
225794
226250
  init_utils();
@@ -225861,7 +226317,7 @@ function* configParser(text, requestedKey = null) {
225861
226317
  }
225862
226318
  }
225863
226319
  var ConfigList;
225864
- var init_ConfigList = __esm({
226320
+ var init_ConfigList = __esm2({
225865
226321
  "src/lib/responses/ConfigList.ts"() {
225866
226322
  init_utils();
225867
226323
  ConfigList = class {
@@ -225959,7 +226415,7 @@ function config_default() {
225959
226415
  };
225960
226416
  }
225961
226417
  var GitConfigScope;
225962
- var init_config = __esm({
226418
+ var init_config = __esm2({
225963
226419
  "src/lib/tasks/config.ts"() {
225964
226420
  init_ConfigList();
225965
226421
  init_utils();
@@ -225977,7 +226433,7 @@ function isDiffNameStatus(input) {
225977
226433
  }
225978
226434
  var DiffNameStatus;
225979
226435
  var diffNameStatus;
225980
- var init_diff_name_status = __esm({
226436
+ var init_diff_name_status = __esm2({
225981
226437
  "src/lib/tasks/diff-name-status.ts"() {
225982
226438
  DiffNameStatus = /* @__PURE__ */ ((DiffNameStatus2) => {
225983
226439
  DiffNameStatus2["ADDED"] = "A";
@@ -226001,11 +226457,11 @@ function parseGrep(grep) {
226001
226457
  const paths = /* @__PURE__ */ new Set;
226002
226458
  const results = {};
226003
226459
  forEachLineWithContent(grep, (input) => {
226004
- const [path4, line, preview] = input.split(NULL);
226005
- paths.add(path4);
226006
- (results[path4] = results[path4] || []).push({
226460
+ const [path3, line, preview] = input.split(NULL);
226461
+ paths.add(path3);
226462
+ (results[path3] = results[path3] || []).push({
226007
226463
  line: asNumber(line),
226008
- path: path4,
226464
+ path: path3,
226009
226465
  preview
226010
226466
  });
226011
226467
  });
@@ -226042,7 +226498,7 @@ var disallowedOptions;
226042
226498
  var Query;
226043
226499
  var _a;
226044
226500
  var GrepQuery;
226045
- var init_grep = __esm({
226501
+ var init_grep = __esm2({
226046
226502
  "src/lib/tasks/grep.ts"() {
226047
226503
  init_utils();
226048
226504
  init_task();
@@ -226098,7 +226554,7 @@ function isValidResetMode(mode) {
226098
226554
  }
226099
226555
  var ResetMode;
226100
226556
  var ResetModes;
226101
- var init_reset = __esm({
226557
+ var init_reset = __esm2({
226102
226558
  "src/lib/tasks/reset.ts"() {
226103
226559
  init_task();
226104
226560
  ResetMode = /* @__PURE__ */ ((ResetMode2) => {
@@ -226160,7 +226616,7 @@ function createLogger(label, verbose, initialStep, infoDebugger = createLog()) {
226160
226616
  });
226161
226617
  }
226162
226618
  }
226163
- var init_git_logger = __esm({
226619
+ var init_git_logger = __esm2({
226164
226620
  "src/lib/git-logger.ts"() {
226165
226621
  init_utils();
226166
226622
  import_debug.default.formatters.L = (value) => String(filterHasLength(value) ? value.length : "-");
@@ -226173,7 +226629,7 @@ var init_git_logger = __esm({
226173
226629
  }
226174
226630
  });
226175
226631
  var TasksPendingQueue;
226176
- var init_tasks_pending_queue = __esm({
226632
+ var init_tasks_pending_queue = __esm2({
226177
226633
  "src/lib/runners/tasks-pending-queue.ts"() {
226178
226634
  init_git_error();
226179
226635
  init_git_logger();
@@ -226257,7 +226713,7 @@ function onDataReceived(target, name, logger2, output) {
226257
226713
  };
226258
226714
  }
226259
226715
  var GitExecutorChain;
226260
- var init_git_executor_chain = __esm({
226716
+ var init_git_executor_chain = __esm2({
226261
226717
  "src/lib/runners/git-executor-chain.ts"() {
226262
226718
  init_git_error();
226263
226719
  init_task();
@@ -226422,7 +226878,7 @@ __export2(git_executor_exports, {
226422
226878
  GitExecutor: () => GitExecutor
226423
226879
  });
226424
226880
  var GitExecutor;
226425
- var init_git_executor = __esm({
226881
+ var init_git_executor = __esm2({
226426
226882
  "src/lib/runners/git-executor.ts"() {
226427
226883
  init_git_executor_chain();
226428
226884
  GitExecutor = class {
@@ -226473,7 +226929,7 @@ function addDeprecationNoticeToError(err) {
226473
226929
  return all3;
226474
226930
  }
226475
226931
  }
226476
- var init_task_callback = __esm({
226932
+ var init_task_callback = __esm2({
226477
226933
  "src/lib/task-callback.ts"() {
226478
226934
  init_git_response_error();
226479
226935
  init_utils();
@@ -226487,7 +226943,7 @@ function changeWorkingDirectoryTask(directory, root) {
226487
226943
  return (root || instance).cwd = directory;
226488
226944
  });
226489
226945
  }
226490
- var init_change_working_directory = __esm({
226946
+ var init_change_working_directory = __esm2({
226491
226947
  "src/lib/tasks/change-working-directory.ts"() {
226492
226948
  init_utils();
226493
226949
  init_task();
@@ -226513,7 +226969,7 @@ function checkout_default() {
226513
226969
  }
226514
226970
  };
226515
226971
  }
226516
- var init_checkout = __esm({
226972
+ var init_checkout = __esm2({
226517
226973
  "src/lib/tasks/checkout.ts"() {
226518
226974
  init_utils();
226519
226975
  init_task();
@@ -226545,7 +227001,7 @@ function count_objects_default() {
226545
227001
  };
226546
227002
  }
226547
227003
  var parser2;
226548
- var init_count_objects = __esm({
227004
+ var init_count_objects = __esm2({
226549
227005
  "src/lib/tasks/count-objects.ts"() {
226550
227006
  init_utils();
226551
227007
  parser2 = new LineParser(/([a-z-]+): (\d+)$/, (result, [key, value]) => {
@@ -226571,7 +227027,7 @@ function parseCommitResult(stdOut) {
226571
227027
  return parseStringResponse(result, parsers, stdOut);
226572
227028
  }
226573
227029
  var parsers;
226574
- var init_parse_commit = __esm({
227030
+ var init_parse_commit = __esm2({
226575
227031
  "src/lib/parsers/parse-commit.ts"() {
226576
227032
  init_utils();
226577
227033
  parsers = [
@@ -226635,7 +227091,7 @@ function commit_default() {
226635
227091
  return !filterStringOrStringArray(message) && configurationErrorTask(`git.commit: requires the commit message to be supplied as a string/string[]`);
226636
227092
  }
226637
227093
  }
226638
- var init_commit = __esm({
227094
+ var init_commit = __esm2({
226639
227095
  "src/lib/tasks/commit.ts"() {
226640
227096
  init_parse_commit();
226641
227097
  init_utils();
@@ -226649,7 +227105,7 @@ function first_commit_default() {
226649
227105
  }
226650
227106
  };
226651
227107
  }
226652
- var init_first_commit = __esm({
227108
+ var init_first_commit = __esm2({
226653
227109
  "src/lib/tasks/first-commit.ts"() {
226654
227110
  init_utils();
226655
227111
  init_task();
@@ -226662,19 +227118,19 @@ function hashObjectTask(filePath, write) {
226662
227118
  }
226663
227119
  return straightThroughStringTask(commands, true);
226664
227120
  }
226665
- var init_hash_object = __esm({
227121
+ var init_hash_object = __esm2({
226666
227122
  "src/lib/tasks/hash-object.ts"() {
226667
227123
  init_task();
226668
227124
  }
226669
227125
  });
226670
- function parseInit(bare, path4, text) {
227126
+ function parseInit(bare, path3, text) {
226671
227127
  const response = String(text).trim();
226672
227128
  let result;
226673
227129
  if (result = initResponseRegex.exec(response)) {
226674
- return new InitSummary(bare, path4, false, result[1]);
227130
+ return new InitSummary(bare, path3, false, result[1]);
226675
227131
  }
226676
227132
  if (result = reInitResponseRegex.exec(response)) {
226677
- return new InitSummary(bare, path4, true, result[1]);
227133
+ return new InitSummary(bare, path3, true, result[1]);
226678
227134
  }
226679
227135
  let gitDir = "";
226680
227136
  const tokens = response.split(" ");
@@ -226685,17 +227141,17 @@ function parseInit(bare, path4, text) {
226685
227141
  break;
226686
227142
  }
226687
227143
  }
226688
- return new InitSummary(bare, path4, /^re/i.test(response), gitDir);
227144
+ return new InitSummary(bare, path3, /^re/i.test(response), gitDir);
226689
227145
  }
226690
227146
  var InitSummary;
226691
227147
  var initResponseRegex;
226692
227148
  var reInitResponseRegex;
226693
- var init_InitSummary = __esm({
227149
+ var init_InitSummary = __esm2({
226694
227150
  "src/lib/responses/InitSummary.ts"() {
226695
227151
  InitSummary = class {
226696
- constructor(bare, path4, existing, gitDir) {
227152
+ constructor(bare, path3, existing, gitDir) {
226697
227153
  this.bare = bare;
226698
- this.path = path4;
227154
+ this.path = path3;
226699
227155
  this.existing = existing;
226700
227156
  this.gitDir = gitDir;
226701
227157
  }
@@ -226707,7 +227163,7 @@ var init_InitSummary = __esm({
226707
227163
  function hasBareCommand(command) {
226708
227164
  return command.includes(bareCommand);
226709
227165
  }
226710
- function initTask(bare = false, path4, customArgs) {
227166
+ function initTask(bare = false, path3, customArgs) {
226711
227167
  const commands = ["init", ...customArgs];
226712
227168
  if (bare && !hasBareCommand(commands)) {
226713
227169
  commands.splice(1, 0, bareCommand);
@@ -226716,12 +227172,12 @@ function initTask(bare = false, path4, customArgs) {
226716
227172
  commands,
226717
227173
  format: "utf-8",
226718
227174
  parser(text) {
226719
- return parseInit(commands.includes("--bare"), path4, text);
227175
+ return parseInit(commands.includes("--bare"), path3, text);
226720
227176
  }
226721
227177
  };
226722
227178
  }
226723
227179
  var bareCommand;
226724
- var init_init = __esm({
227180
+ var init_init = __esm2({
226725
227181
  "src/lib/tasks/init.ts"() {
226726
227182
  init_InitSummary();
226727
227183
  bareCommand = "--bare";
@@ -226740,13 +227196,13 @@ function isLogFormat(customArg) {
226740
227196
  return logFormatRegex.test(customArg);
226741
227197
  }
226742
227198
  var logFormatRegex;
226743
- var init_log_format = __esm({
227199
+ var init_log_format = __esm2({
226744
227200
  "src/lib/args/log-format.ts"() {
226745
227201
  logFormatRegex = /^--(stat|numstat|name-only|name-status)(=|$)/;
226746
227202
  }
226747
227203
  });
226748
227204
  var DiffSummary;
226749
- var init_DiffSummary = __esm({
227205
+ var init_DiffSummary = __esm2({
226750
227206
  "src/lib/responses/DiffSummary.ts"() {
226751
227207
  DiffSummary = class {
226752
227208
  constructor() {
@@ -226767,7 +227223,7 @@ var numStatParser;
226767
227223
  var nameOnlyParser;
226768
227224
  var nameStatusParser;
226769
227225
  var diffSummaryParsers;
226770
- var init_parse_diff_summary = __esm({
227226
+ var init_parse_diff_summary = __esm2({
226771
227227
  "src/lib/parsers/parse-diff-summary.ts"() {
226772
227228
  init_log_format();
226773
227229
  init_DiffSummary();
@@ -226888,7 +227344,7 @@ var START_BOUNDARY;
226888
227344
  var COMMIT_BOUNDARY;
226889
227345
  var SPLITTER;
226890
227346
  var defaultFieldNames;
226891
- var init_parse_list_log_summary = __esm({
227347
+ var init_parse_list_log_summary = __esm2({
226892
227348
  "src/lib/parsers/parse-list-log-summary.ts"() {
226893
227349
  init_utils();
226894
227350
  init_parse_diff_summary();
@@ -226927,7 +227383,7 @@ function validateLogFormatConfig(customArgs) {
226927
227383
  return configurationErrorTask(`Summary flag ${flags} parsing is not compatible with null termination option '-z'`);
226928
227384
  }
226929
227385
  }
226930
- var init_diff = __esm({
227386
+ var init_diff = __esm2({
226931
227387
  "src/lib/tasks/diff.ts"() {
226932
227388
  init_log_format();
226933
227389
  init_parse_diff_summary();
@@ -227011,7 +227467,7 @@ function log_default() {
227011
227467
  }
227012
227468
  }
227013
227469
  var excludeOptions;
227014
- var init_log = __esm({
227470
+ var init_log = __esm2({
227015
227471
  "src/lib/tasks/log.ts"() {
227016
227472
  init_log_format();
227017
227473
  init_pathspec();
@@ -227039,7 +227495,7 @@ var init_log = __esm({
227039
227495
  });
227040
227496
  var MergeSummaryConflict;
227041
227497
  var MergeSummaryDetail;
227042
- var init_MergeSummary = __esm({
227498
+ var init_MergeSummary = __esm2({
227043
227499
  "src/lib/responses/MergeSummary.ts"() {
227044
227500
  MergeSummaryConflict = class {
227045
227501
  constructor(reason, file = null, meta) {
@@ -227074,7 +227530,7 @@ var init_MergeSummary = __esm({
227074
227530
  });
227075
227531
  var PullSummary;
227076
227532
  var PullFailedSummary;
227077
- var init_PullSummary = __esm({
227533
+ var init_PullSummary = __esm2({
227078
227534
  "src/lib/responses/PullSummary.ts"() {
227079
227535
  PullSummary = class {
227080
227536
  constructor() {
@@ -227131,7 +227587,7 @@ function asObjectCount(source) {
227131
227587
  };
227132
227588
  }
227133
227589
  var remoteMessagesObjectParsers;
227134
- var init_parse_remote_objects = __esm({
227590
+ var init_parse_remote_objects = __esm2({
227135
227591
  "src/lib/parsers/parse-remote-objects.ts"() {
227136
227592
  init_utils();
227137
227593
  remoteMessagesObjectParsers = [
@@ -227159,7 +227615,7 @@ function parseRemoteMessages(_stdOut, stdErr) {
227159
227615
  }
227160
227616
  var parsers2;
227161
227617
  var RemoteMessageSummary;
227162
- var init_parse_remote_messages = __esm({
227618
+ var init_parse_remote_messages = __esm2({
227163
227619
  "src/lib/parsers/parse-remote-messages.ts"() {
227164
227620
  init_utils();
227165
227621
  init_parse_remote_objects();
@@ -227198,7 +227654,7 @@ var parsers3;
227198
227654
  var errorParsers;
227199
227655
  var parsePullDetail;
227200
227656
  var parsePullResult;
227201
- var init_parse_pull = __esm({
227657
+ var init_parse_pull = __esm2({
227202
227658
  "src/lib/parsers/parse-pull.ts"() {
227203
227659
  init_PullSummary();
227204
227660
  init_utils();
@@ -227251,7 +227707,7 @@ var init_parse_pull = __esm({
227251
227707
  var parsers4;
227252
227708
  var parseMergeResult;
227253
227709
  var parseMergeDetail;
227254
- var init_parse_merge = __esm({
227710
+ var init_parse_merge = __esm2({
227255
227711
  "src/lib/parsers/parse-merge.ts"() {
227256
227712
  init_MergeSummary();
227257
227713
  init_utils();
@@ -227297,7 +227753,7 @@ function mergeTask(customArgs) {
227297
227753
  }
227298
227754
  };
227299
227755
  }
227300
- var init_merge = __esm({
227756
+ var init_merge = __esm2({
227301
227757
  "src/lib/tasks/merge.ts"() {
227302
227758
  init_git_response_error();
227303
227759
  init_parse_merge();
@@ -227321,7 +227777,7 @@ function pushResultPushedItem(local, remote, status) {
227321
227777
  var parsers5;
227322
227778
  var parsePushResult;
227323
227779
  var parsePushDetail;
227324
- var init_parse_push = __esm({
227780
+ var init_parse_push = __esm2({
227325
227781
  "src/lib/parsers/parse-push.ts"() {
227326
227782
  init_utils();
227327
227783
  init_parse_remote_messages();
@@ -227398,7 +227854,7 @@ function pushTask(ref = {}, customArgs) {
227398
227854
  parser: parsePushResult
227399
227855
  };
227400
227856
  }
227401
- var init_push = __esm({
227857
+ var init_push = __esm2({
227402
227858
  "src/lib/tasks/push.ts"() {
227403
227859
  init_parse_push();
227404
227860
  init_utils();
@@ -227419,7 +227875,7 @@ function show_default() {
227419
227875
  }
227420
227876
  };
227421
227877
  }
227422
- var init_show = __esm({
227878
+ var init_show = __esm2({
227423
227879
  "src/lib/tasks/show.ts"() {
227424
227880
  init_utils();
227425
227881
  init_task();
@@ -227427,16 +227883,16 @@ var init_show = __esm({
227427
227883
  });
227428
227884
  var fromPathRegex;
227429
227885
  var FileStatusSummary;
227430
- var init_FileStatusSummary = __esm({
227886
+ var init_FileStatusSummary = __esm2({
227431
227887
  "src/lib/responses/FileStatusSummary.ts"() {
227432
227888
  fromPathRegex = /^(.+)\0(.+)$/;
227433
227889
  FileStatusSummary = class {
227434
- constructor(path4, index, working_dir) {
227435
- this.path = path4;
227890
+ constructor(path3, index, working_dir) {
227891
+ this.path = path3;
227436
227892
  this.index = index;
227437
227893
  this.working_dir = working_dir;
227438
227894
  if (index === "R" || working_dir === "R") {
227439
- const detail = fromPathRegex.exec(path4) || [null, path4, path4];
227895
+ const detail = fromPathRegex.exec(path3) || [null, path3, path3];
227440
227896
  this.from = detail[2] || "";
227441
227897
  this.path = detail[1] || "";
227442
227898
  }
@@ -227467,21 +227923,21 @@ function splitLine(result, lineStr) {
227467
227923
  default:
227468
227924
  return;
227469
227925
  }
227470
- function data(index, workingDir, path4) {
227926
+ function data(index, workingDir, path3) {
227471
227927
  const raw = `${index}${workingDir}`;
227472
227928
  const handler = parsers6.get(raw);
227473
227929
  if (handler) {
227474
- handler(result, path4);
227930
+ handler(result, path3);
227475
227931
  }
227476
227932
  if (raw !== "##" && raw !== "!!") {
227477
- result.files.push(new FileStatusSummary(path4, index, workingDir));
227933
+ result.files.push(new FileStatusSummary(path3, index, workingDir));
227478
227934
  }
227479
227935
  }
227480
227936
  }
227481
227937
  var StatusSummary;
227482
227938
  var parsers6;
227483
227939
  var parseStatusSummary;
227484
- var init_StatusSummary = __esm({
227940
+ var init_StatusSummary = __esm2({
227485
227941
  "src/lib/responses/StatusSummary.ts"() {
227486
227942
  init_utils();
227487
227943
  init_FileStatusSummary();
@@ -227588,7 +228044,7 @@ function statusTask(customArgs) {
227588
228044
  };
227589
228045
  }
227590
228046
  var ignoredOptions;
227591
- var init_status = __esm({
228047
+ var init_status = __esm2({
227592
228048
  "src/lib/tasks/status.ts"() {
227593
228049
  init_StatusSummary();
227594
228050
  ignoredOptions = ["--null", "-z"];
@@ -227637,7 +228093,7 @@ function versionParser(stdOut) {
227637
228093
  }
227638
228094
  var NOT_INSTALLED;
227639
228095
  var parsers7;
227640
- var init_version = __esm({
228096
+ var init_version = __esm2({
227641
228097
  "src/lib/tasks/version.ts"() {
227642
228098
  init_utils();
227643
228099
  NOT_INSTALLED = "installed=false";
@@ -227656,7 +228112,7 @@ __export2(simple_git_api_exports, {
227656
228112
  SimpleGitApi: () => SimpleGitApi
227657
228113
  });
227658
228114
  var SimpleGitApi;
227659
- var init_simple_git_api = __esm({
228115
+ var init_simple_git_api = __esm2({
227660
228116
  "src/lib/simple-git-api.ts"() {
227661
228117
  init_task_callback();
227662
228118
  init_change_working_directory();
@@ -227705,8 +228161,8 @@ var init_simple_git_api = __esm({
227705
228161
  }
227706
228162
  return this._runTask(configurationErrorTask("Git.cwd: workingDirectory must be supplied as a string"), next);
227707
228163
  }
227708
- hashObject(path4, write) {
227709
- return this._runTask(hashObjectTask(path4, write === true), trailingFunctionArgument(arguments));
228164
+ hashObject(path3, write) {
228165
+ return this._runTask(hashObjectTask(path3, write === true), trailingFunctionArgument(arguments));
227710
228166
  }
227711
228167
  init(bare) {
227712
228168
  return this._runTask(initTask(bare === true, this._executor.cwd, getTrailingOptions(arguments)), trailingFunctionArgument(arguments));
@@ -227747,7 +228203,7 @@ __export2(scheduler_exports, {
227747
228203
  });
227748
228204
  var createScheduledTask;
227749
228205
  var Scheduler;
227750
- var init_scheduler = __esm({
228206
+ var init_scheduler = __esm2({
227751
228207
  "src/lib/runners/scheduler.ts"() {
227752
228208
  init_utils();
227753
228209
  init_git_logger();
@@ -227800,7 +228256,7 @@ __export2(apply_patch_exports, {
227800
228256
  function applyPatchTask(patches, customArgs) {
227801
228257
  return straightThroughStringTask(["apply", ...customArgs, ...patches]);
227802
228258
  }
227803
- var init_apply_patch = __esm({
228259
+ var init_apply_patch = __esm2({
227804
228260
  "src/lib/tasks/apply-patch.ts"() {
227805
228261
  init_task();
227806
228262
  }
@@ -227820,7 +228276,7 @@ function branchDeletionFailure(branch) {
227820
228276
  };
227821
228277
  }
227822
228278
  var BranchDeletionBatch;
227823
- var init_BranchDeleteSummary = __esm({
228279
+ var init_BranchDeleteSummary = __esm2({
227824
228280
  "src/lib/responses/BranchDeleteSummary.ts"() {
227825
228281
  BranchDeletionBatch = class {
227826
228282
  constructor() {
@@ -227841,7 +228297,7 @@ var deleteSuccessRegex;
227841
228297
  var deleteErrorRegex;
227842
228298
  var parsers8;
227843
228299
  var parseBranchDeletions;
227844
- var init_parse_branch_delete = __esm({
228300
+ var init_parse_branch_delete = __esm2({
227845
228301
  "src/lib/parsers/parse-branch-delete.ts"() {
227846
228302
  init_BranchDeleteSummary();
227847
228303
  init_utils();
@@ -227866,7 +228322,7 @@ var init_parse_branch_delete = __esm({
227866
228322
  }
227867
228323
  });
227868
228324
  var BranchSummaryResult;
227869
- var init_BranchSummary = __esm({
228325
+ var init_BranchSummary = __esm2({
227870
228326
  "src/lib/responses/BranchSummary.ts"() {
227871
228327
  BranchSummaryResult = class {
227872
228328
  constructor() {
@@ -227899,7 +228355,7 @@ function parseBranchSummary(stdOut) {
227899
228355
  return parseStringResponse(new BranchSummaryResult, parsers9, stdOut);
227900
228356
  }
227901
228357
  var parsers9;
227902
- var init_parse_branch = __esm({
228358
+ var init_parse_branch = __esm2({
227903
228359
  "src/lib/parsers/parse-branch.ts"() {
227904
228360
  init_BranchSummary();
227905
228361
  init_utils();
@@ -227984,7 +228440,7 @@ function deleteBranchTask(branch, forceDelete = false) {
227984
228440
  };
227985
228441
  return task;
227986
228442
  }
227987
- var init_branch = __esm({
228443
+ var init_branch = __esm2({
227988
228444
  "src/lib/tasks/branch.ts"() {
227989
228445
  init_git_response_error();
227990
228446
  init_parse_branch_delete();
@@ -227993,7 +228449,7 @@ var init_branch = __esm({
227993
228449
  }
227994
228450
  });
227995
228451
  var parseCheckIgnore;
227996
- var init_CheckIgnore = __esm({
228452
+ var init_CheckIgnore = __esm2({
227997
228453
  "src/lib/responses/CheckIgnore.ts"() {
227998
228454
  parseCheckIgnore = (text) => {
227999
228455
  return text.split(/\n/g).map((line) => line.trim()).filter((file) => !!file);
@@ -228011,7 +228467,7 @@ function checkIgnoreTask(paths) {
228011
228467
  parser: parseCheckIgnore
228012
228468
  };
228013
228469
  }
228014
- var init_check_ignore = __esm({
228470
+ var init_check_ignore = __esm2({
228015
228471
  "src/lib/tasks/check-ignore.ts"() {
228016
228472
  init_CheckIgnore();
228017
228473
  }
@@ -228038,7 +228494,7 @@ function cloneMirrorTask(repo, directory, customArgs) {
228038
228494
  append2(customArgs, "--mirror");
228039
228495
  return cloneTask(repo, directory, customArgs);
228040
228496
  }
228041
- var init_clone = __esm({
228497
+ var init_clone = __esm2({
228042
228498
  "src/lib/tasks/clone.ts"() {
228043
228499
  init_task();
228044
228500
  init_utils();
@@ -228056,7 +228512,7 @@ function parseFetchResult(stdOut, stdErr) {
228056
228512
  return parseStringResponse(result, parsers10, [stdOut, stdErr]);
228057
228513
  }
228058
228514
  var parsers10;
228059
- var init_parse_fetch = __esm({
228515
+ var init_parse_fetch = __esm2({
228060
228516
  "src/lib/parsers/parse-fetch.ts"() {
228061
228517
  init_utils();
228062
228518
  parsers10 = [
@@ -228113,7 +228569,7 @@ function fetchTask(remote, branch, customArgs) {
228113
228569
  parser: parseFetchResult
228114
228570
  };
228115
228571
  }
228116
- var init_fetch = __esm({
228572
+ var init_fetch = __esm2({
228117
228573
  "src/lib/tasks/fetch.ts"() {
228118
228574
  init_parse_fetch();
228119
228575
  init_task();
@@ -228123,7 +228579,7 @@ function parseMoveResult(stdOut) {
228123
228579
  return parseStringResponse({ moves: [] }, parsers11, stdOut);
228124
228580
  }
228125
228581
  var parsers11;
228126
- var init_parse_move = __esm({
228582
+ var init_parse_move = __esm2({
228127
228583
  "src/lib/parsers/parse-move.ts"() {
228128
228584
  init_utils();
228129
228585
  parsers11 = [
@@ -228144,7 +228600,7 @@ function moveTask(from, to) {
228144
228600
  parser: parseMoveResult
228145
228601
  };
228146
228602
  }
228147
- var init_move = __esm({
228603
+ var init_move = __esm2({
228148
228604
  "src/lib/tasks/move.ts"() {
228149
228605
  init_parse_move();
228150
228606
  init_utils();
@@ -228174,7 +228630,7 @@ function pullTask(remote, branch, customArgs) {
228174
228630
  }
228175
228631
  };
228176
228632
  }
228177
- var init_pull = __esm({
228633
+ var init_pull = __esm2({
228178
228634
  "src/lib/tasks/pull.ts"() {
228179
228635
  init_git_response_error();
228180
228636
  init_parse_pull();
@@ -228204,7 +228660,7 @@ function parseGetRemotesVerbose(text) {
228204
228660
  function forEach2(text, handler) {
228205
228661
  forEachLineWithContent(text, (line) => handler(line.split(/\s+/)));
228206
228662
  }
228207
- var init_GetRemoteSummary = __esm({
228663
+ var init_GetRemoteSummary = __esm2({
228208
228664
  "src/lib/responses/GetRemoteSummary.ts"() {
228209
228665
  init_utils();
228210
228666
  }
@@ -228248,7 +228704,7 @@ function remoteTask(customArgs) {
228248
228704
  function removeRemoteTask(remoteName) {
228249
228705
  return straightThroughStringTask(["remote", "remove", remoteName]);
228250
228706
  }
228251
- var init_remote = __esm({
228707
+ var init_remote = __esm2({
228252
228708
  "src/lib/tasks/remote.ts"() {
228253
228709
  init_GetRemoteSummary();
228254
228710
  init_task();
@@ -228268,7 +228724,7 @@ function stashListTask(opt = {}, customArgs) {
228268
228724
  parser: parser4
228269
228725
  };
228270
228726
  }
228271
- var init_stash_list = __esm({
228727
+ var init_stash_list = __esm2({
228272
228728
  "src/lib/tasks/stash-list.ts"() {
228273
228729
  init_log_format();
228274
228730
  init_parse_list_log_summary();
@@ -228283,8 +228739,8 @@ __export2(sub_module_exports, {
228283
228739
  subModuleTask: () => subModuleTask,
228284
228740
  updateSubModuleTask: () => updateSubModuleTask
228285
228741
  });
228286
- function addSubModuleTask(repo, path4) {
228287
- return subModuleTask(["add", repo, path4]);
228742
+ function addSubModuleTask(repo, path3) {
228743
+ return subModuleTask(["add", repo, path3]);
228288
228744
  }
228289
228745
  function initSubModuleTask(customArgs) {
228290
228746
  return subModuleTask(["init", ...customArgs]);
@@ -228299,7 +228755,7 @@ function subModuleTask(customArgs) {
228299
228755
  function updateSubModuleTask(customArgs) {
228300
228756
  return subModuleTask(["update", ...customArgs]);
228301
228757
  }
228302
- var init_sub_module = __esm({
228758
+ var init_sub_module = __esm2({
228303
228759
  "src/lib/tasks/sub-module.ts"() {
228304
228760
  init_task();
228305
228761
  }
@@ -228326,7 +228782,7 @@ function toNumber(input) {
228326
228782
  }
228327
228783
  var TagList;
228328
228784
  var parseTagList;
228329
- var init_TagList = __esm({
228785
+ var init_TagList = __esm2({
228330
228786
  "src/lib/responses/TagList.ts"() {
228331
228787
  TagList = class {
228332
228788
  constructor(all3, latest) {
@@ -228392,7 +228848,7 @@ function addAnnotatedTagTask(name, tagMessage) {
228392
228848
  }
228393
228849
  };
228394
228850
  }
228395
- var init_tag = __esm({
228851
+ var init_tag = __esm2({
228396
228852
  "src/lib/tasks/tag.ts"() {
228397
228853
  init_TagList();
228398
228854
  }
@@ -228552,8 +229008,8 @@ var require_git = __commonJS2({
228552
229008
  }
228553
229009
  return this._runTask(straightThroughStringTask2(command, this._trimmed), next);
228554
229010
  };
228555
- Git2.prototype.submoduleAdd = function(repo, path4, then) {
228556
- return this._runTask(addSubModuleTask2(repo, path4), trailingFunctionArgument2(arguments));
229011
+ Git2.prototype.submoduleAdd = function(repo, path3, then) {
229012
+ return this._runTask(addSubModuleTask2(repo, path3), trailingFunctionArgument2(arguments));
228557
229013
  };
228558
229014
  Git2.prototype.submoduleUpdate = function(args, then) {
228559
229015
  return this._runTask(updateSubModuleTask2(getTrailingOptions2(arguments, true)), trailingFunctionArgument2(arguments));
@@ -229068,10 +229524,12 @@ var esm_default2 = gitInstanceFactory;
229068
229524
  import { Writable } from "stream";
229069
229525
 
229070
229526
  // src/config.ts
229527
+ init_constants();
229528
+ init_logger();
229071
229529
  import fs2 from "fs";
229072
- import path4 from "path";
229530
+ import path3 from "path";
229073
229531
  import { fileURLToPath } from "url";
229074
- var BUNDLED_DEFAULT_CONFIG_PATH = path4.join(path4.dirname(fileURLToPath(import.meta.url)), "default-publisher.config.json");
229532
+ var BUNDLED_DEFAULT_CONFIG_PATH = path3.join(path3.dirname(fileURLToPath(import.meta.url)), "default-publisher.config.json");
229075
229533
  function resolvePublisherConfigPath(serverRoot) {
229076
229534
  const explicitPath = process.env.PUBLISHER_CONFIG_PATH;
229077
229535
  if (explicitPath && explicitPath.length > 0) {
@@ -229080,7 +229538,7 @@ function resolvePublisherConfigPath(serverRoot) {
229080
229538
  }
229081
229539
  return { path: explicitPath, isBundledDefault: false };
229082
229540
  }
229083
- const serverRootPath = path4.join(serverRoot, PUBLISHER_CONFIG_NAME);
229541
+ const serverRootPath = path3.join(serverRoot, PUBLISHER_CONFIG_NAME);
229084
229542
  if (fs2.existsSync(serverRootPath)) {
229085
229543
  return { path: serverRootPath, isBundledDefault: false };
229086
229544
  }
@@ -229089,6 +229547,73 @@ function resolvePublisherConfigPath(serverRoot) {
229089
229547
  }
229090
229548
  return null;
229091
229549
  }
229550
+ var DEFAULT_HIGH_WATER_FRACTION = 0.8;
229551
+ var DEFAULT_LOW_WATER_FRACTION = 0.7;
229552
+ var DEFAULT_CHECK_INTERVAL_MS = 5000;
229553
+ var MIN_CHECK_INTERVAL_MS = 100;
229554
+ function parseIntEnv(name) {
229555
+ const raw = process.env[name];
229556
+ if (raw === undefined || raw.trim() === "")
229557
+ return;
229558
+ const value = Number.parseInt(raw, 10);
229559
+ if (!Number.isFinite(value) || String(value) !== raw.trim()) {
229560
+ throw new Error(`Invalid value for ${name}: expected a base-10 integer, got "${raw}"`);
229561
+ }
229562
+ return value;
229563
+ }
229564
+ function parseFloatEnv(name) {
229565
+ const raw = process.env[name];
229566
+ if (raw === undefined || raw.trim() === "")
229567
+ return;
229568
+ const value = Number.parseFloat(raw);
229569
+ if (!Number.isFinite(value)) {
229570
+ throw new Error(`Invalid value for ${name}: expected a finite number, got "${raw}"`);
229571
+ }
229572
+ return value;
229573
+ }
229574
+ function parseBoolEnv(name) {
229575
+ const raw = process.env[name];
229576
+ if (raw === undefined || raw.trim() === "")
229577
+ return;
229578
+ const normalised = raw.trim().toLowerCase();
229579
+ if (["1", "true", "yes", "on"].includes(normalised))
229580
+ return true;
229581
+ if (["0", "false", "no", "off"].includes(normalised))
229582
+ return false;
229583
+ throw new Error(`Invalid value for ${name}: expected a boolean (true/false), got "${raw}"`);
229584
+ }
229585
+ var getMemoryGovernorConfig = () => {
229586
+ const maxMemoryBytes = parseIntEnv("PUBLISHER_MAX_MEMORY_BYTES");
229587
+ if (maxMemoryBytes === undefined || maxMemoryBytes === 0) {
229588
+ return null;
229589
+ }
229590
+ if (maxMemoryBytes < 0) {
229591
+ throw new Error(`PUBLISHER_MAX_MEMORY_BYTES must be a positive integer (got ${maxMemoryBytes})`);
229592
+ }
229593
+ const highWaterFraction = parseFloatEnv("PUBLISHER_MEMORY_HIGH_WATER_FRACTION") ?? DEFAULT_HIGH_WATER_FRACTION;
229594
+ const lowWaterFraction = parseFloatEnv("PUBLISHER_MEMORY_LOW_WATER_FRACTION") ?? DEFAULT_LOW_WATER_FRACTION;
229595
+ const checkIntervalMs = parseIntEnv("PUBLISHER_MEMORY_CHECK_INTERVAL_MS") ?? DEFAULT_CHECK_INTERVAL_MS;
229596
+ const backpressureEnabled = parseBoolEnv("PUBLISHER_MEMORY_BACKPRESSURE") ?? true;
229597
+ if (highWaterFraction <= 0 || highWaterFraction >= 1) {
229598
+ throw new Error(`PUBLISHER_MEMORY_HIGH_WATER_FRACTION must be in (0, 1) (got ${highWaterFraction})`);
229599
+ }
229600
+ if (lowWaterFraction <= 0 || lowWaterFraction >= 1) {
229601
+ throw new Error(`PUBLISHER_MEMORY_LOW_WATER_FRACTION must be in (0, 1) (got ${lowWaterFraction})`);
229602
+ }
229603
+ if (lowWaterFraction >= highWaterFraction) {
229604
+ throw new Error(`PUBLISHER_MEMORY_LOW_WATER_FRACTION (${lowWaterFraction}) must be strictly less than PUBLISHER_MEMORY_HIGH_WATER_FRACTION (${highWaterFraction})`);
229605
+ }
229606
+ if (checkIntervalMs < MIN_CHECK_INTERVAL_MS) {
229607
+ throw new Error(`PUBLISHER_MEMORY_CHECK_INTERVAL_MS must be >= ${MIN_CHECK_INTERVAL_MS} (got ${checkIntervalMs})`);
229608
+ }
229609
+ return {
229610
+ maxMemoryBytes,
229611
+ highWaterFraction,
229612
+ lowWaterFraction,
229613
+ checkIntervalMs,
229614
+ backpressureEnabled
229615
+ };
229616
+ };
229092
229617
  function substituteEnvVars(value) {
229093
229618
  const envVarPattern = /\$\{([A-Z_][A-Z0-9_]*)\}/g;
229094
229619
  return value.replace(envVarPattern, (_match, varName) => {
@@ -229128,7 +229653,7 @@ var getPublisherConfig = (serverRoot) => {
229128
229653
  }
229129
229654
  const publisherConfigPath = resolved.path;
229130
229655
  if (resolved.isBundledDefault) {
229131
- logger.info(`No publisher.config.json found at ${path4.join(serverRoot, PUBLISHER_CONFIG_NAME)}; falling back to bundled DuckDB-only default. Pass --config <path> or place a config in the server root to override.`);
229656
+ logger.info(`No publisher.config.json found at ${path3.join(serverRoot, PUBLISHER_CONFIG_NAME)}; falling back to bundled DuckDB-only default. Pass --config <path> or place a config in the server root to override.`);
229132
229657
  }
229133
229658
  let rawConfig;
229134
229659
  try {
@@ -229258,7 +229783,12 @@ var getProcessedPublisherConfig = (serverRoot) => {
229258
229783
  };
229259
229784
  };
229260
229785
 
229786
+ // src/service/environment_store.ts
229787
+ init_constants();
229788
+ init_errors();
229789
+
229261
229790
  // src/health.ts
229791
+ init_logger();
229262
229792
  var operationalState = "initializing";
229263
229793
  var ready = false;
229264
229794
  var preGracefulShutdownCompleted = false;
@@ -229274,15 +229804,6 @@ function markReady() {
229274
229804
  logger.error("Service is already draining - cannot mark as ready");
229275
229805
  }
229276
229806
  }
229277
- function markDegraded() {
229278
- if (operationalState !== "draining") {
229279
- operationalState = "degraded";
229280
- ready = false;
229281
- logger.warn("Service marked as degraded; one or more environments failed to initialize. Readiness probe will fail until the config is fixed and the process restarts.");
229282
- } else {
229283
- logger.error("Service is already draining - cannot mark as degraded");
229284
- }
229285
- }
229286
229807
  function markNotReady() {
229287
229808
  ready = false;
229288
229809
  logger.info("Service marked as not ready - readiness probe will fail");
@@ -229297,37 +229818,45 @@ function registerSignalHandlers(server, mcpServer, shutdownDrainDurationSeconds
229297
229818
  preGracefulShutdownCompleted = true;
229298
229819
  resolve3(true);
229299
229820
  }, shutdownDrainDurationSeconds * 1000));
229300
- const closeServer = (server2, name) => new Promise((resolve3) => {
229301
- if (server2 && server2.listening) {
229302
- server2.close((err) => {
229303
- if (err) {
229304
- logger.error(`${name} close error:`, err);
229305
- } else {
229306
- logger.info(`${name} closed`);
229307
- }
229308
- resolve3();
229309
- });
229310
- } else {
229821
+ await performGracefulShutdownAfterDrain(server, mcpServer, shutdownGracefulCloseTimeoutSeconds);
229822
+ });
229823
+ }
229824
+ async function performGracefulShutdownAfterDrain(server, mcpServer, shutdownGracefulCloseTimeoutSeconds) {
229825
+ const closeServer = (server2, name) => new Promise((resolve3) => {
229826
+ if (server2 && server2.listening) {
229827
+ server2.close((err) => {
229828
+ if (err) {
229829
+ logger.error(`${name} close error:`, err);
229830
+ } else {
229831
+ logger.info(`${name} closed`);
229832
+ }
229311
229833
  resolve3();
229312
- }
229313
- });
229314
- await Promise.all([
229315
- closeServer(server, "Main server"),
229316
- closeServer(mcpServer, "MCP server")
229317
- ]);
229318
- try {
229319
- await shutdownSDK();
229320
- logger.info("OpenTelemetry SDK shut down");
229321
- } catch (_error) {}
229322
- try {
229323
- logger.close();
229324
- } catch (_error) {}
229325
- if (shutdownGracefulCloseTimeoutSeconds > 0) {
229326
- logger.info(`Waiting ${shutdownGracefulCloseTimeoutSeconds} seconds after server close before exit...`);
229327
- await new Promise((resolve3) => setTimeout(resolve3, shutdownGracefulCloseTimeoutSeconds * 1000));
229834
+ });
229835
+ } else {
229836
+ resolve3();
229328
229837
  }
229329
- process.exit(0);
229330
229838
  });
229839
+ await Promise.all([
229840
+ closeServer(server, "Main server"),
229841
+ closeServer(mcpServer, "MCP server")
229842
+ ]);
229843
+ try {
229844
+ await shutdownSDK();
229845
+ logger.info("OpenTelemetry SDK shut down");
229846
+ } catch (_error) {}
229847
+ try {
229848
+ const { getCompilePool: getCompilePool2 } = await Promise.resolve().then(() => (init_compile_pool(), exports_compile_pool));
229849
+ await getCompilePool2().shutdown();
229850
+ logger.info("Malloy compile worker pool shut down");
229851
+ } catch (_error) {}
229852
+ if (shutdownGracefulCloseTimeoutSeconds > 0) {
229853
+ logger.info(`Waiting ${shutdownGracefulCloseTimeoutSeconds} seconds after server close before exit...`);
229854
+ await new Promise((resolve3) => setTimeout(resolve3, shutdownGracefulCloseTimeoutSeconds * 1000));
229855
+ }
229856
+ try {
229857
+ logger.close();
229858
+ } catch (_error) {}
229859
+ process.exit(0);
229331
229860
  }
229332
229861
  function drainingGuard(req, res, next) {
229333
229862
  if (operationalState === "draining" && preGracefulShutdownCompleted && !req.path.startsWith("/health") && !req.path.startsWith("/metrics")) {
@@ -229361,12 +229890,17 @@ function registerHealthEndpoints(app) {
229361
229890
  });
229362
229891
  }
229363
229892
 
229893
+ // src/service/environment_store.ts
229894
+ init_logger();
229895
+
229364
229896
  // src/storage/StorageManager.ts
229897
+ init_errors();
229898
+ init_logger();
229365
229899
  import * as crypto3 from "crypto";
229366
229900
 
229367
229901
  // src/storage/duckdb/DuckDBConnection.ts
229368
229902
  import duckdb from "duckdb";
229369
- import * as path5 from "path";
229903
+ import * as path4 from "path";
229370
229904
 
229371
229905
  class DuckDBConnection2 {
229372
229906
  db = null;
@@ -229374,7 +229908,7 @@ class DuckDBConnection2 {
229374
229908
  dbPath;
229375
229909
  mutex = new Mutex;
229376
229910
  constructor(dbPath) {
229377
- this.dbPath = dbPath || path5.join(process.cwd(), "publisher.db");
229911
+ this.dbPath = dbPath || path4.join(process.cwd(), "publisher.db");
229378
229912
  }
229379
229913
  async initialize() {
229380
229914
  return new Promise((resolve3, reject) => {
@@ -230168,6 +230702,7 @@ class DuckDBRepository {
230168
230702
  }
230169
230703
 
230170
230704
  // src/storage/duckdb/schema.ts
230705
+ init_logger();
230171
230706
  async function initializeSchema(db, force = false) {
230172
230707
  const initialized = await db.isInitialized();
230173
230708
  if (initialized && !force) {
@@ -230296,6 +230831,8 @@ async function dropAllTables(db) {
230296
230831
  }
230297
230832
 
230298
230833
  // src/storage/ducklake/DuckLakeManifestStore.ts
230834
+ init_logger();
230835
+
230299
230836
  class DuckLakeManifestStore {
230300
230837
  db;
230301
230838
  table;
@@ -230523,18 +231060,75 @@ class StorageManager {
230523
231060
 
230524
231061
  // src/service/environment.ts
230525
231062
  import { MalloyError as MalloyError3, Runtime as Runtime2 } from "@malloydata/malloy";
231063
+ init_constants();
231064
+ init_errors();
231065
+ init_logger();
231066
+ import crypto4 from "crypto";
230526
231067
  import * as fs6 from "fs";
230527
231068
  import * as path9 from "path";
230528
231069
 
231070
+ // src/path_safety.ts
231071
+ init_errors();
231072
+ import * as path5 from "path";
231073
+ var SAFE_NAME_RE = /^(?!\.\.?$)(?!\.)[A-Za-z0-9._-]{1,255}$/;
231074
+ var MAX_MODEL_PATH_LEN = 1024;
231075
+ var SAFE_ENVIRONMENT_PATH_RE = /^(?:\/|[A-Za-z]:[\\/])[\x20-\x7E]*$/;
231076
+ var MAX_ENVIRONMENT_PATH_LEN = 4096;
231077
+ function assertSafePackageName(packageName) {
231078
+ if (typeof packageName !== "string" || !SAFE_NAME_RE.test(packageName)) {
231079
+ throw new BadRequestError(`Invalid package name: must be 1-255 characters of letters, digits, "-", "_", or "." and must not start with "."`);
231080
+ }
231081
+ }
231082
+ function assertSafeRelativeModelPath(modelPath) {
231083
+ if (typeof modelPath !== "string" || modelPath.length === 0 || modelPath.length > MAX_MODEL_PATH_LEN || modelPath.includes("\x00") || modelPath.includes("\\") || path5.isAbsolute(modelPath) || modelPath.startsWith("/")) {
231084
+ throw new BadRequestError(`Invalid model path`);
231085
+ }
231086
+ const segments = modelPath.split("/");
231087
+ for (const segment of segments) {
231088
+ if (segment === "" || segment === "." || segment === "..") {
231089
+ throw new BadRequestError(`Invalid model path`);
231090
+ }
231091
+ if (segment.startsWith(".")) {
231092
+ throw new BadRequestError(`Invalid model path`);
231093
+ }
231094
+ }
231095
+ }
231096
+ function assertSafeEnvironmentPath(environmentPath) {
231097
+ if (typeof environmentPath !== "string") {
231098
+ throw new BadRequestError(`Invalid environment path: must be a string`);
231099
+ }
231100
+ if (environmentPath.length === 0 || environmentPath.length > MAX_ENVIRONMENT_PATH_LEN) {
231101
+ throw new BadRequestError(`Invalid environment path: bad length`);
231102
+ }
231103
+ if (environmentPath.indexOf("\x00") !== -1) {
231104
+ throw new BadRequestError(`Invalid environment path: contains NUL byte`);
231105
+ }
231106
+ if (environmentPath.indexOf("..") !== -1) {
231107
+ throw new BadRequestError(`Invalid environment path: contains ".." traversal segment`);
231108
+ }
231109
+ if (!SAFE_ENVIRONMENT_PATH_RE.test(environmentPath)) {
231110
+ throw new BadRequestError(`Invalid environment path: must be an absolute path of printable ASCII characters`);
231111
+ }
231112
+ }
231113
+ function safeJoinUnderRoot(root, ...segments) {
231114
+ const resolvedRoot = path5.resolve(root);
231115
+ const joined = path5.resolve(resolvedRoot, ...segments);
231116
+ const rootWithSep = resolvedRoot.endsWith(path5.sep) ? resolvedRoot : resolvedRoot + path5.sep;
231117
+ if (joined !== resolvedRoot && !joined.startsWith(rootWithSep)) {
231118
+ throw new BadRequestError(`Resolved path is outside of root`);
231119
+ }
231120
+ return joined;
231121
+ }
231122
+
230529
231123
  // src/utils.ts
230530
231124
  import * as fs3 from "fs";
230531
231125
  import * as path6 from "path";
230532
- import { fileURLToPath as fileURLToPath2 } from "url";
231126
+ import { fileURLToPath as fileURLToPath3 } from "url";
230533
231127
  var URL_READER = {
230534
231128
  readURL: (url2) => {
230535
231129
  let path7 = url2.toString();
230536
231130
  if (url2.protocol == "file:") {
230537
- path7 = fileURLToPath2(url2);
231131
+ path7 = fileURLToPath3(url2);
230538
231132
  }
230539
231133
  return fs3.promises.readFile(path7, "utf8");
230540
231134
  }
@@ -230544,6 +231138,9 @@ function ignoreDotfiles(file) {
230544
231138
  }
230545
231139
 
230546
231140
  // src/service/package.ts
231141
+ init_constants();
231142
+ init_errors();
231143
+ init_logger();
230547
231144
  var import_api3 = __toESM(require_src(), 1);
230548
231145
  var import_recursive_readdir = __toESM(require_recursive_readdir(), 1);
230549
231146
  import * as fs5 from "fs/promises";
@@ -230559,6 +231156,8 @@ import {
230559
231156
  } from "@malloydata/malloy";
230560
231157
 
230561
231158
  // src/service/model.ts
231159
+ init_compile_pool();
231160
+ init_constants();
230562
231161
  var import_api2 = __toESM(require_src(), 1);
230563
231162
  import {
230564
231163
  API,
@@ -230578,6 +231177,7 @@ import { createRequire as createRequire2 } from "module";
230578
231177
  import * as path7 from "path";
230579
231178
 
230580
231179
  // src/data_styles.ts
231180
+ init_logger();
230581
231181
  function compileDataStyles(styles) {
230582
231182
  try {
230583
231183
  return JSON.parse(styles);
@@ -230624,6 +231224,10 @@ class HackyDataStylesAccumulator {
230624
231224
  }
230625
231225
  }
230626
231226
 
231227
+ // src/service/model.ts
231228
+ init_errors();
231229
+ init_logger();
231230
+
230627
231231
  // src/service/filter.ts
230628
231232
  var VALID_FILTER_TYPES = new Set([
230629
231233
  "equal",
@@ -230816,6 +231420,15 @@ function tokenize(input) {
230816
231420
 
230817
231421
  // src/service/model.ts
230818
231422
  var MALLOY_VERSION = createRequire2(import.meta.url)("@malloydata/malloy/package.json").version;
231423
+ function malloyGivenToApi(given) {
231424
+ const type = given.type;
231425
+ const renderedType = type.type === "filter expression" ? `filter<${type.filterType}>` : type.type;
231426
+ return {
231427
+ name: given.name,
231428
+ type: renderedType,
231429
+ annotations: given.getTaglines(/^#\(/)
231430
+ };
231431
+ }
230819
231432
 
230820
231433
  class Model {
230821
231434
  packageName;
@@ -230823,6 +231436,8 @@ class Model {
230823
231436
  dataStyles;
230824
231437
  modelType;
230825
231438
  modelMaterializer;
231439
+ materializerBuilder;
231440
+ materializerBuildPromise;
230826
231441
  modelDef;
230827
231442
  modelInfo;
230828
231443
  sources;
@@ -230831,26 +231446,44 @@ class Model {
230831
231446
  runnableNotebookCells;
230832
231447
  compilationError;
230833
231448
  filterMap;
231449
+ givens;
231450
+ cachedStandardModel;
230834
231451
  meter = import_api2.metrics.getMeter("publisher");
230835
231452
  queryExecutionHistogram = this.meter.createHistogram("malloy_model_query_duration", {
230836
231453
  description: "How long it takes to execute a Malloy model query",
230837
231454
  unit: "ms"
230838
231455
  });
230839
- constructor(packageName, modelPath, dataStyles, modelType, modelMaterializer, modelDef, sources, queries, sourceInfos, runnableNotebookCells, compilationError, filterMap) {
231456
+ constructor(packageName, modelPath, dataStyles, modelType, modelMaterializer, modelDef, sources, queries, sourceInfos, runnableNotebookCells, compilationError, filterMap, givens, materializerBuilder) {
230840
231457
  this.packageName = packageName;
230841
231458
  this.modelPath = modelPath;
230842
231459
  this.dataStyles = dataStyles;
230843
231460
  this.modelType = modelType;
230844
231461
  this.modelDef = modelDef;
230845
231462
  this.modelMaterializer = modelMaterializer;
231463
+ this.materializerBuilder = materializerBuilder;
230846
231464
  this.sources = sources;
230847
231465
  this.queries = queries;
230848
231466
  this.sourceInfos = sourceInfos;
230849
231467
  this.runnableNotebookCells = runnableNotebookCells;
230850
231468
  this.compilationError = compilationError;
230851
231469
  this.filterMap = filterMap ?? new Map;
231470
+ this.givens = givens;
230852
231471
  this.modelInfo = this.modelDef ? modelDefToModelInfo(this.modelDef) : undefined;
230853
231472
  }
231473
+ async ensureMaterializer() {
231474
+ if (this.modelMaterializer)
231475
+ return this.modelMaterializer;
231476
+ if (!this.materializerBuilder) {
231477
+ throw new BadRequestError("Model has no queryable entities.");
231478
+ }
231479
+ if (!this.materializerBuildPromise) {
231480
+ this.materializerBuildPromise = this.materializerBuilder().then((mm) => {
231481
+ this.modelMaterializer = mm;
231482
+ return mm;
231483
+ });
231484
+ }
231485
+ return this.materializerBuildPromise;
231486
+ }
230854
231487
  getFilters(sourceName) {
230855
231488
  return this.filterMap.get(sourceName) ?? [];
230856
231489
  }
@@ -230862,6 +231495,40 @@ class Model {
230862
231495
  return runMatch?.[1] ?? arrowMatch?.[1];
230863
231496
  }
230864
231497
  static async create(packageName, packagePath, modelPath, malloyConfig, options) {
231498
+ const pool = getCompilePool();
231499
+ if (pool.enabled && modelPath.endsWith(MODEL_FILE_SUFFIX)) {
231500
+ try {
231501
+ return await Model.createViaWorker(packageName, packagePath, modelPath, malloyConfig, pool, options);
231502
+ } catch (poolError) {
231503
+ if (poolError instanceof ModelCompilationError || poolError instanceof MalloyError2) {
231504
+ return Model.makeErrorModel(packageName, modelPath, poolError instanceof MalloyError2 ? new ModelCompilationError(poolError) : poolError);
231505
+ }
231506
+ logger.warn("Compile worker failed; falling back to in-process compile", { packageName, modelPath, error: poolError });
231507
+ }
231508
+ }
231509
+ return Model.createInProcess(packageName, packagePath, modelPath, malloyConfig, options);
231510
+ }
231511
+ static async createViaWorker(packageName, packagePath, modelPath, malloyConfig, pool, options) {
231512
+ const resolvedConfig = Model.toMalloyConfig(malloyConfig);
231513
+ const outcome = await pool.compile({
231514
+ packagePath,
231515
+ modelPath,
231516
+ malloyConfig: resolvedConfig,
231517
+ defaultConnectionName: "duckdb",
231518
+ urlReader: URL_READER,
231519
+ buildManifest: options?.buildManifest
231520
+ });
231521
+ const materializerBuilder = async () => {
231522
+ const { runtime, modelURL, importBaseURL } = await Model.getModelRuntime(packagePath, modelPath, malloyConfig, options);
231523
+ return Model.getStandardModelMaterializer(runtime, importBaseURL, modelURL, modelPath);
231524
+ };
231525
+ return new Model(packageName, modelPath, {}, "model", undefined, outcome.modelDef, outcome.sources, outcome.queries, outcome.sourceInfos.length > 0 ? outcome.sourceInfos : undefined, undefined, undefined, outcome.filterMap, outcome.givens, materializerBuilder);
231526
+ }
231527
+ static makeErrorModel(packageName, modelPath, error) {
231528
+ const isNotebook = modelPath.endsWith(NOTEBOOK_FILE_SUFFIX);
231529
+ return new Model(packageName, modelPath, {}, isNotebook ? "notebook" : "model", undefined, undefined, undefined, undefined, undefined, undefined, error);
231530
+ }
231531
+ static async createInProcess(packageName, packagePath, modelPath, malloyConfig, options) {
230865
231532
  const { runtime, modelURL, importBaseURL, dataStyles, modelType } = await Model.getModelRuntime(packagePath, modelPath, malloyConfig, options);
230866
231533
  try {
230867
231534
  const { modelMaterializer, runnableNotebookCells } = await Model.getModelMaterializer(runtime, importBaseURL, modelURL, modelPath);
@@ -230869,10 +231536,14 @@ class Model {
230869
231536
  let sources = undefined;
230870
231537
  let queries = undefined;
230871
231538
  let filterMap;
231539
+ let givens;
230872
231540
  const sourceInfos = [];
230873
231541
  if (modelMaterializer) {
230874
- modelDef = (await modelMaterializer.getModel())._modelDef;
230875
- const sourceResult = Model.getSources(modelPath, modelDef);
231542
+ const compiledModel = await modelMaterializer.getModel();
231543
+ modelDef = compiledModel._modelDef;
231544
+ const malloyGivens = Array.from(compiledModel.givens.values());
231545
+ givens = malloyGivens.length > 0 ? malloyGivens.map(malloyGivenToApi) : undefined;
231546
+ const sourceResult = Model.getSources(modelPath, modelDef, givens);
230876
231547
  sources = sourceResult.sources;
230877
231548
  filterMap = sourceResult.filterMap;
230878
231549
  queries = Model.getQueries(modelPath, modelDef);
@@ -230905,7 +231576,7 @@ class Model {
230905
231576
  }
230906
231577
  }
230907
231578
  }
230908
- return new Model(packageName, modelPath, dataStyles, modelType, modelMaterializer, modelDef, sources, queries, sourceInfos.length > 0 ? sourceInfos : undefined, runnableNotebookCells, undefined, filterMap);
231579
+ return new Model(packageName, modelPath, dataStyles, modelType, modelMaterializer, modelDef, sources, queries, sourceInfos.length > 0 ? sourceInfos : undefined, runnableNotebookCells, undefined, filterMap, givens);
230909
231580
  } catch (error) {
230910
231581
  let computedError = error;
230911
231582
  if (error instanceof Error && error.stack) {
@@ -230959,7 +231630,7 @@ class Model {
230959
231630
  throw new ModelNotFoundError(`${this.modelPath} is not a valid notebook name. Notebook files must end in .malloynb.`);
230960
231631
  }
230961
231632
  }
230962
- async getQueryResults(sourceName, queryName, query, filterParams, bypassFilters) {
231633
+ async getQueryResults(sourceName, queryName, query, filterParams, bypassFilters, givens) {
230963
231634
  const startTime = performance.now();
230964
231635
  if (this.compilationError) {
230965
231636
  if (this.compilationError instanceof MalloyError2 || this.compilationError instanceof ModelCompilationError) {
@@ -230968,8 +231639,18 @@ class Model {
230968
231639
  throw new BadRequestError(`Model compilation failed: ${this.compilationError.message}`);
230969
231640
  }
230970
231641
  let runnable;
230971
- if (!this.modelMaterializer || !this.modelDef || !this.modelInfo)
231642
+ if (!this.modelDef || !this.modelInfo)
230972
231643
  throw new BadRequestError("Model has no queryable entities.");
231644
+ let materializer;
231645
+ try {
231646
+ materializer = await this.ensureMaterializer();
231647
+ } catch (error) {
231648
+ if (error instanceof BadRequestError)
231649
+ throw error;
231650
+ if (error instanceof MalloyError2)
231651
+ throw error;
231652
+ throw new BadRequestError(error instanceof Error ? `Failed to prepare model: ${error.message}` : "Failed to prepare model.");
231653
+ }
230973
231654
  try {
230974
231655
  let queryString;
230975
231656
  if (!sourceName && !queryName && query) {
@@ -231000,7 +231681,7 @@ run: ${sourceName ? sourceName + "->" : ""}${queryName}`;
231000
231681
  }
231001
231682
  }
231002
231683
  }
231003
- runnable = this.modelMaterializer.loadQuery(queryString);
231684
+ runnable = materializer.loadQuery(queryString);
231004
231685
  } catch (error) {
231005
231686
  if (error instanceof BadRequestError) {
231006
231687
  throw error;
@@ -231023,12 +231704,12 @@ run: ${sourceName ? sourceName + "->" : ""}${queryName}`;
231023
231704
  });
231024
231705
  throw new BadRequestError(`Invalid query: ${errorMessage}`);
231025
231706
  }
231026
- const rowLimit = (await runnable.getPreparedResult()).resultExplore.limit || ROW_LIMIT;
231707
+ const rowLimit = (await runnable.getPreparedResult({ givens })).resultExplore.limit || ROW_LIMIT;
231027
231708
  const endTime = performance.now();
231028
231709
  const executionTime = endTime - startTime;
231029
231710
  let queryResults;
231030
231711
  try {
231031
- queryResults = await runnable.run({ rowLimit });
231712
+ queryResults = await runnable.run({ rowLimit, givens });
231032
231713
  } catch (error) {
231033
231714
  const errorEndTime = performance.now();
231034
231715
  const errorExecutionTime = errorEndTime - startTime;
@@ -231072,7 +231753,9 @@ run: ${sourceName ? sourceName + "->" : ""}${queryName}`;
231072
231753
  };
231073
231754
  }
231074
231755
  getStandardModel() {
231075
- return {
231756
+ if (this.cachedStandardModel)
231757
+ return this.cachedStandardModel;
231758
+ const compiled = {
231076
231759
  type: "source",
231077
231760
  packageName: this.packageName,
231078
231761
  modelPath: this.modelPath,
@@ -231082,8 +231765,11 @@ run: ${sourceName ? sourceName + "->" : ""}${queryName}`;
231082
231765
  modelInfo: JSON.stringify(this.modelDef ? modelDefToModelInfo(this.modelDef) : {}),
231083
231766
  sourceInfos: this.getSourceInfos()?.map((sourceInfo) => JSON.stringify(sourceInfo)),
231084
231767
  sources: this.sources,
231085
- queries: this.queries
231768
+ queries: this.queries,
231769
+ givens: this.givens
231086
231770
  };
231771
+ this.cachedStandardModel = compiled;
231772
+ return compiled;
231087
231773
  }
231088
231774
  async getNotebookModel() {
231089
231775
  const notebookCells = this.runnableNotebookCells.map((cell) => {
@@ -231117,7 +231803,7 @@ run: ${sourceName ? sourceName + "->" : ""}${queryName}`;
231117
231803
  notebookCells
231118
231804
  };
231119
231805
  }
231120
- async executeNotebookCell(cellIndex, filterParams, bypassFilters) {
231806
+ async executeNotebookCell(cellIndex, filterParams, bypassFilters, givens) {
231121
231807
  if (this.compilationError) {
231122
231808
  throw this.compilationError;
231123
231809
  }
@@ -231152,8 +231838,8 @@ run: ${sourceName ? sourceName + "->" : ""}${queryName}`;
231152
231838
  }
231153
231839
  }
231154
231840
  }
231155
- const rowLimit = (await runnableToExecute.getPreparedResult()).resultExplore.limit || ROW_LIMIT;
231156
- const result = await runnableToExecute.run({ rowLimit });
231841
+ const rowLimit = (await runnableToExecute.getPreparedResult({ givens })).resultExplore.limit || ROW_LIMIT;
231842
+ const result = await runnableToExecute.run({ rowLimit, givens });
231157
231843
  const query = (await runnableToExecute.getPreparedQuery())._query;
231158
231844
  queryName = query.as || query.name;
231159
231845
  queryResult = result?._queryResult && this.modelInfo && JSON.stringify(API.util.wrapResult(result));
@@ -231230,7 +231916,7 @@ run: ${sourceName ? sourceName + "->" : ""}${queryName}`;
231230
231916
  annotations: queryObj?.annotation?.blockNotes?.filter((note) => note.at.url.includes(modelPath)).map((note) => note.text)
231231
231917
  }));
231232
231918
  }
231233
- static getSources(modelPath, modelDef) {
231919
+ static getSources(modelPath, modelDef, givens) {
231234
231920
  const filterMap = new Map;
231235
231921
  const sources = Object.values(modelDef.contents).filter((obj) => isSourceDef(obj)).map((sourceObj) => {
231236
231922
  const sourceName = sourceObj.as || sourceObj.name;
@@ -231275,7 +231961,8 @@ run: ${sourceName ? sourceName + "->" : ""}${queryName}`;
231275
231961
  name: sourceName,
231276
231962
  annotations,
231277
231963
  views,
231278
- filters
231964
+ filters,
231965
+ givens
231279
231966
  };
231280
231967
  });
231281
231968
  return { sources, filterMap };
@@ -231707,6 +232394,8 @@ class Package {
231707
232394
  }
231708
232395
 
231709
232396
  // src/service/environment.ts
232397
+ var STAGING_DIR_NAME = ".staging";
232398
+ var RETIRED_DIR_NAME = ".retired";
231710
232399
  var RETIRED_CONNECTION_DRAIN_MS = 30000;
231711
232400
 
231712
232401
  class Environment {
@@ -231720,7 +232409,9 @@ class Environment {
231720
232409
  environmentPath;
231721
232410
  environmentName;
231722
232411
  metadata;
232412
+ memoryGovernor = null;
231723
232413
  constructor(environmentName, environmentPath, malloyConfig, apiConnections) {
232414
+ assertSafeEnvironmentPath(environmentPath);
231724
232415
  this.environmentName = environmentName;
231725
232416
  this.environmentPath = environmentPath;
231726
232417
  this.malloyConfig = malloyConfig;
@@ -231777,6 +232468,7 @@ class Environment {
231777
232468
  apiConnections: malloyConfig.apiConnections
231778
232469
  });
231779
232470
  const environment = new Environment(environmentName, environmentPath, malloyConfig, malloyConfig.apiConnections);
232471
+ await Environment.sweepStaleInstallDirs(environmentPath);
231780
232472
  return environment;
231781
232473
  }
231782
232474
  async reloadEnvironmentMetadata() {
@@ -231792,47 +232484,51 @@ class Environment {
231792
232484
  };
231793
232485
  return this.metadata;
231794
232486
  }
231795
- async compileSource(packageName, modelName, source, includeSql = false) {
231796
- const modelDir = path9.dirname(path9.join(this.environmentPath, packageName, modelName));
231797
- const virtualUri = `file://${path9.join(modelDir, "__compile_check.malloy")}`;
231798
- const virtualUrl = new URL(virtualUri);
231799
- const modelPath = path9.join(this.environmentPath, packageName, modelName);
231800
- let modelContent = "";
231801
- try {
231802
- modelContent = await fs6.promises.readFile(modelPath, "utf8");
231803
- } catch {}
231804
- const fullSource = modelContent ? `${modelContent}
232487
+ async compileSource(packageName, modelName, source, includeSql = false, givens) {
232488
+ assertSafePackageName(packageName);
232489
+ assertSafeRelativeModelPath(modelName);
232490
+ return this.withPackageLock(packageName, async () => {
232491
+ const modelPath = safeJoinUnderRoot(this.environmentPath, packageName, modelName);
232492
+ const modelDir = path9.dirname(modelPath);
232493
+ const virtualUri = `file://${path9.join(modelDir, "__compile_check.malloy")}`;
232494
+ const virtualUrl = new URL(virtualUri);
232495
+ let modelContent = "";
232496
+ try {
232497
+ modelContent = await fs6.promises.readFile(modelPath, "utf8");
232498
+ } catch {}
232499
+ const fullSource = modelContent ? `${modelContent}
231805
232500
  ${source}` : source;
231806
- const interceptingReader = {
231807
- readURL: async (url2) => {
231808
- if (url2.toString() === virtualUri) {
231809
- return fullSource;
232501
+ const interceptingReader = {
232502
+ readURL: async (url2) => {
232503
+ if (url2.toString() === virtualUri) {
232504
+ return fullSource;
232505
+ }
232506
+ return URL_READER.readURL(url2);
232507
+ }
232508
+ };
232509
+ const pkg = await this._loadOrGetPackageLocked(packageName);
232510
+ const runtime = new Runtime2({
232511
+ urlReader: interceptingReader,
232512
+ config: pkg.getMalloyConfig()
232513
+ });
232514
+ try {
232515
+ const modelMaterializer = runtime.loadModel(virtualUrl);
232516
+ const model = await modelMaterializer.getModel();
232517
+ let sql;
232518
+ if (includeSql) {
232519
+ try {
232520
+ const queryMaterializer = modelMaterializer.loadFinalQuery();
232521
+ sql = await queryMaterializer.getSQL({ givens });
232522
+ } catch {}
232523
+ }
232524
+ return { problems: model.problems, sql };
232525
+ } catch (error) {
232526
+ if (error instanceof MalloyError3) {
232527
+ return { problems: error.problems };
231810
232528
  }
231811
- return URL_READER.readURL(url2);
232529
+ throw error;
231812
232530
  }
231813
- };
231814
- const pkg = await this.getPackage(packageName);
231815
- const runtime = new Runtime2({
231816
- urlReader: interceptingReader,
231817
- config: pkg.getMalloyConfig()
231818
232531
  });
231819
- try {
231820
- const modelMaterializer = runtime.loadModel(virtualUrl);
231821
- const model = await modelMaterializer.getModel();
231822
- let sql;
231823
- if (includeSql) {
231824
- try {
231825
- const queryMaterializer = modelMaterializer.loadFinalQuery();
231826
- sql = await queryMaterializer.getSQL();
231827
- } catch {}
231828
- }
231829
- return { problems: model.problems, sql };
231830
- } catch (error) {
231831
- if (error instanceof MalloyError3) {
231832
- return { problems: error.problems };
231833
- }
231834
- throw error;
231835
- }
231836
232532
  }
231837
232533
  listApiConnections() {
231838
232534
  return this.apiConnections;
@@ -231916,85 +232612,190 @@ ${source}` : source;
231916
232612
  }
231917
232613
  return packageMutex;
231918
232614
  }
231919
- async getPackage(packageName, reload = false) {
232615
+ async withPackageLock(packageName, fn) {
232616
+ assertSafePackageName(packageName);
232617
+ return this.getOrCreatePackageMutex(packageName).runExclusive(fn);
232618
+ }
232619
+ allocateStagingPath(packageName) {
232620
+ return safeJoinUnderRoot(this.environmentPath, STAGING_DIR_NAME, `${packageName}-${crypto4.randomUUID()}`);
232621
+ }
232622
+ allocateRetiredPath(packageName) {
232623
+ return safeJoinUnderRoot(this.environmentPath, RETIRED_DIR_NAME, `${packageName}-${crypto4.randomUUID()}`);
232624
+ }
232625
+ static async sweepStaleInstallDirs(environmentPath) {
232626
+ assertSafeEnvironmentPath(environmentPath);
232627
+ for (const dirName of [STAGING_DIR_NAME, RETIRED_DIR_NAME]) {
232628
+ const dir = safeJoinUnderRoot(environmentPath, dirName);
232629
+ if (dir.indexOf("..") !== -1)
232630
+ continue;
232631
+ if (path9.basename(dir) !== dirName)
232632
+ continue;
232633
+ try {
232634
+ await fs6.promises.rm(dir, { recursive: true, force: true });
232635
+ } catch (err) {
232636
+ logger.warn(`Failed to sweep stale ${dirName} dir at ${dir}`, {
232637
+ error: err
232638
+ });
232639
+ }
232640
+ }
232641
+ }
232642
+ setMemoryGovernor(governor) {
232643
+ this.memoryGovernor = governor;
232644
+ }
232645
+ assertCanAdmitNewPackage(packageName, reason, allowAdmission) {
232646
+ if (allowAdmission)
232647
+ return;
232648
+ if (!this.memoryGovernor?.isBackpressured())
232649
+ return;
232650
+ throw new ServiceUnavailableError(`Publisher is under memory pressure and cannot ${reason} (package "${packageName}", environment "${this.environmentName}"). Retry after the server's memory usage drops below the configured low-water mark.`);
232651
+ }
232652
+ async getPackage(packageName, reload = false, options = {}) {
232653
+ assertSafePackageName(packageName);
231920
232654
  const _package = this.packages.get(packageName);
231921
232655
  if (_package !== undefined && !reload) {
231922
232656
  return _package;
231923
232657
  }
231924
- const packageMutex = this.getOrCreatePackageMutex(packageName);
231925
- if (packageMutex.isLocked()) {
231926
- logger.debug(`Package ${packageName} is being loaded, waiting for unlock...`);
231927
- await packageMutex.waitForUnlock();
231928
- logger.debug(`Package ${packageName} unlocked`);
231929
- const existingPackage = this.packages.get(packageName);
231930
- if (existingPackage !== undefined && !reload) {
231931
- logger.debug(`Package ${packageName} loaded by another request`);
231932
- return existingPackage;
231933
- }
232658
+ this.assertCanAdmitNewPackage(packageName, reload ? "reload a package" : "load a package", options.allowAdmission === true);
232659
+ return this.withPackageLock(packageName, () => this._loadOrGetPackageLocked(packageName, reload));
232660
+ }
232661
+ async _loadOrGetPackageLocked(packageName, reload = false) {
232662
+ const existingPackage = this.packages.get(packageName);
232663
+ if (existingPackage !== undefined && !reload) {
232664
+ return existingPackage;
231934
232665
  }
231935
- return packageMutex.runExclusive(async () => {
231936
- const existingPackage = this.packages.get(packageName);
231937
- if (existingPackage !== undefined && !reload) {
231938
- return existingPackage;
231939
- }
231940
- this.setPackageStatus(packageName, "loading" /* LOADING */);
231941
- try {
231942
- logger.debug(`Loading package ${packageName}...`);
231943
- const packagePath = path9.join(this.environmentPath, packageName);
231944
- const _package2 = await Package.create(this.environmentName, packageName, packagePath, () => this.malloyConfig.malloyConfig);
231945
- if (existingPackage !== undefined && reload) {
231946
- this.retireConnectionGeneration(`package ${packageName}`, () => existingPackage.getMalloyConfig().releaseConnections());
231947
- }
231948
- this.packages.set(packageName, _package2);
231949
- this.setPackageStatus(packageName, "serving" /* SERVING */);
231950
- logger.debug(`Successfully loaded package ${packageName}`);
231951
- return _package2;
231952
- } catch (error) {
231953
- logger.error(`Failed to load package ${packageName}`, { error });
231954
- this.packages.delete(packageName);
231955
- this.packageStatuses.delete(packageName);
231956
- throw error;
232666
+ this.setPackageStatus(packageName, "loading" /* LOADING */);
232667
+ try {
232668
+ logger.debug(`Loading package ${packageName}...`);
232669
+ const packagePath = safeJoinUnderRoot(this.environmentPath, packageName);
232670
+ const _package = await Package.create(this.environmentName, packageName, packagePath, () => this.malloyConfig.malloyConfig);
232671
+ if (existingPackage !== undefined && reload) {
232672
+ this.retireConnectionGeneration(`package ${packageName}`, () => existingPackage.getMalloyConfig().releaseConnections());
231957
232673
  }
231958
- });
232674
+ this.packages.set(packageName, _package);
232675
+ this.setPackageStatus(packageName, "serving" /* SERVING */);
232676
+ logger.debug(`Successfully loaded package ${packageName}`);
232677
+ return _package;
232678
+ } catch (error) {
232679
+ logger.error(`Failed to load package ${packageName}`, { error });
232680
+ this.packages.delete(packageName);
232681
+ this.packageStatuses.delete(packageName);
232682
+ throw error;
232683
+ }
231959
232684
  }
231960
- async addPackage(packageName) {
231961
- const packagePath = path9.join(this.environmentPath, packageName);
232685
+ async addPackage(packageName, options = {}) {
232686
+ assertSafePackageName(packageName);
232687
+ const packagePath = safeJoinUnderRoot(this.environmentPath, packageName);
231962
232688
  if (!await fs6.promises.access(packagePath).then(() => true).catch(() => false) || !(await fs6.promises.stat(packagePath))?.isDirectory()) {
231963
232689
  throw new PackageNotFoundError(`Package ${packageName} not found`);
231964
232690
  }
232691
+ this.assertCanAdmitNewPackage(packageName, "add a new package", options.allowAdmission === true);
231965
232692
  logger.info(`Adding package ${packageName} to environment ${this.environmentName}`, {
231966
232693
  packagePath,
231967
232694
  malloyConfig: this.malloyConfig.malloyConfig
231968
232695
  });
231969
- const packageMutex = this.getOrCreatePackageMutex(packageName);
231970
- if (packageMutex.isLocked()) {
231971
- logger.debug(`Package ${packageName} is being loaded, waiting before addPackage...`);
231972
- await packageMutex.waitForUnlock();
231973
- const alreadyLoaded = this.packages.get(packageName);
231974
- if (alreadyLoaded !== undefined) {
231975
- return alreadyLoaded;
231976
- }
232696
+ return this.withPackageLock(packageName, () => this._addPackageLocked(packageName));
232697
+ }
232698
+ async _addPackageLocked(packageName) {
232699
+ const packagePath = safeJoinUnderRoot(this.environmentPath, packageName);
232700
+ const existingPackage = this.packages.get(packageName);
232701
+ if (existingPackage !== undefined) {
232702
+ return existingPackage;
231977
232703
  }
231978
- return packageMutex.runExclusive(async () => {
231979
- const existingPackage = this.packages.get(packageName);
231980
- if (existingPackage !== undefined) {
231981
- return existingPackage;
232704
+ this.setPackageStatus(packageName, "loading" /* LOADING */);
232705
+ try {
232706
+ this.packages.set(packageName, await Package.create(this.environmentName, packageName, packagePath, () => this.malloyConfig.malloyConfig));
232707
+ } catch (error) {
232708
+ logger.error("Error adding package", { error });
232709
+ this.deletePackageStatus(packageName);
232710
+ throw error;
232711
+ }
232712
+ this.setPackageStatus(packageName, "serving" /* SERVING */);
232713
+ return this.packages.get(packageName);
232714
+ }
232715
+ async installPackage(packageName, downloader) {
232716
+ assertSafePackageName(packageName);
232717
+ const stagingPath = this.allocateStagingPath(packageName);
232718
+ await fs6.promises.mkdir(path9.dirname(stagingPath), { recursive: true });
232719
+ try {
232720
+ await downloader(stagingPath);
232721
+ } catch (err) {
232722
+ await fs6.promises.rm(stagingPath, { recursive: true, force: true }).catch(() => {});
232723
+ throw err;
232724
+ }
232725
+ return this.withPackageLock(packageName, async () => {
232726
+ const canonicalPath = safeJoinUnderRoot(this.environmentPath, packageName);
232727
+ let retiredPath;
232728
+ const oldPackage = this.packages.get(packageName);
232729
+ const oldExistsOnDisk = await fs6.promises.access(canonicalPath).then(() => true).catch(() => false);
232730
+ if (oldExistsOnDisk) {
232731
+ retiredPath = this.allocateRetiredPath(packageName);
232732
+ await fs6.promises.mkdir(path9.dirname(retiredPath), {
232733
+ recursive: true
232734
+ });
232735
+ await fs6.promises.rename(canonicalPath, retiredPath);
231982
232736
  }
231983
- this.setPackageStatus(packageName, "loading" /* LOADING */);
232737
+ let newPackage;
231984
232738
  try {
231985
- this.packages.set(packageName, await Package.create(this.environmentName, packageName, packagePath, () => this.malloyConfig.malloyConfig));
231986
- } catch (error) {
231987
- logger.error("Error adding package", { error });
232739
+ await fs6.promises.rename(stagingPath, canonicalPath);
232740
+ this.setPackageStatus(packageName, "loading" /* LOADING */);
232741
+ newPackage = await Package.create(this.environmentName, packageName, canonicalPath, () => this.malloyConfig.malloyConfig);
232742
+ } catch (err) {
232743
+ await fs6.promises.rm(canonicalPath, { recursive: true, force: true }).catch(() => {});
232744
+ if (retiredPath) {
232745
+ try {
232746
+ await fs6.promises.rename(retiredPath, canonicalPath);
232747
+ } catch (restoreErr) {
232748
+ logger.error("Failed to restore retired package after install rollback", {
232749
+ error: restoreErr,
232750
+ retiredPath,
232751
+ canonicalPath
232752
+ });
232753
+ }
232754
+ }
232755
+ await fs6.promises.rm(stagingPath, { recursive: true, force: true }).catch(() => {});
231988
232756
  this.deletePackageStatus(packageName);
231989
- throw error;
232757
+ throw err;
231990
232758
  }
232759
+ this.packages.set(packageName, newPackage);
231991
232760
  this.setPackageStatus(packageName, "serving" /* SERVING */);
231992
- return this.packages.get(packageName);
232761
+ if (oldPackage) {
232762
+ this.retireConnectionGeneration(`package ${packageName}`, () => oldPackage.getMalloyConfig().releaseConnections());
232763
+ }
232764
+ if (retiredPath) {
232765
+ const pathToClean = retiredPath;
232766
+ setImmediate(() => {
232767
+ fs6.promises.rm(pathToClean, { recursive: true, force: true }).catch((err) => {
232768
+ logger.warn(`Failed to clean up retired package directory ${pathToClean}`, { error: err });
232769
+ });
232770
+ });
232771
+ }
232772
+ return newPackage;
232773
+ });
232774
+ }
232775
+ async reloadAllModelsForPackage(packageName, manifest) {
232776
+ assertSafePackageName(packageName);
232777
+ return this.withPackageLock(packageName, async () => {
232778
+ const pkg = this.packages.get(packageName);
232779
+ if (!pkg) {
232780
+ throw new PackageNotFoundError(`Package ${packageName} is not loaded`);
232781
+ }
232782
+ await pkg.reloadAllModels(manifest);
232783
+ });
232784
+ }
232785
+ async getModelFileText(packageName, modelPath) {
232786
+ assertSafePackageName(packageName);
232787
+ assertSafeRelativeModelPath(modelPath);
232788
+ return this.withPackageLock(packageName, async () => {
232789
+ const pkg = this.packages.get(packageName);
232790
+ if (!pkg) {
232791
+ throw new PackageNotFoundError(`Package ${packageName} is not loaded`);
232792
+ }
232793
+ return pkg.getModelFileText(modelPath);
231993
232794
  });
231994
232795
  }
231995
232796
  async writePackageManifest(packageName, metadata) {
231996
- const packagePath = path9.join(this.environmentPath, packageName);
231997
- const manifestPath = path9.join(packagePath, "publisher.json");
232797
+ const packagePath = safeJoinUnderRoot(this.environmentPath, packageName);
232798
+ const manifestPath = safeJoinUnderRoot(packagePath, "publisher.json");
231998
232799
  try {
231999
232800
  let existingManifest = {};
232000
232801
  try {
@@ -232016,24 +232817,27 @@ ${source}` : source;
232016
232817
  }
232017
232818
  }
232018
232819
  async updatePackage(packageName, body) {
232019
- const _package = this.packages.get(packageName);
232020
- if (!_package) {
232021
- throw new PackageNotFoundError(`Package ${packageName} not found`);
232022
- }
232023
- if (body.name) {
232024
- _package.setName(body.name);
232025
- }
232026
- _package.setPackageMetadata({
232027
- name: body.name,
232028
- description: body.description,
232029
- resource: body.resource,
232030
- location: body.location
232031
- });
232032
- await this.writePackageManifest(packageName, {
232033
- name: packageName,
232034
- description: body.description
232820
+ assertSafePackageName(packageName);
232821
+ return this.withPackageLock(packageName, async () => {
232822
+ const _package = this.packages.get(packageName);
232823
+ if (!_package) {
232824
+ throw new PackageNotFoundError(`Package ${packageName} not found`);
232825
+ }
232826
+ if (body.name) {
232827
+ _package.setName(body.name);
232828
+ }
232829
+ _package.setPackageMetadata({
232830
+ name: body.name,
232831
+ description: body.description,
232832
+ resource: body.resource,
232833
+ location: body.location
232834
+ });
232835
+ await this.writePackageManifest(packageName, {
232836
+ name: packageName,
232837
+ description: body.description
232838
+ });
232839
+ return _package.getPackageMetadata();
232035
232840
  });
232036
- return _package.getPackageMetadata();
232037
232841
  }
232038
232842
  getPackageStatus(packageName) {
232039
232843
  return this.packageStatuses.get(packageName);
@@ -232050,35 +232854,49 @@ ${source}` : source;
232050
232854
  this.packageStatuses.delete(packageName);
232051
232855
  }
232052
232856
  async deletePackage(packageName) {
232053
- const _package = this.packages.get(packageName);
232054
- if (!_package) {
232055
- return;
232056
- }
232057
- const packageStatus = this.packageStatuses.get(packageName);
232058
- if (packageStatus?.status === "loading" /* LOADING */) {
232059
- logger.error("Package loading. Can't unload.", {
232060
- environmentName: this.environmentName,
232061
- packageName
232062
- });
232063
- throw new Error("Package loading. Can't unload. " + this.environmentName + " " + packageName);
232064
- } else if (packageStatus?.status === "serving" /* SERVING */) {
232065
- this.setPackageStatus(packageName, "unloading" /* UNLOADING */);
232066
- }
232067
- await _package.getMalloyConfig().releaseConnections();
232068
- try {
232069
- await fs6.promises.rm(path9.join(this.environmentPath, packageName), {
232070
- recursive: true,
232071
- force: true
232072
- });
232073
- } catch (err) {
232074
- logger.error("Error removing package directory while unloading package", {
232075
- error: err,
232076
- environmentName: this.environmentName,
232077
- packageName
232078
- });
232079
- }
232080
- this.packages.delete(packageName);
232081
- this.packageStatuses.delete(packageName);
232857
+ assertSafePackageName(packageName);
232858
+ return this.withPackageLock(packageName, async () => {
232859
+ const _package = this.packages.get(packageName);
232860
+ if (!_package) {
232861
+ return;
232862
+ }
232863
+ const packageStatus = this.packageStatuses.get(packageName);
232864
+ if (packageStatus?.status === "loading" /* LOADING */) {
232865
+ logger.error("Package loading. Can't unload.", {
232866
+ environmentName: this.environmentName,
232867
+ packageName
232868
+ });
232869
+ throw new Error("Package loading. Can't unload. " + this.environmentName + " " + packageName);
232870
+ } else if (packageStatus?.status === "serving" /* SERVING */) {
232871
+ this.setPackageStatus(packageName, "unloading" /* UNLOADING */);
232872
+ }
232873
+ this.retireConnectionGeneration(`package ${packageName}`, () => _package.getMalloyConfig().releaseConnections());
232874
+ const canonicalPath = safeJoinUnderRoot(this.environmentPath, packageName);
232875
+ const retiredPath = this.allocateRetiredPath(packageName);
232876
+ let renamed = false;
232877
+ try {
232878
+ await fs6.promises.mkdir(path9.dirname(retiredPath), {
232879
+ recursive: true
232880
+ });
232881
+ await fs6.promises.rename(canonicalPath, retiredPath);
232882
+ renamed = true;
232883
+ } catch (err) {
232884
+ logger.error("Error renaming package directory to retired during unload", {
232885
+ error: err,
232886
+ environmentName: this.environmentName,
232887
+ packageName
232888
+ });
232889
+ }
232890
+ this.packages.delete(packageName);
232891
+ this.packageStatuses.delete(packageName);
232892
+ if (renamed) {
232893
+ setImmediate(() => {
232894
+ fs6.promises.rm(retiredPath, { recursive: true, force: true }).catch((err) => {
232895
+ logger.warn(`Failed to clean up retired package directory ${retiredPath}`, { error: err });
232896
+ });
232897
+ });
232898
+ }
232899
+ });
232082
232900
  }
232083
232901
  updateConnections(malloyConfig, _apiConnections, afterPreviousRelease) {
232084
232902
  const previousMalloyConfig = this.malloyConfig;
@@ -232199,12 +233017,12 @@ class EnvironmentStore {
232199
233017
  publisherConfigIsFrozen;
232200
233018
  finishedInitialization;
232201
233019
  isInitialized = false;
232202
- failedEnvironments = [];
232203
233020
  storageManager;
232204
233021
  s3Client = new import_client_s32.S3({
232205
233022
  followRegionRedirects: true
232206
233023
  });
232207
233024
  gcsClient;
233025
+ memoryGovernor = null;
232208
233026
  constructor(serverRootPath) {
232209
233027
  this.serverRootPath = serverRootPath;
232210
233028
  this.gcsClient = new Storage;
@@ -232217,6 +233035,12 @@ class EnvironmentStore {
232217
233035
  this.storageManager = new StorageManager(storageConfig);
232218
233036
  this.finishedInitialization = this.initialize();
232219
233037
  }
233038
+ setMemoryGovernor(governor) {
233039
+ this.memoryGovernor = governor;
233040
+ for (const env of this.environments.values()) {
233041
+ env.setMemoryGovernor(governor);
233042
+ }
233043
+ }
232220
233044
  async addConfiguredEnvironment(environment) {
232221
233045
  try {
232222
233046
  await this.addEnvironment({
@@ -232232,10 +233056,6 @@ class EnvironmentStore {
232232
233056
  logEnvironmentInitializationError(environmentName, error) {
232233
233057
  const label = environmentName ? ` "${environmentName}"` : "";
232234
233058
  logger.error(`Error initializing environment${label}; skipping environment`, this.extractErrorDataFromError(error));
232235
- this.failedEnvironments.push({
232236
- name: environmentName ?? "<unknown>",
232237
- error: error instanceof Error ? error.message : String(error)
232238
- });
232239
233059
  }
232240
233060
  async initialize() {
232241
233061
  const reInit = process.env.INITIALIZE_STORAGE === "true";
@@ -232281,6 +233101,7 @@ class EnvironmentStore {
232281
233101
  resource: `${API_PREFIX}/connections/${conn.name}`,
232282
233102
  ...conn.config
232283
233103
  })));
233104
+ environmentInstance.setMemoryGovernor(this.memoryGovernor);
232284
233105
  const packages = await repository.listPackages(dbEnvironment.id);
232285
233106
  packages.forEach((pkg) => {
232286
233107
  environmentInstance.setPackageStatus(pkg.name, "serving" /* SERVING */);
@@ -232298,11 +233119,7 @@ class EnvironmentStore {
232298
233119
  }
232299
233120
  }
232300
233121
  this.isInitialized = true;
232301
- if (this.failedEnvironments.length > 0) {
232302
- markDegraded();
232303
- } else {
232304
- markReady();
232305
- }
233122
+ markReady();
232306
233123
  const initializationDuration = performance.now() - initialTime;
232307
233124
  logger.info(`Environment store successfully initialized in ${formatDuration(initializationDuration)}`);
232308
233125
  } catch (error) {
@@ -232538,12 +233355,7 @@ class EnvironmentStore {
232538
233355
  environments: [],
232539
233356
  initialized: this.isInitialized,
232540
233357
  frozenConfig: isPublisherConfigFrozen(this.serverRootPath),
232541
- operationalState: getOperationalState(),
232542
- ...this.failedEnvironments.length > 0 && {
232543
- failedEnvironments: [
232544
- ...this.failedEnvironments
232545
- ]
232546
- }
233358
+ operationalState: getOperationalState()
232547
233359
  };
232548
233360
  const environments = await this.listEnvironments(true);
232549
233361
  await Promise.all(environments.map(async (environment) => {
@@ -232641,6 +233453,7 @@ class EnvironmentStore {
232641
233453
  absoluteEnvironmentPath = await this.scaffoldEnvironment(environment);
232642
233454
  }
232643
233455
  const newEnvironment = await Environment.create(environmentName, absoluteEnvironmentPath, environment.connections || []);
233456
+ newEnvironment.setMemoryGovernor(this.memoryGovernor);
232644
233457
  if (!newEnvironment.metadata)
232645
233458
  newEnvironment.metadata = {};
232646
233459
  newEnvironment.metadata.location = absoluteEnvironmentPath;
@@ -232806,7 +233619,7 @@ class EnvironmentStore {
232806
233619
  });
232807
233620
  }
232808
233621
  for (const [groupedLocation, packagesForLocation] of locationGroups) {
232809
- const locationHash = crypto4.createHash("sha256").update(groupedLocation).digest("hex").substring(0, 16);
233622
+ const locationHash = crypto5.createHash("sha256").update(groupedLocation).digest("hex").substring(0, 16);
232810
233623
  const tempDownloadPath = `${absoluteTargetPath}/.temp_${locationHash}`;
232811
233624
  await fs7.promises.mkdir(tempDownloadPath, { recursive: true });
232812
233625
  logger.info(`Created temporary directory: ${tempDownloadPath}`);
@@ -232995,9 +233808,9 @@ class EnvironmentStore {
232995
233808
  }
232996
233809
  const file = fs7.createWriteStream(zipFilePath);
232997
233810
  item.Body.transformToWebStream().pipeTo(Writable.toWeb(file));
232998
- await new Promise((resolve3, reject) => {
233811
+ await new Promise((resolve4, reject) => {
232999
233812
  file.on("error", reject);
233000
- file.on("finish", resolve3);
233813
+ file.on("finish", resolve4);
233001
233814
  });
233002
233815
  await this.unzipEnvironment(zipFilePath);
233003
233816
  logger.info(`Downloaded S3 zip file ${s3Path} to ${absoluteDirPath}`);
@@ -233035,9 +233848,9 @@ class EnvironmentStore {
233035
233848
  }
233036
233849
  const file = fs7.createWriteStream(absoluteFilePath);
233037
233850
  item.Body.transformToWebStream().pipeTo(Writable.toWeb(file));
233038
- await new Promise((resolve3, reject) => {
233851
+ await new Promise((resolve4, reject) => {
233039
233852
  file.on("error", reject);
233040
- file.on("finish", resolve3);
233853
+ file.on("finish", resolve4);
233041
233854
  });
233042
233855
  }));
233043
233856
  logger.info(`Downloaded S3 directory ${s3Path} to ${absoluteDirPath}`);
@@ -233070,14 +233883,14 @@ class EnvironmentStore {
233070
233883
  });
233071
233884
  await fs7.promises.mkdir(absoluteDirPath, { recursive: true });
233072
233885
  const repoUrl = `https://github.com/${owner}/${repoName}`;
233073
- await new Promise((resolve3, reject) => {
233886
+ await new Promise((resolve4, reject) => {
233074
233887
  esm_default2().clone(repoUrl, absoluteDirPath, {}, (err) => {
233075
233888
  if (err) {
233076
233889
  const errorData = this.extractErrorDataFromError(err);
233077
233890
  logger.error(`Failed to clone GitHub repository "${repoUrl}"`, errorData);
233078
233891
  reject(err);
233079
233892
  }
233080
- resolve3();
233893
+ resolve4();
233081
233894
  });
233082
233895
  });
233083
233896
  if (!cleanPackagePath) {
@@ -233180,7 +233993,12 @@ class WatchModeController {
233180
233993
  };
233181
233994
  }
233182
233995
 
233996
+ // src/server.ts
233997
+ init_errors();
233998
+ init_logger();
233999
+
233183
234000
  // src/service/resolve_environment.ts
234001
+ init_errors();
233184
234002
  async function resolveEnvironmentId(repository, environmentName) {
233185
234003
  const dbEnvironment = await repository.getEnvironmentByName(environmentName);
233186
234004
  if (!dbEnvironment) {
@@ -233212,6 +234030,8 @@ class ManifestController {
233212
234030
  }
233213
234031
 
233214
234032
  // src/controller/materialization.controller.ts
234033
+ init_errors();
234034
+
233215
234035
  class MaterializationController {
233216
234036
  materializationService;
233217
234037
  constructor(materializationService) {
@@ -233473,7 +234293,7 @@ class Protocol {
233473
234293
  }
233474
234294
  request(request, resultSchema, options) {
233475
234295
  const { relatedRequestId, resumptionToken, onresumptiontoken } = options !== null && options !== undefined ? options : {};
233476
- return new Promise((resolve3, reject) => {
234296
+ return new Promise((resolve4, reject) => {
233477
234297
  var _a2, _b, _c, _d, _e, _f;
233478
234298
  if (!this._transport) {
233479
234299
  reject(new Error("Not connected"));
@@ -233524,7 +234344,7 @@ class Protocol {
233524
234344
  }
233525
234345
  try {
233526
234346
  const result = resultSchema.parse(response.result);
233527
- resolve3(result);
234347
+ resolve4(result);
233528
234348
  } catch (error) {
233529
234349
  reject(error);
233530
234350
  }
@@ -235898,6 +236718,12 @@ var EMPTY_COMPLETION_RESULT = {
235898
236718
  }
235899
236719
  };
235900
236720
 
236721
+ // src/mcp/server.ts
236722
+ init_logger();
236723
+
236724
+ // src/mcp/prompts/prompt_service.ts
236725
+ init_logger();
236726
+
235901
236727
  // src/mcp/prompts/handlers.ts
235902
236728
  var import_handlebars = __toESM(require_lib8(), 1);
235903
236729
 
@@ -236092,6 +236918,9 @@ function registerPromptCapability(mcpServer, environmentStore) {
236092
236918
  logger.info(`[MCP Init] Finished registering prompts. Registered: ${registeredCount}`, { duration: endTime - startTime });
236093
236919
  }
236094
236920
 
236921
+ // src/mcp/resources/environment_resource.ts
236922
+ init_logger();
236923
+
236095
236924
  // src/mcp/error_messages.ts
236096
236925
  function getNotFoundError(resourceUriOrContext) {
236097
236926
  const baseMessage = `Resource not found: ${resourceUriOrContext}`;
@@ -236181,6 +237010,9 @@ function getMalloyErrorDetails(operation, modelIdentifier, error) {
236181
237010
  }
236182
237011
 
236183
237012
  // src/mcp/handler_utils.ts
237013
+ init_errors();
237014
+ init_logger();
237015
+
236184
237016
  class McpGetResourceError extends Error {
236185
237017
  details;
236186
237018
  constructor(details) {
@@ -236393,6 +237225,7 @@ function registerEnvironmentResource(mcpServer, environmentStore) {
236393
237225
  }
236394
237226
 
236395
237227
  // src/mcp/resources/model_resource.ts
237228
+ init_errors();
236396
237229
  function registerModelResource(mcpServer, environmentStore) {
236397
237230
  mcpServer.resource("model", new ResourceTemplate("malloy://environment/{environmentName}/package/{packageName}/models/{modelPath}", { list: undefined }), (uri, params) => handleResourceGet(uri, params, "model", async ({
236398
237231
  environmentName,
@@ -236452,6 +237285,8 @@ function registerModelResource(mcpServer, environmentStore) {
236452
237285
  }
236453
237286
 
236454
237287
  // src/mcp/resources/notebook_resource.ts
237288
+ init_errors();
237289
+ init_logger();
236455
237290
  function registerNotebookResource(mcpServer, environmentStore) {
236456
237291
  mcpServer.resource("notebook", new ResourceTemplate("malloy://environment/{environmentName}/package/{packageName}/notebooks/{notebookName}", { list: undefined }), (uri, params) => handleResourceGet(uri, params, "notebook", async ({ environmentName, packageName, notebookName }, uri2) => {
236457
237292
  if (typeof environmentName !== "string" || typeof packageName !== "string" || typeof notebookName !== "string") {
@@ -236491,6 +237326,8 @@ function registerNotebookResource(mcpServer, environmentStore) {
236491
237326
  }
236492
237327
 
236493
237328
  // src/mcp/resources/package_resource.ts
237329
+ init_errors();
237330
+ init_logger();
236494
237331
  async function handleGetPackageContents(uri, params, environmentStore) {
236495
237332
  try {
236496
237333
  const { environmentName, packageName } = params;
@@ -236683,6 +237520,8 @@ function registerPackageResource(mcpServer, environmentStore) {
236683
237520
  }
236684
237521
 
236685
237522
  // src/mcp/resources/query_resource.ts
237523
+ init_errors();
237524
+ init_logger();
236686
237525
  function registerQueryResource(mcpServer, environmentStore) {
236687
237526
  mcpServer.resource("query", new ResourceTemplate("malloy://environment/{environmentName}/package/{packageName}/models/{modelPath}/queries/{queryName}", { list: undefined }), (uri, params) => handleResourceGet(uri, params, "query", async ({
236688
237527
  environmentName,
@@ -236725,6 +237564,8 @@ function registerQueryResource(mcpServer, environmentStore) {
236725
237564
  }
236726
237565
 
236727
237566
  // src/mcp/resources/source_resource.ts
237567
+ init_errors();
237568
+ init_logger();
236728
237569
  function registerSourceResource(mcpServer, environmentStore) {
236729
237570
  mcpServer.resource("source", new ResourceTemplate("malloy://environment/{environmentName}/package/{packageName}/models/{modelPath}/sources/{sourceName}", { list: undefined }), (uri, params) => handleResourceGet(uri, params, "source", async ({
236730
237571
  environmentName,
@@ -236770,6 +237611,8 @@ function registerSourceResource(mcpServer, environmentStore) {
236770
237611
  }
236771
237612
 
236772
237613
  // src/mcp/resources/view_resource.ts
237614
+ init_errors();
237615
+ init_logger();
236773
237616
  function registerViewResource(mcpServer, environmentStore) {
236774
237617
  mcpServer.resource("view", new ResourceTemplate("malloy://environment/{environmentName}/package/{packageName}/models/{modelPath}/sources/{sourceName}/views/{viewName}", { list: undefined }), (uri, params) => handleResourceGet(uri, params, "view", async ({
236775
237618
  environmentName,
@@ -236926,7 +237769,7 @@ function registerTools(mcpServer, environmentStore) {
236926
237769
  console.log("model not found", modelPath, "in ", pkg.listModels());
236927
237770
  throw new Error(`Model not found: ${modelPath}`);
236928
237771
  }
236929
- const fileText = await pkg.getModelFileText(modelPath);
237772
+ const fileText = await environment.getModelFileText(packageName, modelPath);
236930
237773
  console.log(`[MCP LOG] Successfully retrieved model text for ${modelPath}`);
236931
237774
  return {
236932
237775
  content: [
@@ -236967,6 +237810,9 @@ function registerTools(mcpServer, environmentStore) {
236967
237810
  });
236968
237811
  }
236969
237812
 
237813
+ // src/mcp/tools/execute_query_tool.ts
237814
+ init_logger();
237815
+
236970
237816
  // src/mcp/mcp_constants.ts
236971
237817
  var MCP_ERROR_MESSAGES = {
236972
237818
  MISSING_REQUIRED_PARAMS: "Either 'query' or both 'sourceName' and 'queryName' must be provided",
@@ -236989,7 +237835,8 @@ var executeQueryShape = {
236989
237835
  query: exports_external.string().optional().describe("Ad-hoc Malloy query code"),
236990
237836
  sourceName: exports_external.string().optional().describe("Source name for a view"),
236991
237837
  queryName: exports_external.string().optional().describe("Named query or view"),
236992
- filterParams: exports_external.record(exports_external.union([exports_external.string(), exports_external.array(exports_external.string())])).optional().describe("Filter parameter values keyed by filter name. Used with sources that declare #(filter) annotations.")
237838
+ filterParams: exports_external.record(exports_external.union([exports_external.string(), exports_external.array(exports_external.string())])).optional().describe("Filter parameter values keyed by filter name. Used with sources that declare #(filter) annotations."),
237839
+ givens: exports_external.record(exports_external.unknown()).optional().describe("Per-query given values that override model defaults. Keys are given names declared in the model's given: block.")
236993
237840
  };
236994
237841
  function registerExecuteQueryTool(mcpServer, environmentStore) {
236995
237842
  mcpServer.tool("malloy_executeQuery", "Executes a Malloy query (either ad-hoc or a named query/view defined in a model) against the specified model and returns the results as JSON.", executeQueryShape, async (params) => {
@@ -237000,7 +237847,8 @@ function registerExecuteQueryTool(mcpServer, environmentStore) {
237000
237847
  query,
237001
237848
  sourceName,
237002
237849
  queryName,
237003
- filterParams
237850
+ filterParams,
237851
+ givens
237004
237852
  } = params;
237005
237853
  logger.info("[MCP Tool executeQuery] Received params:", { params });
237006
237854
  const hasAdhocQuery = !!query;
@@ -237036,7 +237884,7 @@ function registerExecuteQueryTool(mcpServer, environmentStore) {
237036
237884
  logger.info(`[MCP Tool executeQuery] Model found. Proceeding to execute query.`);
237037
237885
  try {
237038
237886
  if (query) {
237039
- const { result } = await model.getQueryResults(undefined, undefined, query, filterParams);
237887
+ const { result } = await model.getQueryResults(undefined, undefined, query, filterParams, undefined, givens);
237040
237888
  const { validateRenderTags: validateRenderTags2 } = await Promise.resolve().then(() => __toESM(require_dist10(), 1));
237041
237889
  const renderLogs = validateRenderTags2(result);
237042
237890
  const baseUriComponents = {
@@ -237072,7 +237920,7 @@ ${JSON.stringify(renderLogs, null, 2)}`
237072
237920
  }
237073
237921
  return { isError: false, content };
237074
237922
  } else if (queryName) {
237075
- const { result } = await model.getQueryResults(sourceName, queryName, undefined, filterParams);
237923
+ const { result } = await model.getQueryResults(sourceName, queryName, undefined, filterParams, undefined, givens);
237076
237924
  const { validateRenderTags: validateRenderTags2 } = await Promise.resolve().then(() => __toESM(require_dist10(), 1));
237077
237925
  const renderLogs = validateRenderTags2(result);
237078
237926
  const baseUriComponents = {
@@ -237171,6 +238019,8 @@ function initializeMcpServer(environmentStore) {
237171
238019
  }
237172
238020
 
237173
238021
  // src/server-old.ts
238022
+ init_errors();
238023
+ init_logger();
237174
238024
  var import_body_parser = __toESM(require_body_parser(), 1);
237175
238025
  var LEGACY_API_PREFIX = "/api/v0";
237176
238026
  function remapMaterializationResponse(mat) {
@@ -237746,6 +238596,8 @@ function registerLegacyRoutes(app, controllers) {
237746
238596
  }
237747
238597
 
237748
238598
  // src/service/manifest_service.ts
238599
+ init_logger();
238600
+
237749
238601
  class ManifestService {
237750
238602
  environmentStore;
237751
238603
  constructor(environmentStore) {
@@ -237766,8 +238618,8 @@ class ManifestService {
237766
238618
  async reloadManifest(environmentId, packageName, environmentName) {
237767
238619
  const manifest = await this.getManifest(environmentId, packageName);
237768
238620
  const environment = await this.environmentStore.getEnvironment(environmentName, false);
237769
- const pkg = await environment.getPackage(packageName, false);
237770
- await pkg.reloadAllModels(manifest.entries);
238621
+ await environment.getPackage(packageName, false);
238622
+ await environment.reloadAllModelsForPackage(packageName, manifest.entries);
237771
238623
  logger.info("Reloaded manifest and recompiled models", {
237772
238624
  environmentId,
237773
238625
  packageName,
@@ -237781,9 +238633,12 @@ class ManifestService {
237781
238633
  }
237782
238634
 
237783
238635
  // src/service/materialization_service.ts
238636
+ init_errors();
238637
+ init_logger();
237784
238638
  import { Manifest } from "@malloydata/malloy";
237785
238639
 
237786
238640
  // src/service/materialized_table_gc.ts
238641
+ init_logger();
237787
238642
  import {
237788
238643
  DatabricksDialect,
237789
238644
  DuckDBDialect,
@@ -238088,8 +238943,8 @@ class MaterializationService {
238088
238943
  if (metadata.autoLoadManifest) {
238089
238944
  const updatedManifest = await this.manifestService.getManifest(environmentId, packageName);
238090
238945
  const environment = await this.environmentStore.getEnvironment(environmentName, false);
238091
- const pkg = await environment.getPackage(packageName, false);
238092
- await pkg.reloadAllModels(updatedManifest.entries);
238946
+ await environment.getPackage(packageName, false);
238947
+ await environment.reloadAllModelsForPackage(packageName, updatedManifest.entries);
238093
238948
  }
238094
238949
  await this.transitionExecution(executionId, "SUCCESS", {
238095
238950
  completedAt: new Date,
@@ -238179,7 +239034,7 @@ class MaterializationService {
238179
239034
  manifest.loadText(JSON.stringify(existingManifest));
238180
239035
  const existingEntries = await this.manifestService.listEntries(environmentId, packageName);
238181
239036
  const knownMaterializedTables = new Set(existingEntries.map((e) => manifestTableKey(e.connectionName, e.tableName)));
238182
- const { graphs, sources, connectionDigests, connections } = await this.compilePackageBuildPlan(pkg, signal);
239037
+ const { graphs, sources, connectionDigests, connections } = await environment.withPackageLock(packageName, () => this.compilePackageBuildPlan(pkg, signal));
238183
239038
  if (graphs.length === 0) {
238184
239039
  logger.info("No persist sources to build");
238185
239040
  return { sourcesBuilt: 0, sourcesSkipped: 0 };
@@ -238384,6 +239239,108 @@ class MaterializationService {
238384
239239
  }
238385
239240
  }
238386
239241
 
239242
+ // src/service/package_memory_governor.ts
239243
+ init_logger();
239244
+ var import_api4 = __toESM(require_src(), 1);
239245
+ var DEFAULT_RSS_SAMPLER = () => process.memoryUsage().rss;
239246
+
239247
+ class PackageMemoryGovernor {
239248
+ config;
239249
+ rssSampler;
239250
+ highWaterBytes;
239251
+ lowWaterBytes;
239252
+ timer = null;
239253
+ backpressured = false;
239254
+ lastSampledRss = 0;
239255
+ lastSampledAt = null;
239256
+ backpressureActivationsCounter;
239257
+ constructor(config, rssSampler) {
239258
+ this.config = config;
239259
+ this.rssSampler = rssSampler ?? DEFAULT_RSS_SAMPLER;
239260
+ this.highWaterBytes = Math.floor(config.maxMemoryBytes * config.highWaterFraction);
239261
+ this.lowWaterBytes = Math.floor(config.maxMemoryBytes * config.lowWaterFraction);
239262
+ const meter2 = import_api4.metrics.getMeter("publisher");
239263
+ meter2.createObservableGauge("publisher_process_rss_bytes", {
239264
+ description: "Current resident set size of the publisher process in bytes",
239265
+ unit: "By"
239266
+ }).addCallback((observation) => {
239267
+ observation.observe(this.rssSampler());
239268
+ });
239269
+ meter2.createObservableGauge("publisher_memory_backpressure_active", {
239270
+ description: "1 when the publisher is rejecting new package loads to stay under PUBLISHER_MAX_MEMORY_BYTES; 0 otherwise"
239271
+ }).addCallback((observation) => {
239272
+ observation.observe(this.backpressured ? 1 : 0);
239273
+ });
239274
+ this.backpressureActivationsCounter = meter2.createCounter("publisher_memory_backpressure_activations_total", {
239275
+ description: "Number of times the memory governor has activated back-pressure"
239276
+ });
239277
+ meter2.createObservableGauge("publisher_memory_max_bytes", {
239278
+ description: "Configured PUBLISHER_MAX_MEMORY_BYTES",
239279
+ unit: "By"
239280
+ }).addCallback((observation) => observation.observe(this.config.maxMemoryBytes));
239281
+ meter2.createObservableGauge("publisher_memory_high_water_bytes", {
239282
+ description: "RSS threshold at which back-pressure activates",
239283
+ unit: "By"
239284
+ }).addCallback((observation) => observation.observe(this.highWaterBytes));
239285
+ meter2.createObservableGauge("publisher_memory_low_water_bytes", {
239286
+ description: "RSS threshold at which back-pressure clears",
239287
+ unit: "By"
239288
+ }).addCallback((observation) => observation.observe(this.lowWaterBytes));
239289
+ }
239290
+ start() {
239291
+ if (this.timer !== null)
239292
+ return;
239293
+ this.tick();
239294
+ this.timer = setInterval(() => this.tick(), this.config.checkIntervalMs);
239295
+ this.timer.unref?.();
239296
+ logger.info(`PackageMemoryGovernor started (max=${this.config.maxMemoryBytes}B, high=${this.highWaterBytes}B, low=${this.lowWaterBytes}B, interval=${this.config.checkIntervalMs}ms, backpressure=${this.config.backpressureEnabled})`);
239297
+ }
239298
+ stop() {
239299
+ if (this.timer !== null) {
239300
+ clearInterval(this.timer);
239301
+ this.timer = null;
239302
+ }
239303
+ this.backpressured = false;
239304
+ }
239305
+ tick() {
239306
+ let rss;
239307
+ try {
239308
+ rss = this.rssSampler();
239309
+ } catch (err) {
239310
+ logger.error("PackageMemoryGovernor: RSS sample failed", {
239311
+ error: err
239312
+ });
239313
+ return;
239314
+ }
239315
+ this.lastSampledRss = rss;
239316
+ this.lastSampledAt = Date.now();
239317
+ if (!this.config.backpressureEnabled) {
239318
+ return;
239319
+ }
239320
+ if (rss >= this.highWaterBytes && !this.backpressured) {
239321
+ this.backpressured = true;
239322
+ this.backpressureActivationsCounter.add(1);
239323
+ logger.warn(`PackageMemoryGovernor: activating back-pressure (rss=${rss}B >= high=${this.highWaterBytes}B). New package loads will be rejected with HTTP 503 until rss <= ${this.lowWaterBytes}B.`);
239324
+ } else if (rss <= this.lowWaterBytes && this.backpressured) {
239325
+ this.backpressured = false;
239326
+ logger.info(`PackageMemoryGovernor: clearing back-pressure (rss=${rss}B <= low=${this.lowWaterBytes}B).`);
239327
+ }
239328
+ }
239329
+ isBackpressured() {
239330
+ return this.backpressured;
239331
+ }
239332
+ getStatus() {
239333
+ return {
239334
+ rssBytes: this.lastSampledRss,
239335
+ maxMemoryBytes: this.config.maxMemoryBytes,
239336
+ highWaterBytes: this.highWaterBytes,
239337
+ lowWaterBytes: this.lowWaterBytes,
239338
+ backpressured: this.backpressured,
239339
+ lastSampledAt: this.lastSampledAt
239340
+ };
239341
+ }
239342
+ }
239343
+
238387
239344
  // src/server.ts
238388
239345
  function normalizeQueryArray(value) {
238389
239346
  if (value === undefined || value === null)
@@ -238452,7 +239409,7 @@ var MCP_PORT = Number(process.env.MCP_PORT || 4040);
238452
239409
  var MCP_ENDPOINT = "/mcp";
238453
239410
  var SHUTDOWN_DRAIN_DURATION_SECONDS = Number(process.env.SHUTDOWN_DRAIN_DURATION_SECONDS || 0);
238454
239411
  var SHUTDOWN_GRACEFUL_CLOSE_TIMEOUT_SECONDS = Number(process.env.SHUTDOWN_GRACEFUL_CLOSE_TIMEOUT_SECONDS || 0);
238455
- var __filename_esm = fileURLToPath3(import.meta.url);
239412
+ var __filename_esm = fileURLToPath4(import.meta.url);
238456
239413
  var ROOT = path12.join(path12.dirname(__filename_esm), "app");
238457
239414
  var SERVER_ROOT = path12.resolve(process.cwd(), process.env.SERVER_ROOT || ".");
238458
239415
  var API_PREFIX2 = "/api/v0";
@@ -238465,6 +239422,10 @@ var manifestService = new ManifestService(environmentStore);
238465
239422
  var watchModeController = new WatchModeController(environmentStore);
238466
239423
  var connectionController = new ConnectionController(environmentStore);
238467
239424
  var modelController = new ModelController(environmentStore);
239425
+ var memoryGovernorConfig = getMemoryGovernorConfig();
239426
+ var memoryGovernor = memoryGovernorConfig ? new PackageMemoryGovernor(memoryGovernorConfig) : null;
239427
+ memoryGovernor?.start();
239428
+ environmentStore.setMemoryGovernor(memoryGovernor);
238468
239429
  var packageController = new PackageController(environmentStore, manifestService);
238469
239430
  var databaseController = new DatabaseController(environmentStore);
238470
239431
  var queryController = new QueryController(environmentStore);
@@ -238983,7 +239944,18 @@ app.get(`${API_PREFIX2}/environments/:environmentName/packages/:packageName/note
238983
239944
  }
238984
239945
  }
238985
239946
  const bypassFilters = req.query.bypass_filters === "true" ? true : undefined;
238986
- res.status(200).json(await modelController.executeNotebookCell(req.params.environmentName, req.params.packageName, notebookPath, cellIndex, filterParams, bypassFilters));
239947
+ let givens;
239948
+ if (typeof req.query.givens === "string") {
239949
+ try {
239950
+ givens = JSON.parse(req.query.givens);
239951
+ } catch {
239952
+ res.status(400).json({
239953
+ error: "Invalid givens: must be valid JSON"
239954
+ });
239955
+ return;
239956
+ }
239957
+ }
239958
+ res.status(200).json(await modelController.executeNotebookCell(req.params.environmentName, req.params.packageName, notebookPath, cellIndex, filterParams, bypassFilters, givens));
238987
239959
  } catch (error) {
238988
239960
  logger.error(error);
238989
239961
  const { json, status } = internalErrorToHttpError(error);
@@ -239011,7 +239983,7 @@ app.post(`${API_PREFIX2}/environments/:environmentName/packages/:packageName/mod
239011
239983
  }
239012
239984
  try {
239013
239985
  const modelPath = req.params["0"];
239014
- res.status(200).json(await queryController.getQuery(req.params.environmentName, req.params.packageName, modelPath, req.body.sourceName, req.body.queryName, req.body.query, req.body.compactJson === true, req.body.filterParams ?? req.body.sourceFilters, req.body.bypassFilters === true ? true : undefined));
239986
+ res.status(200).json(await queryController.getQuery(req.params.environmentName, req.params.packageName, modelPath, req.body.sourceName, req.body.queryName, req.body.query, req.body.compactJson === true, req.body.filterParams ?? req.body.sourceFilters, req.body.bypassFilters === true ? true : undefined, req.body.givens));
239015
239987
  } catch (error) {
239016
239988
  logger.error(error);
239017
239989
  const { json, status } = internalErrorToHttpError(error);
@@ -239033,7 +240005,7 @@ app.get(`${API_PREFIX2}/environments/:environmentName/packages/:packageName/data
239033
240005
  });
239034
240006
  app.post(`${API_PREFIX2}/environments/:environmentName/packages/:packageName/models/:modelName/compile`, async (req, res) => {
239035
240007
  try {
239036
- const result = await compileController.compile(req.params.environmentName, req.params.packageName, req.params.modelName, req.body.source, req.body.includeSql === true);
240008
+ const result = await compileController.compile(req.params.environmentName, req.params.packageName, req.params.modelName, req.body.source, req.body.includeSql === true, req.body.givens);
239037
240009
  res.status(200).json(result);
239038
240010
  } catch (error) {
239039
240011
  logger.error("Compilation error", { error });