@sqlanvil/cli 1.25.0 → 1.25.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/._LICENSE ADDED
Binary file
package/._NOTICE ADDED
Binary file
package/._README.md ADDED
Binary file
package/._bundle.js ADDED
Binary file
package/._package.json ADDED
Binary file
Binary file
package/bundle.js CHANGED
@@ -49219,7 +49219,15 @@ function verifyObjectMatchesProto(protoType, object, errorBehaviour = VerifyProt
49219
49219
  if (Array.isArray(object)) {
49220
49220
  throw ReferenceError(`Expected a top-level object, but found an array`);
49221
49221
  }
49222
- protoType.verify(object);
49222
+ const verificationError = protoType.verify(object);
49223
+ if (verificationError && verifyErrorIsNonPrimitiveInScalarField(verificationError, object)) {
49224
+ if (errorBehaviour === VerifyProtoErrorBehaviour.SUGGEST_REPORTING_TO_DATAFORM_TEAM) {
49225
+ throw ReferenceError(`Invalid property value: ${verificationError}, please report this to the sqlanvil team ` +
49226
+ `at ${REPORT_ISSUE_URL}.`);
49227
+ }
49228
+ throw ReferenceError(`Invalid property value: ${verificationError}.` +
49229
+ maybeGetDocsLinkPrefix(errorBehaviour, protoType));
49230
+ }
49223
49231
  const proto = protoType.create(object);
49224
49232
  const protoCastObject = protoType.toObject(proto);
49225
49233
  function checkFields(present, desired) {
@@ -49254,6 +49262,23 @@ function verifyObjectMatchesProto(protoType, object, errorBehaviour = VerifyProt
49254
49262
  checkFields(object, protoCastObject);
49255
49263
  return proto;
49256
49264
  }
49265
+ function verifyErrorIsNonPrimitiveInScalarField(message, root) {
49266
+ if (/object expected|array expected|\{k:/.test(message)) {
49267
+ return false;
49268
+ }
49269
+ const path = message.split(":")[0].trim().split(".");
49270
+ let value = root;
49271
+ for (const segment of path) {
49272
+ if (Array.isArray(value)) {
49273
+ value = value.find(element => element !== null && typeof element === "object" && segment in element);
49274
+ }
49275
+ if (value === null || typeof value !== "object" || !(segment in value)) {
49276
+ return false;
49277
+ }
49278
+ value = value[segment];
49279
+ }
49280
+ return value !== null && typeof value === "object";
49281
+ }
49257
49282
  function maybeGetDocsLinkPrefix(errorBehaviour, protoType) {
49258
49283
  return errorBehaviour === VerifyProtoErrorBehaviour.SHOW_DOCS_LINK
49259
49284
  ? ` See ${CONFIGS_PROTO_DOCUMENTATION_URL}#${protoType
@@ -50621,7 +50646,7 @@ function collectEvaluationQueries(queryOrAction, concatenate, queryModifier = (q
50621
50646
  .filter(validationQuery => !!validationQuery.query);
50622
50647
  }
50623
50648
 
50624
- const version = "1.25.0";
50649
+ const version = "1.25.2";
50625
50650
  const dataformVersion = "3.0.61";
50626
50651
 
50627
50652
  async function build(compiledGraph, runConfig, dbadapter) {
@@ -55967,6 +55992,28 @@ function dependencyBlocked(dependencyKeys, statusByKey) {
55967
55992
  return status !== undefined && status !== "PASS";
55968
55993
  });
55969
55994
  }
55995
+ function rewriteSelfReferences(graph, shadowSuffix, resolveTarget) {
55996
+ var _a;
55997
+ const suffix = `_${shadowSuffix}`;
55998
+ for (const action of [...(graph.tables || []), ...(graph.assertions || [])]) {
55999
+ const target = action.target;
56000
+ if (!((_a = target === null || target === void 0 ? void 0 : target.schema) === null || _a === void 0 ? void 0 : _a.endsWith(suffix))) {
56001
+ continue;
56002
+ }
56003
+ const prodTarget = sqlanvil.Target.create(Object.assign(Object.assign({}, target), { schema: target.schema.slice(0, -suffix.length) }));
56004
+ const shadowName = resolveTarget(target);
56005
+ const prodName = resolveTarget(prodTarget);
56006
+ const rewrite = (sql) => sql.split(shadowName).join(prodName);
56007
+ if (action.query) {
56008
+ action.query = rewrite(action.query);
56009
+ }
56010
+ const table = action;
56011
+ if (table.incrementalQuery) {
56012
+ table.incrementalQuery = rewrite(table.incrementalQuery);
56013
+ }
56014
+ }
56015
+ return graph;
56016
+ }
55970
56017
  const VALIDATE_SHADOW_PREFIX = "sqlanvil_validate_";
55971
56018
  function validateShadowSuffix(nowMs) {
55972
56019
  return `${VALIDATE_SHADOW_PREFIX}${nowMs}`;
@@ -56010,6 +56057,22 @@ function tableType(enumType) {
56010
56057
  function depKeys(deps) {
56011
56058
  return (deps || []).map(targetKey);
56012
56059
  }
56060
+ function stripOps(table) {
56061
+ const bare = sqlanvil.Table.create(table);
56062
+ bare.preOps = [];
56063
+ bare.postOps = [];
56064
+ bare.incrementalPreOps = [];
56065
+ bare.incrementalPostOps = [];
56066
+ return bare;
56067
+ }
56068
+ function collectOps(table) {
56069
+ return [
56070
+ ...(table.preOps || []),
56071
+ ...(table.postOps || []),
56072
+ ...(table.incrementalPreOps || []),
56073
+ ...(table.incrementalPostOps || [])
56074
+ ].filter(op => !!op && !!op.trim());
56075
+ }
56013
56076
  async function validate(compiledGraph, deps, options = {}) {
56014
56077
  const nodes = [];
56015
56078
  for (const table of compiledGraph.tables || []) {
@@ -56094,20 +56157,33 @@ async function validate(compiledGraph, deps, options = {}) {
56094
56157
  results.push({ target: node.target, type: node.type, status: "BLOCKED", errors: [] });
56095
56158
  continue;
56096
56159
  }
56160
+ const evaluationAction = node.kind === "table" ? stripOps(node.table) : node.action;
56097
56161
  const evaluations = node.kind === "script"
56098
56162
  ? await deps.checkScript(node.script)
56099
- : await deps.evaluate(node.action);
56163
+ : await deps.evaluate(evaluationAction);
56100
56164
  const failed = evaluations.some(e => e.status === sqlanvil.QueryEvaluation.QueryEvaluationStatus.FAILURE);
56101
- const status = failed ? "FAILURE" : "PASS";
56102
- statusByKey.set(node.key, status);
56103
- results.push({ target: node.target, type: node.type, status, errors: evaluations });
56165
+ let status = failed ? "FAILURE" : "PASS";
56166
+ let stubCreated = false;
56104
56167
  if (status === "PASS" && node.kind === "table") {
56105
56168
  try {
56106
56169
  await deps.execute(deps.validationStubSql(node.table));
56170
+ stubCreated = true;
56107
56171
  }
56108
56172
  catch (e) {
56109
56173
  }
56110
56174
  }
56175
+ if (status === "PASS" && node.kind === "table" && stubCreated && deps.evaluateOp) {
56176
+ for (const op of collectOps(node.table)) {
56177
+ const opEvaluations = await deps.evaluateOp(op);
56178
+ evaluations.push(...opEvaluations);
56179
+ if (opEvaluations.some(e => e.status === sqlanvil.QueryEvaluation.QueryEvaluationStatus.FAILURE)) {
56180
+ status = "FAILURE";
56181
+ break;
56182
+ }
56183
+ }
56184
+ }
56185
+ statusByKey.set(node.key, status);
56186
+ results.push({ target: node.target, type: node.type, status, errors: evaluations });
56111
56187
  }
56112
56188
  }
56113
56189
  finally {
@@ -57178,6 +57254,7 @@ async function runValidate(argv) {
57178
57254
  tags: argv[tagsOption.name]
57179
57255
  });
57180
57256
  const executionSql = new ExecutionSql(compiledGraph.projectConfig, dataformVersion);
57257
+ rewriteSelfReferences(prunedGraph, shadowSuffix, target => executionSql.resolveTarget(target));
57181
57258
  const shadowSchemas = Array.from(new Set((prunedGraph.tables || []).map(table => table.target.schema)));
57182
57259
  process.on("SIGINT", () => {
57183
57260
  Promise.all(shadowSchemas.map(schema => dbadapter.execute(executionSql.dropSchemaCascadeSql(schema)).catch(() => undefined))).then(() => process.exit(1));
@@ -57186,6 +57263,7 @@ async function runValidate(argv) {
57186
57263
  evaluate: action => dbadapter.evaluate(action.enumType !== undefined
57187
57264
  ? sqlanvil.Table.create(action)
57188
57265
  : sqlanvil.Assertion.create(action)),
57266
+ evaluateOp: warehouse === "bigquery" ? (sql) => dbadapter.evaluate(sql) : undefined,
57189
57267
  execute: sql => dbadapter.execute(sql).then(() => undefined),
57190
57268
  validationStubSql: table => executionSql.validationStubSql(table),
57191
57269
  createSchemaSql: schema => executionSql.createSchemaSql(schema),
package/package.json CHANGED
@@ -71,7 +71,7 @@
71
71
  "bin": {
72
72
  "sqlanvil": "bundle.js"
73
73
  },
74
- "version": "1.25.0",
74
+ "version": "1.25.2",
75
75
  "name": "@sqlanvil/cli",
76
76
  "description": "sqlanvil command line interface.",
77
77
  "main": "bundle.js"