@holistics/cli-core 2.5.6 → 2.5.8

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 (2) hide show
  1. package/dist/commands.js +349 -222
  2. package/package.json +1 -1
package/dist/commands.js CHANGED
@@ -24022,7 +24022,7 @@ var require_dist4 = __commonJS((exports2) => {
24022
24022
  exports2.default = deferred;
24023
24023
  });
24024
24024
  // package.json
24025
- var version = "2.5.6";
24025
+ var version = "2.5.8";
24026
24026
 
24027
24027
  // ../../node_modules/.pnpm/commander@15.0.0/node_modules/commander/lib/error.js
24028
24028
  class CommanderError extends Error {
@@ -105272,7 +105272,7 @@ var TypeClass = /* @__PURE__ */ function(e9) {
105272
105272
  return e9.SCALAR = "scalar", e9.FIELD = "field", e9.ROW = "row", e9.TABLE = "table", e9.RELATIONSHIP = "relationship", e9.ARRAY = "array", e9.GROUPING_SET = "grouping_set", e9.FUNCTION = "function", e9.UNION = "union", e9.TYPE_PARAMETER = "type_parameter", e9.TYPE_CLASS = "type_class", e9.USER_ATTRIBUTE = "user_attribute", e9.MODULE = "module", e9.ERROR_ANY = "error_any", e9.NULL = "null", e9;
105273
105273
  }({});
105274
105274
  var ErrorCode = /* @__PURE__ */ function(e9) {
105275
- return e9[e9.UNEXPECTED_ERROR = 0] = "UNEXPECTED_ERROR", e9[e9.SYNTAX_ERROR = 1] = "SYNTAX_ERROR", e9[e9.INVALID_EXPRESSION_0 = 100] = "INVALID_EXPRESSION_0", e9[e9.RELATIONSHIP_NOT_FOUND_0 = 101] = "RELATIONSHIP_NOT_FOUND_0", e9[e9.MODEL_0_NOT_FOUND = 102] = "MODEL_0_NOT_FOUND", e9[e9.FIELD_0_NOT_FOUND_IN_MODEL_1 = 103] = "FIELD_0_NOT_FOUND_IN_MODEL_1", e9[e9.FANOUT_ON_0_FROM_1 = 104] = "FANOUT_ON_0_FROM_1", e9[e9.MODEL_IN_AQL_FIELD_NOT_FOUND = 105] = "MODEL_IN_AQL_FIELD_NOT_FOUND", e9[e9.RELATIONSHIP_PATH_NOT_FOUND_FROM_0_TO_1 = 106] = "RELATIONSHIP_PATH_NOT_FOUND_FROM_0_TO_1", e9[e9.INVALID_ARITY_EXPECT_0_FOR_FUNCTION_1_GOT_2 = 200] = "INVALID_ARITY_EXPECT_0_FOR_FUNCTION_1_GOT_2", e9[e9.INVALID_ARGUMENT_TYPE = 201] = "INVALID_ARGUMENT_TYPE", e9[e9.UNKNOWN_IDENTIFIER_0 = 202] = "UNKNOWN_IDENTIFIER_0", e9[e9.UNSUPPORTED_OPERATOR_0_FOR_TYPE_1 = 203] = "UNSUPPORTED_OPERATOR_0_FOR_TYPE_1", e9[e9.EXPECTED_0_FOUND_1 = 204] = "EXPECTED_0_FOUND_1", e9[e9.NAMED_EXPRESSION_EXPECT_A_FIELD_OR_SCALAR_VALUE_FOUND_0 = 205] = "NAMED_EXPRESSION_EXPECT_A_FIELD_OR_SCALAR_VALUE_FOUND_0", e9[e9.EXPECTED_SCALAR_LIKE_TYPE_FOUND_0 = 206] = "EXPECTED_SCALAR_LIKE_TYPE_FOUND_0", e9[e9.NO_MATCHING_SIGNATURE_FOR_FUNCTION_0 = 207] = "NO_MATCHING_SIGNATURE_FOR_FUNCTION_0", e9[e9.INVALID_MEASURE_DEFINITION_FOR_FIELD_0_IN_MODEL_1 = 208] = "INVALID_MEASURE_DEFINITION_FOR_FIELD_0_IN_MODEL_1", e9[e9.DIMENSIONALIZE_NOT_ALLOWED_DUE_TO_0 = 209] = "DIMENSIONALIZE_NOT_ALLOWED_DUE_TO_0", e9[e9.CANNOT_REFERENCE_AQL_FIELD_0_FROM_SQL = 210] = "CANNOT_REFERENCE_AQL_FIELD_0_FROM_SQL", e9[e9.RIGHT_SIDE_OF_PIPE_MUST_BE_A_FUNCTION = 211] = "RIGHT_SIDE_OF_PIPE_MUST_BE_A_FUNCTION", e9[e9.INVALID_METRIC_DEFINITION_0_IN_DATASET_1 = 212] = "INVALID_METRIC_DEFINITION_0_IN_DATASET_1", e9[e9.MEMBER_0_NOT_FOUND_IN_MODULE_1 = 213] = "MEMBER_0_NOT_FOUND_IN_MODULE_1", e9[e9.INVALID_BIZ_CAL_FUNCTION_0 = 214] = "INVALID_BIZ_CAL_FUNCTION_0", e9[e9.USER_ATTRIBUTE_0_NOT_FOUND = 215] = "USER_ATTRIBUTE_0_NOT_FOUND", e9[e9.INVALID_USAGE_OF_USER_ATTRIBUTE_0_MUTIPLE_VALUES = 216] = "INVALID_USAGE_OF_USER_ATTRIBUTE_0_MUTIPLE_VALUES", e9[e9.TABLE_LITERAL_ROWS_MUST_HAVE_SAME_NUMBER_OF_COLUMNS = 217] = "TABLE_LITERAL_ROWS_MUST_HAVE_SAME_NUMBER_OF_COLUMNS", e9[e9.INVALID_ROW_LEVEL_PERMISSION = 218] = "INVALID_ROW_LEVEL_PERMISSION", e9[e9.PERMISSION_RULE_VIOLATION_ERROR = 219] = "PERMISSION_RULE_VIOLATION_ERROR", e9[e9.UNSUPPORTED_BEHAVIOR_0 = 220] = "UNSUPPORTED_BEHAVIOR_0", e9[e9.POTENTIAL_DB_RUNTIME_ERROR_0 = 221] = "POTENTIAL_DB_RUNTIME_ERROR_0", e9[e9.AMBIGUOUS_RELATIONSHIP_0 = 222] = "AMBIGUOUS_RELATIONSHIP_0", e9[e9.QUERY_PARAM_UNSUPPORTED_OPERATOR = 223] = "QUERY_PARAM_UNSUPPORTED_OPERATOR", e9[e9.QUERY_PARAM_INVALID_PARAM_INPUT = 224] = "QUERY_PARAM_INVALID_PARAM_INPUT", e9[e9.ROW_MUST_CONTAIN_DIMENSIONS_ONLY_0 = 225] = "ROW_MUST_CONTAIN_DIMENSIONS_ONLY_0", e9[e9.ROW_COLUMNS_MUST_BE_SUBSET_OF_TABLE_COLUMNS = 226] = "ROW_COLUMNS_MUST_BE_SUBSET_OF_TABLE_COLUMNS", e9[e9.CANNOT_MATCH_ROW_WITH_LITERAL_TABLE_0 = 227] = "CANNOT_MATCH_ROW_WITH_LITERAL_TABLE_0", e9[e9.INVALID_FIELD_DECLARATION = 228] = "INVALID_FIELD_DECLARATION", e9[e9.CANNOT_REDECLARE_FIELD = 229] = "CANNOT_REDECLARE_FIELD", e9[e9.ADHOC_FIELD_UNSUPPORTED_FIELD_TYPE = 230] = "ADHOC_FIELD_UNSUPPORTED_FIELD_TYPE", e9[e9.CANNOT_RUN_WINDOW_FUNCTION_IN_THIS_CONTEXT_0 = 231] = "CANNOT_RUN_WINDOW_FUNCTION_IN_THIS_CONTEXT_0", e9[e9.INVALID_WINDOW_FRAME_0 = 232] = "INVALID_WINDOW_FRAME_0", e9[e9.CYLIC_FIELD_DEPENDENCY_DETECTED_0 = 233] = "CYLIC_FIELD_DEPENDENCY_DETECTED_0", e9[e9.INVALID_SHORTHAND_AGGREGATION_0 = 234] = "INVALID_SHORTHAND_AGGREGATION_0", e9[e9.UNSUPPORTED_DATE_UNIT_0 = 235] = "UNSUPPORTED_DATE_UNIT_0", e9[e9.INVALID_CONDITIONAL_EXPRESSION_IN_0 = 236] = "INVALID_CONDITIONAL_EXPRESSION_IN_0", e9[e9.UNKNOWN_FUNCTION_0 = 237] = "UNKNOWN_FUNCTION_0", e9[e9.CANNOT_MATCH_ROW_WITH_TABLE_0 = 238] = "CANNOT_MATCH_ROW_WITH_TABLE_0", e9[e9.DUPLICATE_FIELD_NAME_0 = 239] = "DUPLICATE_FIELD_NAME_0", e9[e9.FUNCTION_0_EXPECT_1_GOT_2 = 240] = "FUNCTION_0_EXPECT_1_GOT_2", e9[e9.NESTED_WINDOW_FUNCTION = 241] = "NESTED_WINDOW_FUNCTION", e9[e9.FIELD_0_NOT_FOUND_IN_SELECTED_FIELDS = 242] = "FIELD_0_NOT_FOUND_IN_SELECTED_FIELDS", e9[e9.REFERENCE_FIELD_0_NOT_GROUP_NOR_AGGREGATED = 243] = "REFERENCE_FIELD_0_NOT_GROUP_NOR_AGGREGATED", e9[e9.INVALID_TABLE_CONDITION_0 = 244] = "INVALID_TABLE_CONDITION_0", e9[e9.INVALID_DATETIME_LITERAL_0 = 245] = "INVALID_DATETIME_LITERAL_0", e9[e9.NO_PRIMARY_KEY_FOUND_FOR_MODEL_0_REASON_1 = 246] = "NO_PRIMARY_KEY_FOUND_FOR_MODEL_0_REASON_1", e9[e9.RECURSIVE_AQL_FUNCTION_0_CHAIN_1 = 247] = "RECURSIVE_AQL_FUNCTION_0_CHAIN_1", e9[e9.INVALID_RETURN_TYPE_FOR_FUNCTION_0_EXPECTED_1_GOT_2 = 248] = "INVALID_RETURN_TYPE_FOR_FUNCTION_0_EXPECTED_1_GOT_2", e9[e9.INVALID_REF_ARGUMENT_FOR_PARAM_0_EXPECTED_1_GOT_2 = 249] = "INVALID_REF_ARGUMENT_FOR_PARAM_0_EXPECTED_1_GOT_2", e9[e9.AQL_0_1_SHADOWS_BUILTIN = 250] = "AQL_0_1_SHADOWS_BUILTIN", e9[e9.RELATIONSHIP_FILTER_ON_0_READS_1 = 251] = "RELATIONSHIP_FILTER_ON_0_READS_1", e9[e9.RELATIONSHIP_MATCH_READS_0 = 252] = "RELATIONSHIP_MATCH_READS_0", e9[e9.RELATIONSHIP_MATCH_MISSES_0 = 253] = "RELATIONSHIP_MATCH_MISSES_0", e9[e9.AQL_NAME_0_DECLARED_AS_1_AND_2_IN_3 = 254] = "AQL_NAME_0_DECLARED_AS_1_AND_2_IN_3", e9[e9.OPERATOR_0_ON_PARAM_1 = 255] = "OPERATOR_0_ON_PARAM_1", e9[e9.SHOULD_FOLLOW_GROUP_WITH_SELECT_OR_FILTER = 300] = "SHOULD_FOLLOW_GROUP_WITH_SELECT_OR_FILTER", e9;
105275
+ return e9[e9.UNEXPECTED_ERROR = 0] = "UNEXPECTED_ERROR", e9[e9.SYNTAX_ERROR = 1] = "SYNTAX_ERROR", e9[e9.INVALID_EXPRESSION_0 = 100] = "INVALID_EXPRESSION_0", e9[e9.RELATIONSHIP_NOT_FOUND_0 = 101] = "RELATIONSHIP_NOT_FOUND_0", e9[e9.MODEL_0_NOT_FOUND = 102] = "MODEL_0_NOT_FOUND", e9[e9.FIELD_0_NOT_FOUND_IN_MODEL_1 = 103] = "FIELD_0_NOT_FOUND_IN_MODEL_1", e9[e9.FANOUT_ON_0_FROM_1 = 104] = "FANOUT_ON_0_FROM_1", e9[e9.MODEL_IN_AQL_FIELD_NOT_FOUND = 105] = "MODEL_IN_AQL_FIELD_NOT_FOUND", e9[e9.RELATIONSHIP_PATH_NOT_FOUND_FROM_0_TO_1 = 106] = "RELATIONSHIP_PATH_NOT_FOUND_FROM_0_TO_1", e9[e9.INVALID_ARITY_EXPECT_0_FOR_FUNCTION_1_GOT_2 = 200] = "INVALID_ARITY_EXPECT_0_FOR_FUNCTION_1_GOT_2", e9[e9.INVALID_ARGUMENT_TYPE = 201] = "INVALID_ARGUMENT_TYPE", e9[e9.UNKNOWN_IDENTIFIER_0 = 202] = "UNKNOWN_IDENTIFIER_0", e9[e9.UNSUPPORTED_OPERATOR_0_FOR_TYPE_1 = 203] = "UNSUPPORTED_OPERATOR_0_FOR_TYPE_1", e9[e9.EXPECTED_0_FOUND_1 = 204] = "EXPECTED_0_FOUND_1", e9[e9.NAMED_EXPRESSION_EXPECT_A_FIELD_OR_SCALAR_VALUE_FOUND_0 = 205] = "NAMED_EXPRESSION_EXPECT_A_FIELD_OR_SCALAR_VALUE_FOUND_0", e9[e9.EXPECTED_SCALAR_LIKE_TYPE_FOUND_0 = 206] = "EXPECTED_SCALAR_LIKE_TYPE_FOUND_0", e9[e9.NO_MATCHING_SIGNATURE_FOR_FUNCTION_0 = 207] = "NO_MATCHING_SIGNATURE_FOR_FUNCTION_0", e9[e9.INVALID_MEASURE_DEFINITION_FOR_FIELD_0_IN_MODEL_1 = 208] = "INVALID_MEASURE_DEFINITION_FOR_FIELD_0_IN_MODEL_1", e9[e9.DIMENSIONALIZE_NOT_ALLOWED_DUE_TO_0 = 209] = "DIMENSIONALIZE_NOT_ALLOWED_DUE_TO_0", e9[e9.CANNOT_REFERENCE_AQL_FIELD_0_FROM_SQL = 210] = "CANNOT_REFERENCE_AQL_FIELD_0_FROM_SQL", e9[e9.RIGHT_SIDE_OF_PIPE_MUST_BE_A_FUNCTION = 211] = "RIGHT_SIDE_OF_PIPE_MUST_BE_A_FUNCTION", e9[e9.INVALID_METRIC_DEFINITION_0_IN_DATASET_1 = 212] = "INVALID_METRIC_DEFINITION_0_IN_DATASET_1", e9[e9.MEMBER_0_NOT_FOUND_IN_MODULE_1 = 213] = "MEMBER_0_NOT_FOUND_IN_MODULE_1", e9[e9.INVALID_BIZ_CAL_FUNCTION_0 = 214] = "INVALID_BIZ_CAL_FUNCTION_0", e9[e9.USER_ATTRIBUTE_0_NOT_FOUND = 215] = "USER_ATTRIBUTE_0_NOT_FOUND", e9[e9.INVALID_USAGE_OF_USER_ATTRIBUTE_0_MUTIPLE_VALUES = 216] = "INVALID_USAGE_OF_USER_ATTRIBUTE_0_MUTIPLE_VALUES", e9[e9.TABLE_LITERAL_ROWS_MUST_HAVE_SAME_NUMBER_OF_COLUMNS = 217] = "TABLE_LITERAL_ROWS_MUST_HAVE_SAME_NUMBER_OF_COLUMNS", e9[e9.INVALID_ROW_LEVEL_PERMISSION = 218] = "INVALID_ROW_LEVEL_PERMISSION", e9[e9.PERMISSION_RULE_VIOLATION_ERROR = 219] = "PERMISSION_RULE_VIOLATION_ERROR", e9[e9.UNSUPPORTED_BEHAVIOR_0 = 220] = "UNSUPPORTED_BEHAVIOR_0", e9[e9.POTENTIAL_DB_RUNTIME_ERROR_0 = 221] = "POTENTIAL_DB_RUNTIME_ERROR_0", e9[e9.AMBIGUOUS_RELATIONSHIP_0 = 222] = "AMBIGUOUS_RELATIONSHIP_0", e9[e9.QUERY_PARAM_UNSUPPORTED_OPERATOR = 223] = "QUERY_PARAM_UNSUPPORTED_OPERATOR", e9[e9.QUERY_PARAM_INVALID_PARAM_INPUT = 224] = "QUERY_PARAM_INVALID_PARAM_INPUT", e9[e9.ROW_MUST_CONTAIN_DIMENSIONS_ONLY_0 = 225] = "ROW_MUST_CONTAIN_DIMENSIONS_ONLY_0", e9[e9.ROW_COLUMNS_MUST_BE_SUBSET_OF_TABLE_COLUMNS = 226] = "ROW_COLUMNS_MUST_BE_SUBSET_OF_TABLE_COLUMNS", e9[e9.CANNOT_MATCH_ROW_WITH_LITERAL_TABLE_0 = 227] = "CANNOT_MATCH_ROW_WITH_LITERAL_TABLE_0", e9[e9.INVALID_FIELD_DECLARATION = 228] = "INVALID_FIELD_DECLARATION", e9[e9.CANNOT_REDECLARE_FIELD = 229] = "CANNOT_REDECLARE_FIELD", e9[e9.ADHOC_FIELD_UNSUPPORTED_FIELD_TYPE = 230] = "ADHOC_FIELD_UNSUPPORTED_FIELD_TYPE", e9[e9.CANNOT_RUN_WINDOW_FUNCTION_IN_THIS_CONTEXT_0 = 231] = "CANNOT_RUN_WINDOW_FUNCTION_IN_THIS_CONTEXT_0", e9[e9.INVALID_WINDOW_FRAME_0 = 232] = "INVALID_WINDOW_FRAME_0", e9[e9.CYLIC_FIELD_DEPENDENCY_DETECTED_0 = 233] = "CYLIC_FIELD_DEPENDENCY_DETECTED_0", e9[e9.INVALID_SHORTHAND_AGGREGATION_0 = 234] = "INVALID_SHORTHAND_AGGREGATION_0", e9[e9.UNSUPPORTED_DATE_UNIT_0 = 235] = "UNSUPPORTED_DATE_UNIT_0", e9[e9.INVALID_CONDITIONAL_EXPRESSION_IN_0 = 236] = "INVALID_CONDITIONAL_EXPRESSION_IN_0", e9[e9.UNKNOWN_FUNCTION_0 = 237] = "UNKNOWN_FUNCTION_0", e9[e9.CANNOT_MATCH_ROW_WITH_TABLE_0 = 238] = "CANNOT_MATCH_ROW_WITH_TABLE_0", e9[e9.DUPLICATE_FIELD_NAME_0 = 239] = "DUPLICATE_FIELD_NAME_0", e9[e9.FUNCTION_0_EXPECT_1_GOT_2 = 240] = "FUNCTION_0_EXPECT_1_GOT_2", e9[e9.NESTED_WINDOW_FUNCTION = 241] = "NESTED_WINDOW_FUNCTION", e9[e9.FIELD_0_NOT_FOUND_IN_SELECTED_FIELDS = 242] = "FIELD_0_NOT_FOUND_IN_SELECTED_FIELDS", e9[e9.REFERENCE_FIELD_0_NOT_GROUP_NOR_AGGREGATED = 243] = "REFERENCE_FIELD_0_NOT_GROUP_NOR_AGGREGATED", e9[e9.INVALID_TABLE_CONDITION_0 = 244] = "INVALID_TABLE_CONDITION_0", e9[e9.INVALID_DATETIME_LITERAL_0 = 245] = "INVALID_DATETIME_LITERAL_0", e9[e9.NO_PRIMARY_KEY_FOUND_FOR_MODEL_0_REASON_1 = 246] = "NO_PRIMARY_KEY_FOUND_FOR_MODEL_0_REASON_1", e9[e9.RECURSIVE_AQL_FUNCTION_0_CHAIN_1 = 247] = "RECURSIVE_AQL_FUNCTION_0_CHAIN_1", e9[e9.INVALID_RETURN_TYPE_FOR_FUNCTION_0_EXPECTED_1_GOT_2 = 248] = "INVALID_RETURN_TYPE_FOR_FUNCTION_0_EXPECTED_1_GOT_2", e9[e9.INVALID_REF_ARGUMENT_FOR_PARAM_0_EXPECTED_1_GOT_2 = 249] = "INVALID_REF_ARGUMENT_FOR_PARAM_0_EXPECTED_1_GOT_2", e9[e9.AQL_0_1_SHADOWS_BUILTIN = 250] = "AQL_0_1_SHADOWS_BUILTIN", e9[e9.RELATIONSHIP_FILTER_ON_0_READS_1 = 251] = "RELATIONSHIP_FILTER_ON_0_READS_1", e9[e9.RELATIONSHIP_MATCH_READS_0 = 252] = "RELATIONSHIP_MATCH_READS_0", e9[e9.RELATIONSHIP_MATCH_MISSES_0 = 253] = "RELATIONSHIP_MATCH_MISSES_0", e9[e9.AQL_NAME_0_DECLARED_AS_1_AND_2_IN_3 = 254] = "AQL_NAME_0_DECLARED_AS_1_AND_2_IN_3", e9[e9.OPERATOR_0_ON_PARAM_1 = 255] = "OPERATOR_0_ON_PARAM_1", e9[e9.SQL_PASSTHROUGH_FUNCTION_0_NOT_ALLOWED = 256] = "SQL_PASSTHROUGH_FUNCTION_0_NOT_ALLOWED", e9[e9.SHOULD_FOLLOW_GROUP_WITH_SELECT_OR_FILTER = 300] = "SHOULD_FOLLOW_GROUP_WITH_SELECT_OR_FILTER", e9;
105276
105276
  }({});
105277
105277
  var isFieldTrace = (e9) => e9.type !== "udf";
105278
105278
  var isUdfTrace = (e9) => e9.type === "udf";
@@ -108074,6 +108074,7 @@ var errorMessages = {
108074
108074
  [ErrorCode.MEMBER_0_NOT_FOUND_IN_MODULE_1]: "Member `{0}` not found in module `{1}`.",
108075
108075
  [ErrorCode.INVALID_BIZ_CAL_FUNCTION_0]: "The function `{0}` is not part of the business calculation language. Please check the documentation for the list of supported functions. If you're trying to use a function from the AQL language, please convert this business calculation to an AQL field.",
108076
108076
  [ErrorCode.USER_ATTRIBUTE_0_NOT_FOUND]: "User attribute `{0}` not found.",
108077
+ [ErrorCode.SQL_PASSTHROUGH_FUNCTION_0_NOT_ALLOWED]: "SQL passthrough function `{0}` is not allowed in ad-hoc fields. Define the field in the dataset or model instead.",
108077
108078
  [ErrorCode.INVALID_USAGE_OF_USER_ATTRIBUTE_0_MUTIPLE_VALUES]: "Invalid usage of user attribute `{0}`. User attribute contains mutiple values and cannot be used in this context.",
108078
108079
  [ErrorCode.TABLE_LITERAL_ROWS_MUST_HAVE_SAME_NUMBER_OF_COLUMNS]: "Table literal rows must have the same number of columns.",
108079
108080
  [ErrorCode.INVALID_ROW_LEVEL_PERMISSION]: "Invalid row level permission.",
@@ -108177,6 +108178,9 @@ function cylicFieldDependencyError(e9, t) {
108177
108178
  let n = e9.map((e10) => e10.join(" -> ")).join("; ");
108178
108179
  return createError(ErrorCode.CYLIC_FIELD_DEPENDENCY_DETECTED_0, t, n);
108179
108180
  }
108181
+ function shorthandAggregationOverConstMessage(e9, t) {
108182
+ return `\`${t}\` is a const, so ${e9}(${t}) cannot infer the table to aggregate over. Aggregate the expression itself, e.g. ${e9}(<expression>), or bind a table to the const.`;
108183
+ }
108180
108184
  function shorthandAggregationWithMultipleModelsMessage(e9, t) {
108181
108185
  return `When there are multiple models involved, the table must be explicitly stated to avoid ambiguity. Valid form of the expression: ${e9}(<table>, ${t.loc?.source ? `${t.loc?.source}` : "<field expression>"}) . Please add the table to the query and try again.
108182
108186
  Correct usages:
@@ -121047,6 +121051,75 @@ function _createTypeChecker(e10, t, n, r3, i = CheckFlags.Normal) {
121047
121051
  }
121048
121052
  }
121049
121053
  var createTypeChecker = Rr3.wrapFuncWithinActiveSpan(_createTypeChecker);
121054
+ var NUMBER_AGGS = [
121055
+ "sum",
121056
+ "avg",
121057
+ "average",
121058
+ "median",
121059
+ "stdev",
121060
+ "stdevp",
121061
+ "var",
121062
+ "varp"
121063
+ ];
121064
+ var MINMAX_AGGS = ["min", "max"];
121065
+ var COUNT_AGGS = [
121066
+ "count",
121067
+ "count_distinct",
121068
+ "countd",
121069
+ "approx_count_distinct",
121070
+ "approx_countd"
121071
+ ];
121072
+ var FAN_INVARIANT_AGGS = /* @__PURE__ */ new Set([
121073
+ ...MINMAX_AGGS,
121074
+ "count_distinct",
121075
+ "countd",
121076
+ "approx_count_distinct",
121077
+ "approx_countd"
121078
+ ]);
121079
+ function isFanInvariantAgg(e10) {
121080
+ return FAN_INVARIANT_AGGS.has(e10);
121081
+ }
121082
+ var SHORTHAND_TABLE_AGGS = /* @__PURE__ */ new Set([
121083
+ ...NUMBER_AGGS,
121084
+ ...MINMAX_AGGS,
121085
+ ...COUNT_AGGS,
121086
+ "count_if"
121087
+ ]);
121088
+ var AGG_PASSTHROUGH_FUNCS = /* @__PURE__ */ new Set([
121089
+ "agg_text",
121090
+ "agg_number",
121091
+ "agg_truefalse",
121092
+ "agg_datetime",
121093
+ "agg_date"
121094
+ ]);
121095
+ function isAggPassthrough(e10) {
121096
+ return AGG_PASSTHROUGH_FUNCS.has(e10);
121097
+ }
121098
+ var SQL_PASSTHROUGH_FUNCS = /* @__PURE__ */ new Set([
121099
+ "sql_text",
121100
+ "sql_number",
121101
+ "sql_truefalse",
121102
+ "sql_datetime",
121103
+ "sql_date"
121104
+ ]);
121105
+ function invalidPassthroughFuncName(e10) {
121106
+ if (!/^[a-zA-Z0-9_.]+$/.test(e10))
121107
+ return `Invalid function name "${e10}". Function names must contain only alphanumeric characters, underscores, and dots`;
121108
+ }
121109
+ function isSqlPassthroughFunction(e10) {
121110
+ return SQL_PASSTHROUGH_FUNCS.has(e10) || AGG_PASSTHROUGH_FUNCS.has(e10);
121111
+ }
121112
+ function checkAdhocSqlPassthrough(e10) {
121113
+ let t = [];
121114
+ return e10.forEach((e11) => {
121115
+ visitAst((e12) => {
121116
+ if (!isFunctionCall(e12) || e12.name.length !== 1)
121117
+ return true;
121118
+ let [n] = e12.name;
121119
+ return isSqlPassthroughFunction(n.value) && t.push(createError(ErrorCode.SQL_PASSTHROUGH_FUNCTION_0_NOT_ALLOWED, n.loc, undefined, n.value)), true;
121120
+ }, e11);
121121
+ }), t;
121122
+ }
121050
121123
  function createFunctionType(e10, t, n, r3 = false, i = false) {
121051
121124
  return {
121052
121125
  typeClass: TypeClass.FUNCTION,
@@ -121906,61 +121979,6 @@ registerTypeRule([
121906
121979
  origin: undefined
121907
121980
  } : datetimeType;
121908
121981
  });
121909
- var NUMBER_AGGS = [
121910
- "sum",
121911
- "avg",
121912
- "average",
121913
- "median",
121914
- "stdev",
121915
- "stdevp",
121916
- "var",
121917
- "varp"
121918
- ];
121919
- var MINMAX_AGGS = ["min", "max"];
121920
- var COUNT_AGGS = [
121921
- "count",
121922
- "count_distinct",
121923
- "countd",
121924
- "approx_count_distinct",
121925
- "approx_countd"
121926
- ];
121927
- var FAN_INVARIANT_AGGS = /* @__PURE__ */ new Set([
121928
- ...MINMAX_AGGS,
121929
- "count_distinct",
121930
- "countd",
121931
- "approx_count_distinct",
121932
- "approx_countd"
121933
- ]);
121934
- function isFanInvariantAgg(e10) {
121935
- return FAN_INVARIANT_AGGS.has(e10);
121936
- }
121937
- var SHORTHAND_TABLE_AGGS = /* @__PURE__ */ new Set([
121938
- ...NUMBER_AGGS,
121939
- ...MINMAX_AGGS,
121940
- ...COUNT_AGGS,
121941
- "count_if"
121942
- ]);
121943
- var AGG_PASSTHROUGH_FUNCS = /* @__PURE__ */ new Set([
121944
- "agg_text",
121945
- "agg_number",
121946
- "agg_truefalse",
121947
- "agg_datetime",
121948
- "agg_date"
121949
- ]);
121950
- function isAggPassthrough(e10) {
121951
- return AGG_PASSTHROUGH_FUNCS.has(e10);
121952
- }
121953
- var SQL_PASSTHROUGH_FUNCS = /* @__PURE__ */ new Set([
121954
- "sql_text",
121955
- "sql_number",
121956
- "sql_truefalse",
121957
- "sql_datetime",
121958
- "sql_date"
121959
- ]);
121960
- function invalidPassthroughFuncName(e10) {
121961
- if (!/^[a-zA-Z0-9_.]+$/.test(e10))
121962
- return `Invalid function name "${e10}". Function names must contain only alphanumeric characters, underscores, and dots`;
121963
- }
121964
121982
  var CAST_TARGETS = {
121965
121983
  date: SqlType.DATE,
121966
121984
  datetime: SqlType.DATETIME,
@@ -126386,12 +126404,20 @@ function resolveShorthandAggregate(e11, t, n, r3, i, a, s3) {
126386
126404
  let c3 = n[0], l = e11.resolveExpr(c3, r3);
126387
126405
  if (isTableType(l.ty))
126388
126406
  return buildReduce(e11, t, n, r3, i, a, s3);
126407
+ if (isUserConstReference(c3, r3))
126408
+ return e11.dataset.diagnostics.push(createError(ErrorCode.INVALID_SHORTHAND_AGGREGATION_0, i, undefined, shorthandAggregationOverConstMessage(t, c3.value))), finishAggregate(e11, t, [l], errType, i, a);
126389
126409
  if (isFieldType(l.ty)) {
126390
126410
  let u = AggregationArgFold.inspect(l), f = !u.producesRelation && !u.hasQueryLevelExpression ? clearOrigin(e11, [...u.models]) : undefined;
126391
126411
  return f ? buildReduce(e11, t, [isDotExpression(c3) ? c3.left : createIdentifier(f, borrow(c3.loc), true), c3], r3, i, a, s3) : buildReduce(e11, t, n, r3, i, a, s3);
126392
126412
  }
126393
126413
  return e11.dataset.diagnostics.push(createError(ErrorCode.INVALID_SHORTHAND_AGGREGATION_0, i, undefined, shorthandAggregationWithMultipleModelsMessage(t, c3))), buildReduce(e11, t, n, r3, i, a, s3);
126394
126414
  }
126415
+ function isUserConstReference(e11, t) {
126416
+ if (!isIdentifier(e11))
126417
+ return false;
126418
+ let n = blockConstExpr(e11.value, t);
126419
+ return n?.kind === "const" && !n.synthetic;
126420
+ }
126395
126421
  function buildReduce(e11, t, n, r3, i, a, s3) {
126396
126422
  let c3 = resolveAggregateArgs(e11, n, r3), l = c3.length === 1;
126397
126423
  if (l && isTableType(c3[0].ty) && c3[0].ty.rowType.columns.length !== 1)
@@ -132610,19 +132636,24 @@ function prepareCheck(e16) {
132610
132636
  };
132611
132637
  }
132612
132638
  function checkAql(e16) {
132613
- let { dataset: t, adhocMetrics: n, adhocDimensions: r3, aql: i, aqlType: a, fieldName: s3, modelUname: c3, userAttributes: l = [], checkFlags: u = CheckFlags.SkipCheckingRelationshipKey, allowAmbiguousPaths: f = false, useV2Compiler: p3 = false } = e16, { datasetStore: m3, fieldDeclarations: S3 } = prepareCheck(e16), w3;
132639
+ let { dataset: t, adhocMetrics: n, adhocDimensions: r3, aql: i, aqlType: a, fieldName: s3, modelUname: c3, userAttributes: l = [], checkFlags: u = CheckFlags.SkipCheckingRelationshipKey, allowAmbiguousPaths: f = false, useV2Compiler: p3 = false, allowAdhocSqlPassthroughFunctions: m3 = true } = e16, { datasetStore: S3, fieldDeclarations: w3 } = prepareCheck(e16), E3;
132614
132640
  try {
132615
- w3 = parse(i);
132641
+ E3 = parse(i);
132616
132642
  } catch (e17) {
132617
132643
  return [e17];
132618
132644
  }
132619
- let E3 = a === "dimension" && c3 ? getFqn(c3) : undefined;
132645
+ if (!m3) {
132646
+ let e17 = checkAdhocSqlPassthrough([E3]);
132647
+ if (e17.length > 0)
132648
+ return e17;
132649
+ }
132650
+ let k3 = a === "dimension" && c3 ? getFqn(c3) : undefined;
132620
132651
  if (p3 && a !== "condition") {
132621
132652
  let e17 = resolve({
132622
- store: m3,
132623
- program: w3,
132624
- modelContext: E3,
132625
- adhocFields: S3,
132653
+ store: S3,
132654
+ program: E3,
132655
+ modelContext: k3,
132656
+ adhocFields: w3,
132626
132657
  userAttributes: l,
132627
132658
  checkFlags: u,
132628
132659
  recordSpanTypes: true,
@@ -132631,31 +132662,39 @@ function checkAql(e16) {
132631
132662
  });
132632
132663
  if (e17.diagnostics.length > 0)
132633
132664
  return e17.diagnostics;
132634
- let t3 = import_lodash2.last(w3.exprs);
132665
+ let t3 = import_lodash2.last(E3.exprs);
132635
132666
  return t3 === undefined ? SqlType.UNKNOWN : sqlTypeOfCheckedExpression(e17.spanTypes?.at(t3.loc));
132636
132667
  }
132637
- let k3 = createTypeChecker(m3, l, S3, [], u), N3;
132638
- if (a === "condition" && (N3 = k3.getDiagnosticsForCondition(w3)), N3 = k3.getDiagnostics(w3, E3), N3.length > 0)
132639
- return N3;
132640
- let I3 = import_lodash2.last(w3.exprs)?.id;
132641
- return I3 === undefined ? SqlType.UNKNOWN : sqlTypeOfCheckedExpression(k3.getTypeFromNodeId(I3));
132668
+ let N3 = createTypeChecker(S3, l, w3, [], u), I3;
132669
+ if (a === "condition" && (I3 = N3.getDiagnosticsForCondition(E3)), I3 = N3.getDiagnostics(E3, k3), I3.length > 0)
132670
+ return I3;
132671
+ let L3 = import_lodash2.last(E3.exprs)?.id;
132672
+ return L3 === undefined ? SqlType.UNKNOWN : sqlTypeOfCheckedExpression(N3.getTypeFromNodeId(L3));
132642
132673
  }
132643
132674
  function checkAqlCondition(e16) {
132644
- let { userAttributes: t = [], checkFlags: n = CheckFlags.SkipCheckingRelationshipKey, useV2Compiler: r3 = false } = e16, i;
132675
+ let { userAttributes: t = [], checkFlags: n = CheckFlags.SkipCheckingRelationshipKey, useV2Compiler: r3 = false, allowAdhocSqlPassthroughFunctions: i = true } = e16, a;
132645
132676
  try {
132646
- i = parse(e16.aql);
132677
+ a = parse(e16.aql);
132647
132678
  } catch (e17) {
132648
132679
  return {
132649
132680
  diagnostics: [e17],
132650
132681
  conditionType: "normal"
132651
132682
  };
132652
132683
  }
132653
- let { datasetStore: a, fieldDeclarations: s3 } = prepareCheck(e16);
132684
+ if (!i) {
132685
+ let e17 = checkAdhocSqlPassthrough([a]);
132686
+ if (e17.length > 0)
132687
+ return {
132688
+ diagnostics: e17,
132689
+ conditionType: "normal"
132690
+ };
132691
+ }
132692
+ let { datasetStore: s3, fieldDeclarations: c3 } = prepareCheck(e16);
132654
132693
  if (r3) {
132655
132694
  let e17 = resolve({
132656
- store: a,
132657
- program: i,
132658
- adhocFields: s3,
132695
+ store: s3,
132696
+ program: a,
132697
+ adhocFields: c3,
132659
132698
  userAttributes: t,
132660
132699
  checkFlags: n,
132661
132700
  typeCheckOnly: true,
@@ -132666,13 +132705,13 @@ function checkAqlCondition(e16) {
132666
132705
  conditionType: e17.conditionKind ?? "normal"
132667
132706
  };
132668
132707
  }
132669
- let c3 = createTypeChecker(a, t, s3, [], n), l = c3.getDiagnosticsForCondition(i);
132670
- return l.length > 0 ? {
132671
- diagnostics: l,
132708
+ let l = createTypeChecker(s3, t, c3, [], n), u = l.getDiagnosticsForCondition(a);
132709
+ return u.length > 0 ? {
132710
+ diagnostics: u,
132672
132711
  conditionType: "normal"
132673
132712
  } : {
132674
- diagnostics: l,
132675
- conditionType: c3.measure_conditions.getMeasureCondition(i.exprs[0]) ? "measure" : "normal"
132713
+ diagnostics: u,
132714
+ conditionType: l.measure_conditions.getMeasureCondition(a.exprs[0]) ? "measure" : "normal"
132676
132715
  };
132677
132716
  }
132678
132717
  function createFieldRelationshipChecker(e16) {
@@ -137472,6 +137511,12 @@ function baseTreeParts(e17, t) {
137472
137511
  t3.extend !== undefined && !isCrossModelExtend(e17, t3) && r3.push(...extendDef(e17, t3.extend).parts), t3 !== n && r3.push(...t3.parts ?? []);
137473
137512
  }), r3;
137474
137513
  }
137514
+ function expandTreeLodParts(e17, t) {
137515
+ let n = (t3) => t3.extend === undefined ? [] : extendDef(e17, t3.extend).parts, r3 = [];
137516
+ return walkTree(t, (i) => {
137517
+ i !== t && !isCrossModelExtend(e17, i) && r3.push(...n(i));
137518
+ }), [...t.extend === undefined ? [] : [...n(t), ...baseTreeParts(e17, extendDef(e17, t.extend))], ...r3];
137519
+ }
137475
137520
  function extendRootRelation(e17, t, n) {
137476
137521
  if (sealedSlot(e17, t))
137477
137522
  return lowerSealedSlot(e17, t, n);
@@ -138277,45 +138322,34 @@ function lowerReduceUncached(e17, t, n) {
138277
138322
  });
138278
138323
  }
138279
138324
  return i.kind === Kind.IDENTIFIER ? buildJoinScope(t, i.name, refRowColumns(i), []) : unsupported$1(`reduce source kind '${i.kind}'`);
138280
- })(), w3 = (e18) => e18.extend === undefined ? [] : extendDef(t, e18.extend).parts, E3 = (e18) => e18.extend === undefined ? [] : [...w3(e18), ...baseTreeParts(t, extendDef(t, e18.extend))], k3 = (e18) => isCrossModelExtend(t, e18) ? [] : w3(e18), N3 = (() => {
138281
- if (i.kind !== "expand_model")
138282
- return [...s3];
138283
- let e18 = [];
138284
- return walkTree(i, (t3) => {
138285
- t3 !== i && e18.push(...k3(t3));
138286
- }), [
138287
- ...E3(i),
138288
- ...e18,
138289
- ...s3
138290
- ];
138291
- })(), I3 = inlineExtendComputed(scopeExtendComputedAll(t, i)), L3 = S3.arity, U3 = attachLodParts(e17, t, S3, N3, S3.relation, L3), pe3 = U3.base;
138292
- L3 = U3.arity;
138293
- let { partOf: me3 } = U3, Ze4 = i.kind === "expand_model" ? membershipBranches(i) : [], yr4 = Ze4.length > 0;
138294
- if (a.length > 0 && !yr4) {
138295
- let e18 = (e19) => me3(e19) ?? S3.indexOf(e19), n3 = (e19) => me3(e19) != null || S3.tryIndexOf(e19) != null;
138296
- pe3 = filterKeepingArity(pe3, a.map((r4) => scalarToPlan(inlineDeclDims(t, I3(r4), n3), e18)));
138297
- }
138298
- let oi3 = scopeExtendComputed(t, i), ci3 = (e18) => {
138325
+ })(), w3 = i.kind === "expand_model" ? [...expandTreeLodParts(t, i), ...s3] : [...s3], E3 = inlineExtendComputed(scopeExtendComputedAll(t, i)), k3 = S3.arity, N3 = attachLodParts(e17, t, S3, w3, S3.relation, k3), I3 = N3.base;
138326
+ k3 = N3.arity;
138327
+ let { partOf: L3 } = N3, U3 = i.kind === "expand_model" ? membershipBranches(i) : [], pe3 = U3.length > 0;
138328
+ if (a.length > 0 && !pe3) {
138329
+ let e18 = (e19) => L3(e19) ?? S3.indexOf(e19), n3 = (e19) => L3(e19) != null || S3.tryIndexOf(e19) != null;
138330
+ I3 = filterKeepingArity(I3, a.map((r4) => scalarToPlan(inlineDeclDims(t, E3(r4), n3), e18)));
138331
+ }
138332
+ let me3 = scopeExtendComputed(t, i), Ze4 = (e18) => {
138299
138333
  let n3 = aliasedOrigin(t, e18);
138300
138334
  return n3 ? S3.scope.tryResolveOrigin(n3) : undefined;
138301
- }, li3 = columnResolver((e18) => ci3(e18) ?? me3(e18) ?? S3.indexOf(e18), (e18) => ci3(e18) ?? me3(e18) ?? S3.tryResolve(e18)), di3 = oi3.map((e18) => scalarToPlan(I3(e18.expr), li3)), fi3 = oi3.map((e18) => e18.origin), pi3 = /* @__PURE__ */ new Map;
138302
- fi3.forEach((e18, t3) => pi3.set(originKey(e18), L3 + t3));
138303
- let mi3 = (e18) => {
138335
+ }, yr4 = columnResolver((e18) => Ze4(e18) ?? L3(e18) ?? S3.indexOf(e18), (e18) => Ze4(e18) ?? L3(e18) ?? S3.tryResolve(e18)), oi3 = me3.map((e18) => scalarToPlan(E3(e18.expr), yr4)), ci3 = me3.map((e18) => e18.origin), li3 = /* @__PURE__ */ new Map;
138336
+ ci3.forEach((e18, t3) => li3.set(originKey(e18), k3 + t3));
138337
+ let di3 = (e18) => {
138304
138338
  let t3 = e18;
138305
138339
  for (;t3.kind === Kind.NAMED_EXPRESSION; )
138306
138340
  t3 = t3.expr;
138307
138341
  let n3 = t3.kind === Kind.IDENTIFIER ? refOrigin(t3) : undefined;
138308
- return n3 ? pi3.get(originKey(n3)) : undefined;
138309
- }, hi3 = (e18) => me3(e18) ?? mi3(e18) ?? S3.indexOf(e18), gi3 = (e18) => me3(e18) ?? mi3(e18) ?? S3.tryIndexOf(e18), _i3 = L3 + di3.length, vi3 = relationType(S3.relation), yi3 = [], bi3 = [], xi3 = (e18) => {
138342
+ return n3 ? li3.get(originKey(n3)) : undefined;
138343
+ }, fi3 = (e18) => L3(e18) ?? di3(e18) ?? S3.indexOf(e18), pi3 = (e18) => L3(e18) ?? di3(e18) ?? S3.tryIndexOf(e18), mi3 = k3 + oi3.length, hi3 = relationType(S3.relation), gi3 = [], _i3 = [], vi3 = (e18) => {
138310
138344
  if (!e18 || !isSubtimeField(e18))
138311
138345
  return;
138312
138346
  let [t3] = e18.fieldName.split("->");
138313
138347
  if (S3.scope.tryResolveOrigin(createModelFieldReference(e18.modelName, t3)) == null)
138314
138348
  return S3.scope.tryResolveOrigin(e18);
138315
- }, Si2 = (e18) => e18.kind === Kind.IDENTIFIER ? me3(e18) != null : e18.kind === Kind.FUNCTION_CALL ? e18.args.some(Si2) : e18.kind === Kind.NAMED_EXPRESSION && Si2(e18.expr), Ci3 = (e18) => {
138316
- if (!Si2(e18)) {
138349
+ }, yi3 = (e18) => e18.kind === Kind.IDENTIFIER ? L3(e18) != null : e18.kind === Kind.FUNCTION_CALL ? e18.args.some(yi3) : e18.kind === Kind.NAMED_EXPRESSION && yi3(e18.expr), bi3 = (e18) => {
138350
+ if (!yi3(e18)) {
138317
138351
  let t3 = refOrigin(e18);
138318
- if (t3 && isSubtimeField(t3) && xi3(t3) != null)
138352
+ if (t3 && isSubtimeField(t3) && vi3(t3) != null)
138319
138353
  return {
138320
138354
  kind: Kind.IDENTIFIER,
138321
138355
  id: e18.id,
@@ -138326,40 +138360,40 @@ function lowerReduceUncached(e17, t, n) {
138326
138360
  }
138327
138361
  return e18.kind === Kind.FUNCTION_CALL ? {
138328
138362
  ...e18,
138329
- args: e18.args.map(Ci3)
138363
+ args: e18.args.map(bi3)
138330
138364
  } : e18.kind === Kind.NAMED_EXPRESSION ? {
138331
138365
  ...e18,
138332
- expr: Ci3(e18.expr)
138366
+ expr: bi3(e18.expr)
138333
138367
  } : e18;
138334
- }, wi3 = (e18) => {
138368
+ }, xi3 = (e18) => {
138335
138369
  let n3 = scopeExtendComputedAll(t, i).find((t3) => originKey(t3.origin) === originKey(e18));
138336
- return n3 ? scalarToPlan(I3(n3.expr), li3) : undefined;
138337
- }, Ti3 = r3.map((e18) => {
138338
- let t3 = gi3(e18);
138370
+ return n3 ? scalarToPlan(E3(n3.expr), yr4) : undefined;
138371
+ }, Si2 = r3.map((e18) => {
138372
+ let t3 = pi3(e18);
138339
138373
  if (t3 != null)
138340
138374
  return t3;
138341
- let n3 = refOrigin(e18), r4 = Si2(e18), i3 = r4 ? undefined : xi3(n3);
138375
+ let n3 = refOrigin(e18), r4 = yi3(e18), i3 = r4 ? undefined : vi3(n3);
138342
138376
  if (i3 == null && !r4) {
138343
138377
  let t4 = e18;
138344
138378
  for (;t4.kind === Kind.NAMED_EXPRESSION; )
138345
138379
  t4 = t4.expr;
138346
- t4 !== e18 && (i3 = xi3(refOrigin(t4)));
138380
+ t4 !== e18 && (i3 = vi3(refOrigin(t4)));
138347
138381
  }
138348
- return i3 ?? (!r4 && e18.kind === Kind.IDENTIFIER && n3 && isSubtimeField(n3) ? yi3.push(subtimeGrainScalar(S3, vi3, n3, wi3)) : r4 ? yi3.push(scalarToPlan(Ci3(I3(e18)), hi3)) : yi3.push(scalarToPlan(rewriteNestedSubtimes(I3(e18), (e19) => gi3(e19) != null), hi3)), bi3.push(n3), _i3 + yi3.length - 1);
138349
- }), Ei3 = [...di3, ...yi3], Di3 = [...fi3, ...bi3], Oi3 = attachSemiJoins(e17, t, Ei3.length > 0 ? cons({
138382
+ return i3 ?? (!r4 && e18.kind === Kind.IDENTIFIER && n3 && isSubtimeField(n3) ? gi3.push(subtimeGrainScalar(S3, hi3, n3, xi3)) : r4 ? gi3.push(scalarToPlan(bi3(E3(e18)), fi3)) : gi3.push(scalarToPlan(rewriteNestedSubtimes(E3(e18), (e19) => pi3(e19) != null), fi3)), _i3.push(n3), mi3 + gi3.length - 1);
138383
+ }), Ci3 = [...oi3, ...gi3], wi3 = [...ci3, ..._i3], Ti3 = attachSemiJoins(e17, t, Ci3.length > 0 ? cons({
138350
138384
  kind: "map",
138351
- input: pe3,
138352
- scalars: Ei3,
138353
- origins: Di3
138354
- }) : pe3, hi3, m3, (e18) => rewriteNestedSubtimes(I3(e18), (e19) => gi3(e19) != null)), ki4 = Ze4.reduce((n3, r4) => joinExistenceFilter(e17, t, n3, S3, r4), Oi3);
138385
+ input: I3,
138386
+ scalars: Ci3,
138387
+ origins: wi3
138388
+ }) : I3, fi3, m3, (e18) => rewriteNestedSubtimes(E3(e18), (e19) => pi3(e19) != null)), Ei3 = U3.reduce((n3, r4) => joinExistenceFilter(e17, t, n3, S3, r4), Ti3);
138355
138389
  return {
138356
138390
  reduce: cons({
138357
138391
  kind: "reduce",
138358
- input: a.length > 0 && yr4 ? filterKeepingArity(ki4, a.map((e18) => scalarToPlan(inlineDeclDims(t, I3(e18), (e19) => gi3(e19) != null), hi3))) : ki4,
138359
- groupKey: Ti3,
138392
+ input: a.length > 0 && pe3 ? filterKeepingArity(Ei3, a.map((e18) => scalarToPlan(inlineDeclDims(t, E3(e18), (e19) => pi3(e19) != null), fi3))) : Ei3,
138393
+ groupKey: Si2,
138360
138394
  aggregates: c3.map((e18) => ({
138361
138395
  func: e18.name.name,
138362
- args: e18.args.length > 0 ? e18.args.map((e19) => scalarToPlan(e19, hi3)) : [{
138396
+ args: e18.args.length > 0 ? e18.args.map((e19) => scalarToPlan(e19, fi3)) : [{
138363
138397
  kind: "literal",
138364
138398
  literal: "number",
138365
138399
  value: "1",
@@ -138378,7 +138412,7 @@ function lowerReduceUncached(e17, t, n) {
138378
138412
  annotations: n.annotations,
138379
138413
  ...n.distinct ? { preferDistinct: true } : {}
138380
138414
  }),
138381
- grainLen: Ti3.length
138415
+ grainLen: Si2.length
138382
138416
  };
138383
138417
  }
138384
138418
  function lowerWindow(e17, t, n) {
@@ -138982,54 +139016,52 @@ function lowerSelect(e17, t, n) {
138982
139016
  }
138983
139017
  if (r3.kind !== Kind.IDENTIFIER && r3.kind !== "expand_model")
138984
139018
  return lowerSelectOver(n, lowerTop(e17, t, r3, originLeafRefs(n.projection)));
138985
- let a = r3.kind === "expand_model" && r3.extend !== undefined && !isCrossModelExtend(t, r3) ? r3 : undefined, { projection: s3 } = n, c3 = i, l, u;
138986
- r3.kind === "expand_model" ? (l = r3.model, u = undefined) : (l = refRootModel(r3) ?? r3.name, u = refRowColumns(r3));
138987
- let f = r3.kind === "expand_model" && isCrossModelExtend(t, r3) ? lowerExtendRelation(t, r3) : undefined, p3 = (() => {
139019
+ let { projection: a } = n, s3 = i, c3, l;
139020
+ r3.kind === "expand_model" ? (c3 = r3.model, l = undefined) : (c3 = refRootModel(r3) ?? r3.name, l = refRowColumns(r3));
139021
+ let u = r3.kind === "expand_model" && isCrossModelExtend(t, r3) ? lowerExtendRelation(t, r3) : undefined, f = (() => {
138988
139022
  if (r3.kind !== "expand_model")
138989
- return buildJoinScope(t, l, u, [], { rootRel: f });
139023
+ return buildJoinScope(t, c3, l, [], { rootRel: u });
138990
139024
  let { edges: n3, fanouts: i3 } = partitionFanoutExpansions(t, r3, e17), a3 = [];
138991
139025
  walkTree(r3, (e18) => {
138992
139026
  e18 !== r3 && a3.push(e18);
138993
139027
  });
138994
139028
  let s4 = crossModelSubstitute(t, a3.filter((e18) => isCrossModelExtend(t, e18)), scopeModelsOf(r3), e17);
138995
- return buildJoinScope(t, l, u, n3, {
138996
- rootRel: f,
139029
+ return buildJoinScope(t, c3, l, n3, {
139030
+ rootRel: u,
138997
139031
  fanouts: i3,
138998
139032
  substitute: s4,
138999
139033
  tree: r3
139000
139034
  });
139001
- })(), m3 = scopeExtendComputed(t, r3), S3 = inlineExtendComputed(scopeExtendComputedAll(t, r3)), { scalars: w3, tableConds: E3 } = splitTableConditions(c3), k3 = w3.length > 0 ? filterKeepingArity(p3.relation, w3.map((e18) => scalarToPlan(S3(e18), p3.indexOf))) : p3.relation;
139002
- k3 = attachSemiJoins(e17, t, k3, p3.indexOf, E3, S3), r3.kind === "expand_model" && (k3 = membershipBranches(r3).reduce((n3, r4) => joinExistenceFilter(e17, t, n3, p3, r4), k3));
139003
- let N3 = arity(k3), I3 = attachLodParts(e17, t, p3, a?.extend === undefined ? [] : extendDef(t, a.extend).parts, k3, N3);
139004
- ({ base: k3 } = I3), N3 = I3.arity;
139005
- let { partOf: L3 } = I3, U3 = (e18) => {
139035
+ })(), p3 = scopeExtendComputed(t, r3), m3 = inlineExtendComputed(scopeExtendComputedAll(t, r3)), S3 = attachLodParts(e17, t, f, r3.kind === "expand_model" ? expandTreeLodParts(t, r3) : [], f.relation, arity(f.relation)), { partOf: w3 } = S3, { scalars: E3, tableConds: k3 } = splitTableConditions(s3), N3 = (e18) => w3(e18) ?? f.indexOf(e18), I3 = E3.length > 0 ? filterKeepingArity(S3.base, E3.map((e18) => scalarToPlan(m3(e18), N3))) : S3.base;
139036
+ I3 = attachSemiJoins(e17, t, I3, N3, k3, m3), r3.kind === "expand_model" && (I3 = membershipBranches(r3).reduce((n3, r4) => joinExistenceFilter(e17, t, n3, f, r4), I3));
139037
+ let L3 = arity(I3), U3 = (e18) => {
139006
139038
  let n3 = aliasedOrigin(t, e18);
139007
139039
  if (n3) {
139008
- let e19 = p3.scope.tryResolveOrigin(n3);
139040
+ let e19 = f.scope.tryResolveOrigin(n3);
139009
139041
  if (e19 != null)
139010
139042
  return e19;
139011
139043
  }
139012
- return L3(e18) ?? p3.indexOf(e18);
139013
- }, pe3 = m3.map((e18) => scalarToPlan(S3(e18.expr), U3)), me3 = m3.map((e18) => e18.origin), Ze4 = /* @__PURE__ */ new Map;
139014
- me3.forEach((e18, t3) => Ze4.set(originKey(e18), N3 + t3));
139044
+ return w3(e18) ?? f.indexOf(e18);
139045
+ }, pe3 = p3.map((e18) => scalarToPlan(m3(e18.expr), U3)), me3 = p3.map((e18) => e18.origin), Ze4 = /* @__PURE__ */ new Map;
139046
+ me3.forEach((e18, t3) => Ze4.set(originKey(e18), L3 + t3));
139015
139047
  let yr4 = (e18) => {
139016
- let t3 = L3(e18);
139048
+ let t3 = w3(e18);
139017
139049
  if (t3 != null)
139018
139050
  return t3;
139019
139051
  let n3 = e18.kind === Kind.IDENTIFIER ? refOrigin(e18) : undefined;
139020
- return (n3 ? Ze4.get(originKey(n3)) : undefined) ?? p3.indexOf(e18);
139052
+ return (n3 ? Ze4.get(originKey(n3)) : undefined) ?? f.indexOf(e18);
139021
139053
  }, oi3 = [...pe3], ci3 = [...me3], li3 = [], di3 = [], fi3 = (e18, t3, n3) => {
139022
139054
  di3.push(e18), li3.push({
139023
139055
  name: t3,
139024
139056
  origin: n3
139025
139057
  });
139026
139058
  }, pi3 = (e18, t3, n3) => {
139027
- oi3.push(e18), ci3.push(n3), di3.push(N3 + oi3.length - 1), li3.push({
139059
+ oi3.push(e18), ci3.push(n3), di3.push(L3 + oi3.length - 1), li3.push({
139028
139060
  name: t3,
139029
139061
  origin: n3
139030
139062
  });
139031
139063
  };
139032
- return s3.forEach((e18, t3) => {
139064
+ return a.forEach((e18, t3) => {
139033
139065
  if (e18.kind === Kind.NAMED_EXPRESSION) {
139034
139066
  let { name: t4 } = e18.name, n3 = refOrigin(e18) ?? refOrigin(e18.expr);
139035
139067
  e18.expr.kind === Kind.IDENTIFIER && isColumnRef(e18.expr) ? fi3(yr4(e18.expr), t4, n3) : pi3(scalarToPlan(e18.expr, yr4), t4, n3);
@@ -139040,10 +139072,10 @@ function lowerSelect(e17, t, n) {
139040
139072
  kind: "project",
139041
139073
  input: oi3.length > 0 ? cons({
139042
139074
  kind: "map",
139043
- input: k3,
139075
+ input: I3,
139044
139076
  scalars: oi3,
139045
139077
  origins: ci3.some((e18) => e18) ? ci3 : undefined
139046
- }) : k3,
139078
+ }) : I3,
139047
139079
  outputs: di3
139048
139080
  }),
139049
139081
  outputs: li3
@@ -145093,18 +145125,23 @@ function getDiagnosticsV2(e17, { store: t, userAttributes: n = [], checkFlags: r
145093
145125
  typeCheckOnly: true
145094
145126
  }).diagnostics;
145095
145127
  }
145096
- function _compile(e17, { referenceTime: t = /* @__PURE__ */ new Date, timezoneRegion: n, databaseTimezone: r3 = "Etc/UTC", fallbackValueTimezoneRegion: i = "Etc/UTC", valueDatetimeFormat: a = "%FT%T.%L%:z", weekStartDay: s3, sqlGenerationFlags: c3, adhocFields: l = [], userAttributes: u, rowLevelPermissions: f, strictUserPermissionCheck: p3 = false, shouldDecomposeFanoutAggregate: m3 = false, calendarRange: S3 = [new Date(1900, 0, 1), new Date(3001, 0, 1)], useV2Compiler: w3 = false, store: E3, globals: k3 = createAmqlGlobals(), checkFlags: N3 = CheckFlags.Normal }) {
145097
- let I3 = parse(e17, "<main>"), L3 = parseAdhocFields(l);
145098
- if (c3?.shouldPrioritizeLengthForMixedPaths && (E3.modelGraph.shouldPrioritizeLengthForMixedPaths = true), w3) {
145128
+ function _compile(e17, { referenceTime: t = /* @__PURE__ */ new Date, timezoneRegion: n, databaseTimezone: r3 = "Etc/UTC", fallbackValueTimezoneRegion: i = "Etc/UTC", valueDatetimeFormat: a = "%FT%T.%L%:z", weekStartDay: s3, sqlGenerationFlags: c3, adhocFields: l = [], userAttributes: u, rowLevelPermissions: f, strictUserPermissionCheck: p3 = false, shouldDecomposeFanoutAggregate: m3 = false, calendarRange: S3 = [new Date(1900, 0, 1), new Date(3001, 0, 1)], useV2Compiler: w3 = false, allowAdhocSqlPassthroughFunctions: E3 = true, store: k3, globals: N3 = createAmqlGlobals(), checkFlags: I3 = CheckFlags.Normal }) {
145129
+ let L3 = parse(e17, "<main>"), U3 = parseAdhocFields(l);
145130
+ if (!E3) {
145131
+ let e18 = checkAdhocSqlPassthrough([L3, ...U3]);
145132
+ if (e18.length > 0)
145133
+ throw createAqlTypecheckError(e18);
145134
+ }
145135
+ if (c3?.shouldPrioritizeLengthForMixedPaths && (k3.modelGraph.shouldPrioritizeLengthForMixedPaths = true), w3) {
145099
145136
  let e18 = resolve({
145100
- program: I3,
145101
- store: E3,
145102
- adhocFields: L3,
145137
+ program: L3,
145138
+ store: k3,
145139
+ adhocFields: U3,
145103
145140
  recordSpanTypes: true,
145104
145141
  userAttributes: u,
145105
145142
  rowLevelPermissions: f,
145106
145143
  strictUserPermissionCheck: p3,
145107
- checkFlags: N3,
145144
+ checkFlags: I3,
145108
145145
  sqlGenerationFlags: c3,
145109
145146
  datetime: {
145110
145147
  timezoneRegion: n,
@@ -145125,14 +145162,14 @@ function _compile(e17, { referenceTime: t = /* @__PURE__ */ new Date, timezoneRe
145125
145162
  sqlGenerationFlags: c3
145126
145163
  });
145127
145164
  return {
145128
- expr: I3,
145165
+ expr: L3,
145129
145166
  explore: m4,
145130
145167
  context: w4,
145131
145168
  json: exploreToJSON(w4, m4),
145132
145169
  spanTypes: e18.spanTypes
145133
145170
  };
145134
145171
  }
145135
- E3.setModel(buildCalendarModel({
145172
+ k3.setModel(buildCalendarModel({
145136
145173
  calendarRange: S3,
145137
145174
  referenceTime: t,
145138
145175
  timezoneRegion: n,
@@ -145140,11 +145177,11 @@ function _compile(e17, { referenceTime: t = /* @__PURE__ */ new Date, timezoneRe
145140
145177
  fallbackValueTimezoneRegion: i,
145141
145178
  valueDatetimeFormat: a,
145142
145179
  weekStartDay: s3
145143
- }, E3.dataSource));
145144
- let U3 = createTypeChecker(E3, u, L3, f, N3), pe3 = U3.getDiagnostics(I3);
145145
- if (pe3.length > 0)
145146
- throw createAqlTypecheckError(pe3);
145147
- return compileAst(I3, {
145180
+ }, k3.dataSource));
145181
+ let pe3 = createTypeChecker(k3, u, U3, f, I3), me3 = pe3.getDiagnostics(L3);
145182
+ if (me3.length > 0)
145183
+ throw createAqlTypecheckError(me3);
145184
+ return compileAst(L3, {
145148
145185
  referenceTime: t,
145149
145186
  timezoneRegion: n,
145150
145187
  databaseTimezone: r3,
@@ -145152,15 +145189,15 @@ function _compile(e17, { referenceTime: t = /* @__PURE__ */ new Date, timezoneRe
145152
145189
  valueDatetimeFormat: a,
145153
145190
  weekStartDay: s3,
145154
145191
  sqlGenerationFlags: c3,
145155
- adhocFieldDeclarations: L3,
145192
+ adhocFieldDeclarations: U3,
145156
145193
  userAttributes: u,
145157
145194
  rowLevelPermissions: f,
145158
145195
  strictUserPermissionCheck: p3,
145159
145196
  shouldDecomposeFanoutAggregate: m3,
145160
145197
  calendarRange: S3,
145161
- store: E3,
145162
- globals: k3,
145163
- checker: U3
145198
+ store: k3,
145199
+ globals: N3,
145200
+ checker: pe3
145164
145201
  });
145165
145202
  }
145166
145203
  var compile = Rr3.wrapFuncWithinActiveSpan(_compile);
@@ -155340,6 +155377,30 @@ async function releaseLock(repoPath) {
155340
155377
  async function writeState(repoPath, state) {
155341
155378
  await writeStateJson(repoPath, "state.json", state);
155342
155379
  }
155380
+ function startingState(resolvedPath, mode, projectId, startedAt, pid = process.pid) {
155381
+ return {
155382
+ mode,
155383
+ pid,
155384
+ project_id: projectId,
155385
+ repo_path: resolvedPath,
155386
+ started_at: startedAt,
155387
+ last_cycle_at: null,
155388
+ dirty_count: 0,
155389
+ last_error: null,
155390
+ conflicts: [],
155391
+ blocked: null,
155392
+ oversized: [],
155393
+ declined: null,
155394
+ pending_input: null,
155395
+ asking: null
155396
+ };
155397
+ }
155398
+ async function recordSpawned(repoPath, mode, projectId, pid) {
155399
+ const resolvedPath = path13.resolve(repoPath);
155400
+ if ((await readState(resolvedPath))?.pid === pid)
155401
+ return;
155402
+ await writeState(resolvedPath, startingState(resolvedPath, mode, projectId, new Date().toISOString(), pid));
155403
+ }
155343
155404
  async function recordPendingInput(repoPath, mode, projectId, pending) {
155344
155405
  const resolvedPath = path13.resolve(repoPath);
155345
155406
  const state = {
@@ -155533,6 +155594,9 @@ class GitRepo {
155533
155594
  };
155534
155595
  return new GitRepo(dir, { env, signal: signal2 });
155535
155596
  }
155597
+ withSignal(signal2) {
155598
+ return new GitRepo(this.repoPath, { env: this.env, signal: signal2 });
155599
+ }
155536
155600
  spawnEnv() {
155537
155601
  if (!this.env)
155538
155602
  return;
@@ -166151,6 +166215,58 @@ function startSessionLoop(runCycle, intervalMs) {
166151
166215
  };
166152
166216
  }
166153
166217
 
166218
+ // src/commands/code_sync/lib/engine/cycle_deadline.ts
166219
+ var NO_DEADLINE = { paused: (wait) => wait() };
166220
+ function formatDuration2(ms6) {
166221
+ if (ms6 >= 60000)
166222
+ return `${Math.round(ms6 / 60000)} min`;
166223
+ return `${Math.round(ms6 / 1000)} s`;
166224
+ }
166225
+ function startCycleDeadline({ timeoutMs, graceMs }, onStuck) {
166226
+ const controller = new AbortController;
166227
+ let timer = null;
166228
+ let settled = false;
166229
+ const disarm = () => {
166230
+ if (timer) {
166231
+ clearTimeout(timer);
166232
+ timer = null;
166233
+ }
166234
+ };
166235
+ const arm = () => {
166236
+ if (settled)
166237
+ return;
166238
+ if (!controller.signal.aborted) {
166239
+ timer = setTimeout(() => {
166240
+ timer = null;
166241
+ controller.abort(new Error(`The sync cycle ran for over ${formatDuration2(timeoutMs)} and was cancelled; the next one starts afresh`));
166242
+ arm();
166243
+ }, timeoutMs);
166244
+ } else {
166245
+ timer = setTimeout(() => {
166246
+ timer = null;
166247
+ settled = true;
166248
+ onStuck();
166249
+ }, graceMs);
166250
+ }
166251
+ };
166252
+ arm();
166253
+ return {
166254
+ signal: controller.signal,
166255
+ paused: async (wait) => {
166256
+ disarm();
166257
+ try {
166258
+ return await wait();
166259
+ } finally {
166260
+ arm();
166261
+ }
166262
+ },
166263
+ clear: () => {
166264
+ settled = true;
166265
+ disarm();
166266
+ }
166267
+ };
166268
+ }
166269
+
166154
166270
  // src/commands/code_sync/lib/engine/session_engine.ts
166155
166271
  var DEFAULT_SESSION_INTERVAL_MS = parseInt(process.env.CODE_SYNC_INTERVAL || "3000");
166156
166272
  function checkBranch(ctx, localBranch, cloudBranch) {
@@ -166354,9 +166470,20 @@ function rebind(ctx, branch, out) {
166354
166470
  ctx.loggedOversized = [];
166355
166471
  out(fmt.cyan(`⟲ Syncing '${branch}' from now on`));
166356
166472
  }
166473
+ function heartbeatOf(ctx, result, error) {
166474
+ return {
166475
+ last_cycle_at: new Date().toISOString(),
166476
+ conflicts: result?.conflicts ?? [],
166477
+ dirty_count: ctx.pending ?? 0,
166478
+ last_error: error,
166479
+ blocked: ctx.blocked ?? null,
166480
+ oversized: ctx.loggedOversized ?? [],
166481
+ declined: ctx.declined ?? null
166482
+ };
166483
+ }
166357
166484
  async function runSessionCycle(ctx, engine = { shutdown: () => {
166358
166485
  ctx.stopped = true;
166359
- } }) {
166486
+ } }, deadline = NO_DEADLINE) {
166360
166487
  if (ctx.stopped)
166361
166488
  return null;
166362
166489
  let result = null;
@@ -166378,7 +166505,8 @@ async function runSessionCycle(ctx, engine = { shutdown: () => {
166378
166505
  if (!ctx.onBranchInput) {
166379
166506
  fatal = branchStopMessage(check.pending, ctx.mode);
166380
166507
  } else if (!ctx.stopped) {
166381
- const resumeOn = await ctx.onBranchInput(check.pending, engine);
166508
+ const ask = ctx.onBranchInput;
166509
+ const resumeOn = await deadline.paused(() => ask(check.pending, engine));
166382
166510
  if (resumeOn === null)
166383
166511
  engine.shutdown();
166384
166512
  else if (!ctx.stopped)
@@ -166406,26 +166534,20 @@ async function runSessionCycle(ctx, engine = { shutdown: () => {
166406
166534
  }
166407
166535
  if (ctx.stopped)
166408
166536
  return result;
166409
- if (ctx.onCycle) {
166410
- await ctx.onCycle({
166411
- last_cycle_at: new Date().toISOString(),
166412
- conflicts: result?.conflicts ?? [],
166413
- dirty_count: ctx.pending ?? 0,
166414
- last_error: error,
166415
- blocked: ctx.blocked ?? null,
166416
- oversized: ctx.loggedOversized ?? [],
166417
- declined: ctx.declined ?? null
166418
- });
166419
- }
166537
+ await ctx.onCycle?.(heartbeatOf(ctx, result, error));
166420
166538
  if (fatal && !ctx.stopped) {
166421
166539
  engine.shutdown();
166422
166540
  await ctx.onFatal?.(fatal);
166423
166541
  }
166424
166542
  return result;
166425
166543
  }
166544
+ var DEFAULT_CYCLE_TIMEOUT_MS = parseInt(process.env.CODE_SYNC_CYCLE_TIMEOUT_MS || String(10 * 60000));
166545
+ var DEFAULT_CYCLE_GRACE_MS = 2 * 60000;
166426
166546
  var MAX_IMMEDIATE_ROUNDS = 3;
166427
166547
  function startSessionEngine(ctx, options2 = {}) {
166428
166548
  const intervalMs = options2.intervalMs ?? DEFAULT_SESSION_INTERVAL_MS;
166549
+ const timeoutMs = options2.cycleTimeoutMs ?? DEFAULT_CYCLE_TIMEOUT_MS;
166550
+ const graceMs = options2.cycleGraceMs ?? DEFAULT_CYCLE_GRACE_MS;
166429
166551
  let lastErrored = false;
166430
166552
  let rounds = 0;
166431
166553
  let loop = null;
@@ -166435,9 +166557,29 @@ function startSessionEngine(ctx, options2 = {}) {
166435
166557
  loop?.stop();
166436
166558
  }
166437
166559
  };
166560
+ const stuck = async () => {
166561
+ if (ctx.stopped)
166562
+ return;
166563
+ const message = withRestart(`A sync cycle ran for over ${formatDuration2(timeoutMs + graceMs)} and did not stop when cancelled, ` + "so the session has stopped.", ctx.mode ?? "foreground");
166564
+ engine.shutdown();
166565
+ logWithTime(fmt.red(`✗ ${message}`));
166566
+ await ctx.onCycle?.(heartbeatOf(ctx, null, message));
166567
+ await ctx.onFatal?.(message);
166568
+ };
166438
166569
  loop = startSessionLoop(async () => {
166439
166570
  ctx.immediateRound = rounds > 0;
166440
- const result = await runSessionCycle(ctx, engine);
166571
+ const deadline = startCycleDeadline({ timeoutMs, graceMs }, () => {
166572
+ stuck().catch((err) => logWithTime(fmt.red(`✗ Failed to stop the session: ${err?.message ?? String(err)}`)));
166573
+ });
166574
+ const sessionRepo = ctx.repo;
166575
+ ctx.repo = sessionRepo.withSignal(deadline.signal);
166576
+ let result;
166577
+ try {
166578
+ result = await runSessionCycle(ctx, engine, deadline);
166579
+ } finally {
166580
+ ctx.repo = sessionRepo;
166581
+ deadline.clear();
166582
+ }
166441
166583
  if (ctx.stopped) {
166442
166584
  loop?.stop();
166443
166585
  return;
@@ -166522,6 +166664,17 @@ import { createHash } from "crypto";
166522
166664
  import fs22 from "fs/promises";
166523
166665
  import { existsSync as existsSync2 } from "fs";
166524
166666
  import path18 from "path";
166667
+
166668
+ // src/commands/code_sync/lib/bun.ts
166669
+ var BUN_STANDALONE_ROOTS = ["/$bunfs/", "B:/~BUN/", "B:\\~BUN\\"];
166670
+ function isBunStandaloneEntry(entryPath) {
166671
+ if (!entryPath)
166672
+ return false;
166673
+ const lowerEntry = entryPath.toLowerCase();
166674
+ return BUN_STANDALONE_ROOTS.some((root2) => lowerEntry.startsWith(root2.toLowerCase()));
166675
+ }
166676
+
166677
+ // src/commands/code_sync/lib/branch_wip/hooks.ts
166525
166678
  var HOOKS_FILE = "hooks.json";
166526
166679
  var BLOCK_BEGIN = "# >>> holistics sync >>>";
166527
166680
  var BLOCK_END = "# <<< holistics sync <<<";
@@ -166531,24 +166684,20 @@ function shellQuote2(s3) {
166531
166684
  }
166532
166685
  function selfCommand() {
166533
166686
  const script = process.argv[1];
166534
- if (script && script !== process.execPath && existsSync2(script))
166687
+ if (script && script !== process.execPath && !isBunStandaloneEntry(script) && existsSync2(script)) {
166535
166688
  return [process.execPath, path18.resolve(script)];
166689
+ }
166536
166690
  return existsSync2(process.execPath) ? [process.execPath] : null;
166537
166691
  }
166538
166692
  function runCli(self2, args) {
166539
- const fallback = [
166540
- "command -v holistics >/dev/null 2>&1; then",
166693
+ const lines = [
166694
+ " if command -v holistics >/dev/null 2>&1; then",
166541
166695
  ` holistics sync ${args} || true`
166542
166696
  ];
166543
- if (!self2)
166544
- return [` if ${fallback[0]}`, fallback[1], " fi"];
166545
- return [
166546
- ` if [ -x ${shellQuote2(self2[0])} ]; then`,
166547
- ` ${self2.map(shellQuote2).join(" ")} sync ${args} || true`,
166548
- ` elif ${fallback[0]}`,
166549
- fallback[1],
166550
- " fi"
166551
- ];
166697
+ if (self2) {
166698
+ lines.push(` elif [ -x ${shellQuote2(self2[0])} ]; then`, ` ${self2.map(shellQuote2).join(" ")} sync ${args} || true`);
166699
+ }
166700
+ return [...lines, " fi"];
166552
166701
  }
166553
166702
  var HEADER = [
166554
166703
  BLOCK_BEGIN,
@@ -166977,13 +167126,6 @@ import { spawn as spawn2 } from "child_process";
166977
167126
  import fs24 from "fs";
166978
167127
  import path20 from "path";
166979
167128
  var CHILD_ENV_FLAG = "HOLISTICS_SYNC_CHILD";
166980
- var BUN_STANDALONE_ROOTS = ["/$bunfs/", "B:/~BUN/", "B:\\~BUN\\"];
166981
- function isBunStandaloneEntry(entryPath) {
166982
- if (!entryPath)
166983
- return false;
166984
- const lowerEntry = entryPath.toLowerCase();
166985
- return BUN_STANDALONE_ROOTS.some((root2) => lowerEntry.startsWith(root2.toLowerCase()));
166986
- }
166987
167129
  function buildBackgroundSpawnArgs(resolvedPath, entryPath) {
166988
167130
  const childCommand = ["sync", "start", resolvedPath];
166989
167131
  return isBunStandaloneEntry(entryPath) ? childCommand : [entryPath, ...childCommand];
@@ -167000,16 +167142,16 @@ async function spawnBackgroundSync(repoPath) {
167000
167142
  }
167001
167143
  log(fmt.bold("Holistics Code Sync"));
167002
167144
  separator();
167003
- let failure = null;
167145
+ let preflight;
167004
167146
  try {
167005
- await runSyncPreflight(resolvedPath, "background");
167147
+ preflight = await runSyncPreflight(resolvedPath, "background");
167006
167148
  } catch (error) {
167007
- failure = { error };
167149
+ preflight = { error };
167008
167150
  }
167009
167151
  await releaseLock(resolvedPath);
167010
- if (failure) {
167152
+ if ("error" in preflight) {
167011
167153
  log(fmt.red("Please fix the error, then run `holistics sync start --background` again"));
167012
- await logErr(failure.error);
167154
+ await logErr(preflight.error);
167013
167155
  process.exit(1);
167014
167156
  }
167015
167157
  const entryPath = process.argv[1];
@@ -167028,6 +167170,9 @@ async function spawnBackgroundSync(repoPath) {
167028
167170
  });
167029
167171
  child.unref();
167030
167172
  fs24.closeSync(fd3);
167173
+ if (child.pid !== undefined) {
167174
+ await recordSpawned(resolvedPath, "background", preflight.project.id, child.pid);
167175
+ }
167031
167176
  log(fmt.green(`✓ Background sync started (pid ${child.pid})`));
167032
167177
  log(fmt.dim(` Log: ${logFile}`));
167033
167178
  log(fmt.dim(" Status: holistics sync status"));
@@ -167044,24 +167189,6 @@ function claimExit(exit) {
167044
167189
  exit.exiting = true;
167045
167190
  return true;
167046
167191
  }
167047
- function startingState(resolvedPath, mode, projectId, startedAt) {
167048
- return {
167049
- mode,
167050
- pid: process.pid,
167051
- project_id: projectId,
167052
- repo_path: resolvedPath,
167053
- started_at: startedAt,
167054
- last_cycle_at: null,
167055
- dirty_count: 0,
167056
- last_error: null,
167057
- conflicts: [],
167058
- blocked: null,
167059
- oversized: [],
167060
- declined: null,
167061
- pending_input: null,
167062
- asking: null
167063
- };
167064
- }
167065
167192
  function buildHeartbeatWriter(resolvedPath, mode, projectId, clock) {
167066
167193
  return async (heartbeat) => {
167067
167194
  if (!clock.fresh && heartbeat.last_error === null)
@@ -167828,7 +167955,7 @@ See documentation at: https://docs.holistics.io/docs/cli`);
167828
167955
  command12.commands.forEach((subCommand) => addDocumentationHelp(subCommand));
167829
167956
  }
167830
167957
  function registerCommands(program3) {
167831
- program3.version(version);
167958
+ program3.name("holistics").version(version);
167832
167959
  program3.addCommand(auth_default).addCommand(dbt_default).addCommand(aml_default).addCommand(mcp_default).addCommand(query_default).addCommand(sync_default).addCommand(legacy_default, { hidden: true });
167833
167960
  addDocumentationHelp(program3);
167834
167961
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@holistics/cli-core",
3
3
  "type": "module",
4
- "version": "2.5.6",
4
+ "version": "2.5.8",
5
5
  "bin": {
6
6
  "holistics": "./bin/holistics.js"
7
7
  },