@sqlanvil/cli 1.2.0 → 1.4.0

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 (3) hide show
  1. package/bundle.js +296 -338
  2. package/package.json +1 -1
  3. package/worker_bundle.js +28 -0
package/bundle.js CHANGED
@@ -12722,6 +12722,7 @@ const sqlanvil = $root.sqlanvil = (() => {
12722
12722
  * @interface IBound
12723
12723
  * @property {string|null} [name] Bound name
12724
12724
  * @property {string|null} [values] Bound values
12725
+ * @property {sqlanvil.PostgresOptions.IPartition|null} [subPartition] Bound subPartition
12725
12726
  */
12726
12727
 
12727
12728
  /**
@@ -12755,6 +12756,14 @@ const sqlanvil = $root.sqlanvil = (() => {
12755
12756
  */
12756
12757
  Bound.prototype.values = "";
12757
12758
 
12759
+ /**
12760
+ * Bound subPartition.
12761
+ * @member {sqlanvil.PostgresOptions.IPartition|null|undefined} subPartition
12762
+ * @memberof sqlanvil.PostgresOptions.Partition.Bound
12763
+ * @instance
12764
+ */
12765
+ Bound.prototype.subPartition = null;
12766
+
12758
12767
  /**
12759
12768
  * Creates a new Bound instance using the specified properties.
12760
12769
  * @function create
@@ -12783,6 +12792,8 @@ const sqlanvil = $root.sqlanvil = (() => {
12783
12792
  writer.uint32(/* id 1, wireType 2 =*/10).string(message.name);
12784
12793
  if (message.values != null && Object.hasOwnProperty.call(message, "values"))
12785
12794
  writer.uint32(/* id 2, wireType 2 =*/18).string(message.values);
12795
+ if (message.subPartition != null && Object.hasOwnProperty.call(message, "subPartition"))
12796
+ $root.sqlanvil.PostgresOptions.Partition.encode(message.subPartition, writer.uint32(/* id 3, wireType 2 =*/26).fork()).ldelim();
12786
12797
  return writer;
12787
12798
  };
12788
12799
 
@@ -12827,6 +12838,10 @@ const sqlanvil = $root.sqlanvil = (() => {
12827
12838
  message.values = reader.string();
12828
12839
  break;
12829
12840
  }
12841
+ case 3: {
12842
+ message.subPartition = $root.sqlanvil.PostgresOptions.Partition.decode(reader, reader.uint32());
12843
+ break;
12844
+ }
12830
12845
  default:
12831
12846
  reader.skipType(tag & 7);
12832
12847
  break;
@@ -12868,6 +12883,11 @@ const sqlanvil = $root.sqlanvil = (() => {
12868
12883
  if (message.values != null && message.hasOwnProperty("values"))
12869
12884
  if (!$util.isString(message.values))
12870
12885
  return "values: string expected";
12886
+ if (message.subPartition != null && message.hasOwnProperty("subPartition")) {
12887
+ let error = $root.sqlanvil.PostgresOptions.Partition.verify(message.subPartition);
12888
+ if (error)
12889
+ return "subPartition." + error;
12890
+ }
12871
12891
  return null;
12872
12892
  };
12873
12893
 
@@ -12887,6 +12907,11 @@ const sqlanvil = $root.sqlanvil = (() => {
12887
12907
  message.name = String(object.name);
12888
12908
  if (object.values != null)
12889
12909
  message.values = String(object.values);
12910
+ if (object.subPartition != null) {
12911
+ if (typeof object.subPartition !== "object")
12912
+ throw TypeError(".sqlanvil.PostgresOptions.Partition.Bound.subPartition: object expected");
12913
+ message.subPartition = $root.sqlanvil.PostgresOptions.Partition.fromObject(object.subPartition);
12914
+ }
12890
12915
  return message;
12891
12916
  };
12892
12917
 
@@ -12906,11 +12931,14 @@ const sqlanvil = $root.sqlanvil = (() => {
12906
12931
  if (options.defaults) {
12907
12932
  object.name = "";
12908
12933
  object.values = "";
12934
+ object.subPartition = null;
12909
12935
  }
12910
12936
  if (message.name != null && message.hasOwnProperty("name"))
12911
12937
  object.name = message.name;
12912
12938
  if (message.values != null && message.hasOwnProperty("values"))
12913
12939
  object.values = message.values;
12940
+ if (message.subPartition != null && message.hasOwnProperty("subPartition"))
12941
+ object.subPartition = $root.sqlanvil.PostgresOptions.Partition.toObject(message.subPartition, options);
12914
12942
  return object;
12915
12943
  };
12916
12944
 
@@ -38415,27 +38443,44 @@ class PostgresExecutionSql {
38415
38443
  }
38416
38444
  }
38417
38445
  createPartitionedTableTasks(table) {
38446
+ var _a;
38418
38447
  const partition = table.postgres.partition;
38419
38448
  const target = this.resolveTarget(table.target);
38420
38449
  const stage = this.resolveTarget(Object.assign(Object.assign({}, table.target), { name: `${table.target.name}__sa_stage` }));
38421
38450
  const kind = this.partitionKindAsSql(partition.kind);
38422
38451
  const columns = (partition.columns || []).map(c => `"${c}"`).join(", ");
38452
+ const tablespace = ((_a = table.postgres) === null || _a === void 0 ? void 0 : _a.tablespace) ? ` tablespace "${table.postgres.tablespace}"` : "";
38423
38453
  const statements = [
38424
38454
  `drop table if exists ${stage} cascade`,
38425
38455
  `create unlogged table ${stage} as ${table.query} with no data`,
38426
38456
  `drop table if exists ${target} cascade`,
38427
- `create table ${target} (like ${stage} including defaults) partition by ${kind} (${columns})`
38457
+ `create table ${target} (like ${stage} including defaults) partition by ${kind} (${columns})${tablespace}`
38428
38458
  ];
38459
+ statements.push(...this.createChildPartitions(table.target, table.target.name, target, partition));
38460
+ statements.push(`insert into ${target} select * from (${table.query}) as q`);
38461
+ statements.push(`drop table if exists ${stage} cascade`);
38462
+ return statements;
38463
+ }
38464
+ createChildPartitions(baseTarget, parentName, parentSql, partition) {
38465
+ const statements = [];
38429
38466
  for (const bound of partition.partitions || []) {
38430
- const child = this.resolveTarget(Object.assign(Object.assign({}, table.target), { name: `${table.target.name}__${bound.name}` }));
38431
- statements.push(`create table ${child} partition of ${target} for values ${bound.values}`);
38467
+ const childName = `${parentName}__${bound.name}`;
38468
+ const childSql = this.resolveTarget(Object.assign(Object.assign({}, baseTarget), { name: childName }));
38469
+ const sub = bound.subPartition;
38470
+ if (sub && (sub.columns || []).length > 0) {
38471
+ const subKind = this.partitionKindAsSql(sub.kind);
38472
+ const subColumns = (sub.columns || []).map(c => `"${c}"`).join(", ");
38473
+ statements.push(`create table ${childSql} partition of ${parentSql} for values ${bound.values} partition by ${subKind} (${subColumns})`);
38474
+ statements.push(...this.createChildPartitions(baseTarget, childName, childSql, sub));
38475
+ }
38476
+ else {
38477
+ statements.push(`create table ${childSql} partition of ${parentSql} for values ${bound.values}`);
38478
+ }
38432
38479
  }
38433
38480
  if (partition.includeDefault) {
38434
- const def = this.resolveTarget(Object.assign(Object.assign({}, table.target), { name: `${table.target.name}__default` }));
38435
- statements.push(`create table ${def} partition of ${target} default`);
38481
+ const def = this.resolveTarget(Object.assign(Object.assign({}, baseTarget), { name: `${parentName}__default` }));
38482
+ statements.push(`create table ${def} partition of ${parentSql} default`);
38436
38483
  }
38437
- statements.push(`insert into ${target} select * from (${table.query}) as q`);
38438
- statements.push(`drop table if exists ${stage} cascade`);
38439
38484
  return statements;
38440
38485
  }
38441
38486
  partitionKindAsSql(kind) {
@@ -38608,7 +38653,7 @@ function collectEvaluationQueries(queryOrAction, concatenate, queryModifier = (q
38608
38653
  .filter(validationQuery => !!validationQuery.query);
38609
38654
  }
38610
38655
 
38611
- const version = "1.2.0";
38656
+ const version = "1.4.0";
38612
38657
  const dataformVersion = "3.0.59";
38613
38658
 
38614
38659
  async function build(compiledGraph, runConfig, dbadapter) {
@@ -39693,12 +39738,13 @@ async function test(dbadapter, tests) {
39693
39738
  return await Promise.all(tests.map(testCase => runTest(dbadapter, testCase)));
39694
39739
  }
39695
39740
  async function runTest(dbadapter, testCase) {
39741
+ const noLimit = {};
39696
39742
  let actualResults;
39697
39743
  let expectedResults;
39698
39744
  try {
39699
39745
  [actualResults, expectedResults] = await Promise.all([
39700
- dbadapter.execute(testCase.testQuery, { byteLimit: 1024 * 1024 }),
39701
- dbadapter.execute(testCase.expectedOutputQuery, { byteLimit: 1024 * 1024 })
39746
+ dbadapter.execute(testCase.testQuery, noLimit),
39747
+ dbadapter.execute(testCase.expectedOutputQuery, noLimit)
39702
39748
  ]);
39703
39749
  }
39704
39750
  catch (e) {
@@ -41233,6 +41279,12 @@ function getBigQueryCredentials() {
41233
41279
  };
41234
41280
  }
41235
41281
 
41282
+ function option(name, opt, check) {
41283
+ return { name, option: opt, check };
41284
+ }
41285
+ function positionalOption(name, opt, check) {
41286
+ return { name, option: opt, check };
41287
+ }
41236
41288
  function createYargsCli(cli) {
41237
41289
  let yargsChain = yargs__default["default"](fixArgvForHelp());
41238
41290
  for (const command of cli.commands) {
@@ -41938,16 +41990,14 @@ function postProcessFormattedSqlx(formattedSql) {
41938
41990
 
41939
41991
  const RECOMPILE_DELAY = 500;
41940
41992
  process.on("unhandledRejection", async (reason) => {
41941
- printError(`Unhandled promise rejection: ${(reason === null || reason === void 0 ? void 0 : reason.stack) || reason}`);
41993
+ var _a;
41994
+ printError(`Unhandled promise rejection: ${((_a = reason) === null || _a === void 0 ? void 0 : _a.stack) || reason}`);
41995
+ });
41996
+ const projectDirOption = positionalOption("project-dir", {
41997
+ describe: "The sqlanvil project directory.",
41998
+ default: ".",
41999
+ coerce: actuallyResolve
41942
42000
  });
41943
- const projectDirOption = {
41944
- name: "project-dir",
41945
- option: {
41946
- describe: "The sqlanvil project directory.",
41947
- default: ".",
41948
- coerce: actuallyResolve
41949
- }
41950
- };
41951
42001
  const projectDirMustExistOption = Object.assign(Object.assign({}, projectDirOption), { check: (argv) => {
41952
42002
  assertPathExists(argv[projectDirOption.name]);
41953
42003
  const workflowSettingsYamlPath = path__namespace.resolve(argv[projectDirOption.name], "workflow_settings.yaml");
@@ -41955,144 +42005,104 @@ const projectDirMustExistOption = Object.assign(Object.assign({}, projectDirOpti
41955
42005
  throw new Error(`${argv[projectDirOption.name]} does not appear to be a sqlanvil directory (missing workflow_settings.yaml file).`);
41956
42006
  }
41957
42007
  } });
41958
- const fullRefreshOption = {
41959
- name: "full-refresh",
41960
- option: {
41961
- describe: "Forces incremental tables to be rebuilt from scratch.",
41962
- type: "boolean",
41963
- default: false
41964
- }
41965
- };
41966
- const actionsOption = {
41967
- name: "actions",
41968
- option: {
41969
- describe: "A list of action names or patterns to run. Can include '*' wildcards.",
41970
- type: "array",
41971
- coerce: (rawActions) => rawActions.map(actions => actions.split(",")).flat()
41972
- }
41973
- };
41974
- const tagsOption = {
41975
- name: "tags",
41976
- option: {
41977
- describe: "A list of tags to filter the actions to run.",
41978
- type: "array",
41979
- coerce: (rawTags) => rawTags.map(tags => tags.split(",")).flat()
41980
- }
41981
- };
41982
- const includeDepsOption = {
41983
- name: "include-deps",
41984
- option: {
41985
- describe: "If set, dependencies for selected actions will also be run.",
41986
- type: "boolean"
41987
- },
41988
- check: (argv) => {
41989
- if (argv[includeDepsOption.name] && !(argv[actionsOption.name] || argv[tagsOption.name])) {
41990
- throw new Error(`The --${includeDepsOption.name} flag should only be supplied along with --${actionsOption.name} or --${tagsOption.name}.`);
41991
- }
41992
- }
41993
- };
41994
- const includeDependentsOption = {
41995
- name: "include-dependents",
41996
- option: {
41997
- describe: "If set, dependents (downstream) for selected actions will also be run.",
41998
- type: "boolean"
41999
- },
42000
- check: (argv) => {
42001
- if (argv[includeDependentsOption.name] &&
42002
- !(argv[actionsOption.name] || argv[tagsOption.name])) {
42003
- throw new Error(`The --${includeDependentsOption.name} flag should only be supplied along with --${actionsOption.name} or --${tagsOption.name}.`);
42004
- }
42005
- }
42006
- };
42007
- const credentialsOption = {
42008
- name: "credentials",
42009
- option: {
42010
- describe: "The location of the credentials JSON file to use.",
42011
- default: CREDENTIALS_FILENAME
42012
- },
42013
- check: (argv) => getCredentialsPath(argv[projectDirOption.name], argv[credentialsOption.name])
42014
- };
42015
- const jsonOutputOption = {
42016
- name: "json",
42017
- option: {
42018
- describe: "Outputs a JSON representation of the compiled project or test results.",
42019
- type: "boolean",
42020
- default: false
42021
- }
42022
- };
42023
- const dotOutputOption = {
42024
- name: "dot",
42025
- option: {
42026
- describe: "Outputs a dot representation of the compiled project.",
42027
- type: "boolean",
42028
- default: false,
42029
- },
42030
- check: (argv) => {
42031
- if (argv.json && argv.dot) {
42032
- throw new Error("Arguments --json and --dot are mutually exclusive.");
42033
- }
42034
- }
42035
- };
42036
- const timeoutOption = {
42037
- name: "timeout",
42038
- option: {
42039
- describe: "Duration to allow project compilation to complete. Examples: '1s', '10m', etc.",
42040
- type: "string",
42041
- default: null,
42042
- coerce: (rawTimeoutString) => rawTimeoutString ? parseDuration__default["default"](rawTimeoutString) : null
42043
- }
42044
- };
42045
- const jobPrefixOption = {
42046
- name: "job-prefix",
42047
- option: {
42048
- describe: "Adds an additional prefix in the form of `sqlanvil-${jobPrefix}-`.",
42049
- type: "string",
42050
- default: null
42008
+ const fullRefreshOption = option("full-refresh", {
42009
+ describe: "Forces incremental tables to be rebuilt from scratch.",
42010
+ type: "boolean",
42011
+ default: false
42012
+ });
42013
+ const actionsOption = option("actions", {
42014
+ describe: "A list of action names or patterns to run. Can include '*' wildcards.",
42015
+ type: "array",
42016
+ coerce: (rawActions) => rawActions.map(actions => actions.split(",")).flat()
42017
+ });
42018
+ const tagsOption = option("tags", {
42019
+ describe: "A list of tags to filter the actions to run.",
42020
+ type: "array",
42021
+ coerce: (rawTags) => rawTags.map(tags => tags.split(",")).flat()
42022
+ });
42023
+ const includeDepsOption = option("include-deps", {
42024
+ describe: "If set, dependencies for selected actions will also be run.",
42025
+ type: "boolean"
42026
+ }, (argv) => {
42027
+ if (argv[includeDepsOption.name] && !(argv[actionsOption.name] || argv[tagsOption.name])) {
42028
+ throw new Error(`The --${includeDepsOption.name} flag should only be supplied along with --${actionsOption.name} or --${tagsOption.name}.`);
42051
42029
  }
42052
- };
42053
- const bigqueryJobLabelsOption = {
42054
- name: "job-labels",
42055
- option: {
42056
- describe: "Comma-separated list of labels to add to BigQuery jobs, e.g. 'key1=val1,key2=val2'.",
42057
- type: "string",
42058
- coerce: (raw) => {
42059
- const labels = {};
42060
- raw === null || raw === void 0 ? void 0 : raw.split(",").forEach(kv => {
42061
- if (!kv) {
42062
- return;
42063
- }
42064
- const [key, ...rest] = kv.split("=");
42065
- labels[key] = rest.join("=") || "";
42066
- });
42067
- return labels;
42068
- }
42030
+ });
42031
+ const includeDependentsOption = option("include-dependents", {
42032
+ describe: "If set, dependents (downstream) for selected actions will also be run.",
42033
+ type: "boolean"
42034
+ }, (argv) => {
42035
+ if (argv[includeDependentsOption.name] &&
42036
+ !(argv[actionsOption.name] || argv[tagsOption.name])) {
42037
+ throw new Error(`The --${includeDependentsOption.name} flag should only be supplied along with --${actionsOption.name} or --${tagsOption.name}.`);
42069
42038
  }
42070
- };
42071
- const quietCompileOption = {
42072
- name: "quiet",
42073
- option: {
42074
- describe: "Less verbose compilation output. Example usage: 'sqlanvil compile --quiet'",
42075
- type: "boolean",
42076
- default: false
42039
+ });
42040
+ const compileActionsOption = Object.assign(Object.assign({}, actionsOption), { option: Object.assign(Object.assign({}, actionsOption.option), { describe: "A list of action names or patterns to include in the output. Can include '*' wildcards." }) });
42041
+ const compileTagsOption = Object.assign(Object.assign({}, tagsOption), { option: Object.assign(Object.assign({}, tagsOption.option), { describe: "A list of tags to filter the output to." }) });
42042
+ const compileIncludeDepsOption = Object.assign(Object.assign({}, includeDepsOption), { option: Object.assign(Object.assign({}, includeDepsOption.option), { describe: "If set, dependencies of selected actions are also included in the output." }) });
42043
+ const compileIncludeDependentsOption = Object.assign(Object.assign({}, includeDependentsOption), { option: Object.assign(Object.assign({}, includeDependentsOption.option), { describe: "If set, dependents (downstream) of selected actions are also included in the output." }) });
42044
+ const credentialsOption = option("credentials", {
42045
+ describe: "The location of the credentials JSON file to use.",
42046
+ default: CREDENTIALS_FILENAME
42047
+ }, (argv) => {
42048
+ getCredentialsPath(argv[projectDirOption.name], argv.credentials);
42049
+ });
42050
+ const jsonOutputOption = option("json", {
42051
+ describe: "Outputs a JSON representation of the compiled project or test results.",
42052
+ type: "boolean",
42053
+ default: false
42054
+ });
42055
+ const dotOutputOption = option("dot", {
42056
+ describe: "Outputs a dot representation of the compiled project.",
42057
+ type: "boolean",
42058
+ default: false
42059
+ }, (argv) => {
42060
+ if (argv.json && argv.dot) {
42061
+ throw new Error("Arguments --json and --dot are mutually exclusive.");
42077
42062
  }
42078
- };
42079
- const icebergOption = {
42080
- name: "iceberg",
42081
- option: {
42082
- describe: "Initialize the project with workflow-level Iceberg tables configuration.",
42083
- type: "boolean",
42084
- default: false,
42085
- },
42086
- };
42087
- const warehouseOption = {
42088
- name: "warehouse",
42089
- option: {
42090
- describe: "Target warehouse for the new project.",
42091
- type: "string",
42092
- choices: ["bigquery", "postgres", "supabase"],
42093
- default: "supabase"
42063
+ });
42064
+ const timeoutOption = option("timeout", {
42065
+ describe: "Duration to allow project compilation to complete. Examples: '1s', '10m', etc.",
42066
+ type: "string",
42067
+ default: null,
42068
+ coerce: (rawTimeoutString) => rawTimeoutString ? parseDuration__default["default"](rawTimeoutString) : null
42069
+ });
42070
+ const jobPrefixOption = option("job-prefix", {
42071
+ describe: "Adds an additional prefix in the form of `sqlanvil-${jobPrefix}-`.",
42072
+ type: "string",
42073
+ default: null
42074
+ });
42075
+ const bigqueryJobLabelsOption = option("job-labels", {
42076
+ describe: "Comma-separated list of labels to add to BigQuery jobs, e.g. 'key1=val1,key2=val2'.",
42077
+ type: "string",
42078
+ coerce: (raw) => {
42079
+ const labels = {};
42080
+ raw === null || raw === void 0 ? void 0 : raw.split(",").forEach(kv => {
42081
+ if (!kv) {
42082
+ return;
42083
+ }
42084
+ const [key, ...rest] = kv.split("=");
42085
+ labels[key] = rest.join("=") || "";
42086
+ });
42087
+ return labels;
42094
42088
  }
42095
- };
42089
+ });
42090
+ const quietCompileOption = option("quiet", {
42091
+ describe: "Less verbose compilation output. Example usage: 'sqlanvil compile --quiet'",
42092
+ type: "boolean",
42093
+ default: false
42094
+ });
42095
+ const icebergOption = option("iceberg", {
42096
+ describe: "Initialize the project with workflow-level Iceberg tables configuration.",
42097
+ type: "boolean",
42098
+ default: false
42099
+ });
42100
+ const warehouseOption = option("warehouse", {
42101
+ describe: "Target warehouse for the new project.",
42102
+ type: "string",
42103
+ choices: ["bigquery", "postgres", "supabase"],
42104
+ default: "supabase"
42105
+ });
42096
42106
  const testConnectionOptionName = "test-connection";
42097
42107
  const watchOptionName = "watch";
42098
42108
  const verboseOptionName = "verbose";
@@ -42111,7 +42121,7 @@ function runCli() {
42111
42121
  description: "Show help. If [command] is specified, the help is for the given command.",
42112
42122
  positionalOptions: [],
42113
42123
  options: [],
42114
- processFn: async (argv) => {
42124
+ processFn: async () => {
42115
42125
  return 0;
42116
42126
  }
42117
42127
  },
@@ -42121,33 +42131,25 @@ function runCli() {
42121
42131
  description: "Create a new sqlanvil project (BigQuery, Postgres, or Supabase).",
42122
42132
  positionalOptions: [
42123
42133
  projectDirOption,
42124
- {
42125
- name: ProjectConfigOptions.defaultDatabase.name,
42126
- option: {
42127
- describe: "The default database to use, equivalent to Google Cloud Project ID."
42128
- },
42129
- check: (argv) => {
42130
- const warehouse = argv[warehouseOption.name] || "bigquery";
42131
- if (warehouse === "bigquery" && !argv[ProjectConfigOptions.defaultDatabase.name]) {
42132
- throw new Error(`The ${ProjectConfigOptions.defaultDatabase.name} positional argument is ` +
42133
- `required for BigQuery projects. Use "sqlanvil help init" for more info.`);
42134
- }
42134
+ positionalOption(ProjectConfigOptions.defaultDatabase.name, {
42135
+ describe: "The default database to use, equivalent to Google Cloud Project ID."
42136
+ }, (argv) => {
42137
+ const warehouse = argv[warehouseOption.name] || "bigquery";
42138
+ if (warehouse === "bigquery" && !argv[ProjectConfigOptions.defaultDatabase.name]) {
42139
+ throw new Error(`The ${ProjectConfigOptions.defaultDatabase.name} positional argument is ` +
42140
+ `required for BigQuery projects. Use "sqlanvil help init" for more info.`);
42135
42141
  }
42136
- },
42137
- {
42138
- name: ProjectConfigOptions.defaultLocation.name,
42139
- option: {
42140
- describe: "The default location to use. See " +
42141
- "https://cloud.google.com/bigquery/docs/locations for supported values."
42142
- },
42143
- check: (argv) => {
42144
- const warehouse = argv[warehouseOption.name] || "bigquery";
42145
- if (warehouse === "bigquery" && !argv[ProjectConfigOptions.defaultLocation.name]) {
42146
- throw new Error(`The ${ProjectConfigOptions.defaultLocation.name} positional argument is ` +
42147
- `required for BigQuery projects. Use "sqlanvil help init" for more info.`);
42148
- }
42142
+ }),
42143
+ positionalOption(ProjectConfigOptions.defaultLocation.name, {
42144
+ describe: "The default location to use. See " +
42145
+ "https://cloud.google.com/bigquery/docs/locations for supported values."
42146
+ }, (argv) => {
42147
+ const warehouse = argv[warehouseOption.name] || "bigquery";
42148
+ if (warehouse === "bigquery" && !argv[ProjectConfigOptions.defaultLocation.name]) {
42149
+ throw new Error(`The ${ProjectConfigOptions.defaultLocation.name} positional argument is ` +
42150
+ `required for BigQuery projects. Use "sqlanvil help init" for more info.`);
42149
42151
  }
42150
- }
42152
+ })
42151
42153
  ],
42152
42154
  options: [warehouseOption, icebergOption],
42153
42155
  processFn: async (argv) => {
@@ -42188,14 +42190,11 @@ function runCli() {
42188
42190
  `accessing BigQuery.`,
42189
42191
  positionalOptions: [projectDirMustExistOption],
42190
42192
  options: [
42191
- {
42192
- name: testConnectionOptionName,
42193
- option: {
42194
- describe: "If true, a test query will be run using your final credentials.",
42195
- type: "boolean",
42196
- default: true
42197
- }
42198
- }
42193
+ option(testConnectionOptionName, {
42194
+ describe: "If true, a test query will be run using your final credentials.",
42195
+ type: "boolean",
42196
+ default: true
42197
+ })
42199
42198
  ],
42200
42199
  processFn: async (argv) => {
42201
42200
  const finalCredentials = getBigQueryCredentials();
@@ -42231,36 +42230,34 @@ function runCli() {
42231
42230
  description: "Compile the sqlanvil project. Produces JSON output describing the non-executable graph.",
42232
42231
  positionalOptions: [projectDirMustExistOption],
42233
42232
  options: [
42234
- {
42235
- name: watchOptionName,
42236
- option: {
42237
- describe: "Whether to watch the changes in the project directory.",
42238
- type: "boolean",
42239
- default: false
42240
- }
42241
- },
42233
+ option(watchOptionName, {
42234
+ describe: "Whether to watch the changes in the project directory.",
42235
+ type: "boolean",
42236
+ default: false
42237
+ }),
42242
42238
  jsonOutputOption,
42243
42239
  dotOutputOption,
42244
42240
  timeoutOption,
42245
42241
  quietCompileOption,
42246
- {
42247
- name: verboseOptionName,
42248
- option: {
42249
- describe: "Enable verbose compilation output. Example usage: 'sqlanvil compile --verbose'",
42250
- type: "boolean",
42251
- default: false
42252
- },
42253
- check: (argv) => {
42254
- if (argv.quiet && argv.verbose) {
42255
- throw new Error("Arguments --verbose and --quiet are mutually exclusive.");
42256
- }
42242
+ compileActionsOption,
42243
+ compileTagsOption,
42244
+ compileIncludeDepsOption,
42245
+ compileIncludeDependentsOption,
42246
+ option(verboseOptionName, {
42247
+ describe: "Enable verbose compilation output. Example usage: 'sqlanvil compile --verbose'",
42248
+ type: "boolean",
42249
+ default: false
42250
+ }, (argv) => {
42251
+ if (argv.quiet && argv.verbose) {
42252
+ throw new Error("Arguments --verbose and --quiet are mutually exclusive.");
42257
42253
  }
42258
- },
42254
+ }),
42259
42255
  ...ProjectConfigOptions.allYargsOptions
42260
42256
  ],
42261
42257
  processFn: async (argv) => {
42262
42258
  const projectDir = argv[projectDirMustExistOption.name];
42263
42259
  async function compileAndPrint() {
42260
+ var _a, _b;
42264
42261
  let outputType = compiledGraphOutputType.Summary;
42265
42262
  if (argv[jsonOutputOption.name]) {
42266
42263
  outputType = compiledGraphOutputType.Json;
@@ -42277,7 +42274,16 @@ function runCli() {
42277
42274
  timeoutMillis: argv[timeoutOption.name] || undefined,
42278
42275
  verbose: argv[verboseOptionName] || false
42279
42276
  });
42280
- printCompiledGraph(compiledGraph, outputType, argv[quietCompileOption.name]);
42277
+ const hasSelector = ((_a = argv[actionsOption.name]) === null || _a === void 0 ? void 0 : _a.length) > 0 || ((_b = argv[tagsOption.name]) === null || _b === void 0 ? void 0 : _b.length) > 0;
42278
+ const outputGraph = hasSelector && !compiledGraphHasErrors(compiledGraph)
42279
+ ? prune(compiledGraph, {
42280
+ actions: argv[actionsOption.name],
42281
+ tags: argv[tagsOption.name],
42282
+ includeDependencies: argv[includeDepsOption.name],
42283
+ includeDependents: argv[includeDependentsOption.name]
42284
+ })
42285
+ : compiledGraph;
42286
+ printCompiledGraph(outputGraph, outputType, argv[quietCompileOption.name]);
42281
42287
  if (compiledGraphHasErrors(compiledGraph)) {
42282
42288
  print("");
42283
42289
  printCompiledGraphErrors(compiledGraph.graphErrors, argv[quietCompileOption.name]);
@@ -42389,28 +42395,19 @@ function runCli() {
42389
42395
  description: "Run the sqlanvil project.",
42390
42396
  positionalOptions: [projectDirMustExistOption],
42391
42397
  options: [
42392
- {
42393
- name: dryRunOptionName,
42394
- option: {
42395
- describe: "If set, BigQuery will validate the run SQL without applying changes to the warehouse.",
42396
- type: "boolean"
42397
- }
42398
- },
42399
- {
42400
- name: runTestsOptionName,
42401
- option: {
42402
- describe: "If set, the project's unit tests are required to pass before running the project.",
42403
- type: "boolean"
42404
- }
42405
- },
42406
- {
42407
- name: actionRetryLimitName,
42408
- option: {
42409
- describe: "If set, idempotent actions will be retried up to the limit.",
42410
- type: "number",
42411
- default: 0
42412
- }
42413
- },
42398
+ option(dryRunOptionName, {
42399
+ describe: "If set, BigQuery will validate the run SQL without applying changes to the warehouse.",
42400
+ type: "boolean"
42401
+ }),
42402
+ option(runTestsOptionName, {
42403
+ describe: "If set, the project's unit tests are required to pass before running the project.",
42404
+ type: "boolean"
42405
+ }),
42406
+ option(actionRetryLimitName, {
42407
+ describe: "If set, idempotent actions will be retried up to the limit.",
42408
+ type: "number",
42409
+ default: 0
42410
+ }),
42414
42411
  actionsOption,
42415
42412
  credentialsOption,
42416
42413
  fullRefreshOption,
@@ -42534,14 +42531,11 @@ function runCli() {
42534
42531
  positionalOptions: [projectDirMustExistOption],
42535
42532
  options: [
42536
42533
  actionsOption,
42537
- {
42538
- name: checkOptionName,
42539
- option: {
42540
- describe: "Check if files are formatted correctly without modifying them.",
42541
- type: "boolean",
42542
- default: false
42543
- }
42544
- }
42534
+ option(checkOptionName, {
42535
+ describe: "Check if files are formatted correctly without modifying them.",
42536
+ type: "boolean",
42537
+ default: false
42538
+ })
42545
42539
  ],
42546
42540
  processFn: async (argv) => {
42547
42541
  let actions = ["{definitions,includes}/**/*.{js,sqlx}"];
@@ -42602,24 +42596,19 @@ function runCli() {
42602
42596
  format: `introspect <connection> <tableRef> [${projectDirOption.name}]`,
42603
42597
  description: "Read a source table's schema from a connection and write a declaration .sqlx with columnTypes.",
42604
42598
  positionalOptions: [
42605
- {
42606
- name: "connection",
42607
- option: { describe: "Connection name (from workflow_settings.yaml connections)." }
42608
- },
42609
- {
42610
- name: "tableRef",
42611
- option: { describe: "Source table as schema.table (or just table)." }
42612
- },
42599
+ positionalOption("connection", {
42600
+ describe: "Connection name (from workflow_settings.yaml connections)."
42601
+ }),
42602
+ positionalOption("tableRef", {
42603
+ describe: "Source table as schema.table (or just table)."
42604
+ }),
42613
42605
  projectDirOption
42614
42606
  ],
42615
42607
  options: [
42616
- {
42617
- name: "output",
42618
- option: {
42619
- describe: "File to write the declaration .sqlx to. Prints to stdout if omitted.",
42620
- type: "string"
42621
- }
42622
- }
42608
+ option("output", {
42609
+ describe: "File to write the declaration .sqlx to. Prints to stdout if omitted.",
42610
+ type: "string"
42611
+ })
42623
42612
  ],
42624
42613
  processFn: async (argv) => {
42625
42614
  const projectDir = argv[projectDirOption.name];
@@ -42693,93 +42682,62 @@ class ProjectConfigOptions {
42693
42682
  return projectConfigOptions;
42694
42683
  }
42695
42684
  }
42696
- ProjectConfigOptions.defaultDatabase = {
42697
- name: "default-database",
42698
- option: {
42699
- describe: "The default database to use, equivalent to Google Cloud Project ID. If unset, " +
42700
- "the value from workflow_settings.yaml is used.",
42701
- type: "string"
42702
- }
42703
- };
42704
- ProjectConfigOptions.defaultSchema = {
42705
- name: "default-schema",
42706
- option: {
42707
- describe: "Override for the default schema name. If unset, the value from workflow_settings.yaml is used."
42708
- }
42709
- };
42710
- ProjectConfigOptions.defaultLocation = {
42711
- name: "default-location",
42712
- option: {
42713
- describe: "The default location to use. See " +
42714
- "https://cloud.google.com/bigquery/docs/locations for supported values. If unset, the " +
42715
- "value from workflow_settings.yaml is used."
42716
- }
42717
- };
42718
- ProjectConfigOptions.assertionSchema = {
42719
- name: "assertion-schema",
42720
- option: {
42721
- describe: "Default assertion schema. If unset, the value from workflow_settings.yaml is used."
42722
- }
42723
- };
42724
- ProjectConfigOptions.databaseSuffix = {
42725
- name: "database-suffix",
42726
- option: {
42727
- describe: "Default assertion schema. If unset, the value from workflow_settings.yaml is used."
42728
- }
42729
- };
42730
- ProjectConfigOptions.vars = {
42731
- name: "vars",
42732
- option: {
42733
- describe: "Override for variables to inject via '--vars=someKey=someValue,a=b', referenced by " +
42734
- "`sqlanvil.projectConfig.vars.someValue`. If unset, the value from workflow_settings.yaml is used.",
42735
- type: "string",
42736
- default: null,
42737
- coerce: (rawVarsString) => {
42738
- const variables = {};
42739
- rawVarsString === null || rawVarsString === void 0 ? void 0 : rawVarsString.split(",").forEach(keyValueStr => {
42740
- const [key, value] = keyValueStr.split("=");
42741
- variables[key] = value;
42742
- });
42743
- return variables;
42744
- }
42745
- }
42746
- };
42747
- ProjectConfigOptions.schemaSuffix = {
42748
- name: "schema-suffix",
42749
- option: {
42750
- describe: "A suffix to be appended to output schema names. If unset, the value from workflow_settings.yaml " +
42751
- "is used."
42752
- },
42753
- check: (argv) => {
42754
- if (argv[ProjectConfigOptions.schemaSuffix.name] &&
42755
- !/^[a-zA-Z_0-9]+$/.test(argv[ProjectConfigOptions.schemaSuffix.name])) {
42756
- throw new Error(`--${ProjectConfigOptions.schemaSuffix.name} should contain only ` +
42757
- `alphanumeric characters and/or underscores.`);
42758
- }
42759
- }
42760
- };
42761
- ProjectConfigOptions.tablePrefix = {
42762
- name: "table-prefix",
42763
- option: {
42764
- describe: "Adds a prefix for all table names. If unset, the value from workflow_settings.yaml is used."
42765
- }
42766
- };
42767
- ProjectConfigOptions.disableAssertions = {
42768
- name: "disable-assertions",
42769
- option: {
42770
- describe: "Disables all assertions including built-in assertions (uniqueKey, nonNull, rowConditions) and manual assertions (type: assertion).",
42771
- type: "boolean",
42772
- default: false
42685
+ ProjectConfigOptions.defaultDatabase = option("default-database", {
42686
+ describe: "The default database to use, equivalent to Google Cloud Project ID. If unset, " +
42687
+ "the value from workflow_settings.yaml is used.",
42688
+ type: "string"
42689
+ });
42690
+ ProjectConfigOptions.defaultSchema = option("default-schema", {
42691
+ describe: "Override for the default schema name. If unset, the value from workflow_settings.yaml is used."
42692
+ });
42693
+ ProjectConfigOptions.defaultLocation = option("default-location", {
42694
+ describe: "The default location to use. See " +
42695
+ "https://cloud.google.com/bigquery/docs/locations for supported values. If unset, the " +
42696
+ "value from workflow_settings.yaml is used."
42697
+ });
42698
+ ProjectConfigOptions.assertionSchema = option("assertion-schema", {
42699
+ describe: "Default assertion schema. If unset, the value from workflow_settings.yaml is used."
42700
+ });
42701
+ ProjectConfigOptions.databaseSuffix = option("database-suffix", {
42702
+ describe: "Default assertion schema. If unset, the value from workflow_settings.yaml is used."
42703
+ });
42704
+ ProjectConfigOptions.vars = option("vars", {
42705
+ describe: "Override for variables to inject via '--vars=someKey=someValue,a=b', referenced by " +
42706
+ "`sqlanvil.projectConfig.vars.someValue`. If unset, the value from workflow_settings.yaml is used.",
42707
+ type: "string",
42708
+ default: null,
42709
+ coerce: (rawVarsString) => {
42710
+ const variables = {};
42711
+ rawVarsString === null || rawVarsString === void 0 ? void 0 : rawVarsString.split(",").forEach(keyValueStr => {
42712
+ const [key, value] = keyValueStr.split("=");
42713
+ variables[key] = value;
42714
+ });
42715
+ return variables;
42773
42716
  }
42774
- };
42775
- ProjectConfigOptions.defaultReservation = {
42776
- name: "default-reservation",
42777
- option: {
42778
- describe: "The default BigQuery reservation to use for execution. If unset, the value from " +
42779
- "workflow_settings.yaml is used. If neither is set, default BigQuery behavior applies.",
42780
- type: "string"
42717
+ });
42718
+ ProjectConfigOptions.schemaSuffix = option("schema-suffix", {
42719
+ describe: "A suffix to be appended to output schema names. If unset, the value from workflow_settings.yaml " +
42720
+ "is used."
42721
+ }, (argv) => {
42722
+ if (argv[ProjectConfigOptions.schemaSuffix.name] &&
42723
+ !/^[a-zA-Z_0-9]+$/.test(argv[ProjectConfigOptions.schemaSuffix.name])) {
42724
+ throw new Error(`--${ProjectConfigOptions.schemaSuffix.name} should contain only ` +
42725
+ `alphanumeric characters and/or underscores.`);
42781
42726
  }
42782
- };
42727
+ });
42728
+ ProjectConfigOptions.tablePrefix = option("table-prefix", {
42729
+ describe: "Adds a prefix for all table names. If unset, the value from workflow_settings.yaml is used."
42730
+ });
42731
+ ProjectConfigOptions.disableAssertions = option("disable-assertions", {
42732
+ describe: "Disables all assertions including built-in assertions (uniqueKey, nonNull, rowConditions) and manual assertions (type: assertion).",
42733
+ type: "boolean",
42734
+ default: false
42735
+ });
42736
+ ProjectConfigOptions.defaultReservation = option("default-reservation", {
42737
+ describe: "The default BigQuery reservation to use for execution. If unset, the value from " +
42738
+ "workflow_settings.yaml is used. If neither is set, default BigQuery behavior applies.",
42739
+ type: "string"
42740
+ });
42783
42741
  ProjectConfigOptions.allYargsOptions = [
42784
42742
  ProjectConfigOptions.defaultDatabase,
42785
42743
  ProjectConfigOptions.defaultSchema,
package/package.json CHANGED
@@ -61,7 +61,7 @@
61
61
  "bin": {
62
62
  "sqlanvil": "bundle.js"
63
63
  },
64
- "version": "1.2.0",
64
+ "version": "1.4.0",
65
65
  "name": "@sqlanvil/cli",
66
66
  "description": "sqlanvil command line interface.",
67
67
  "main": "bundle.js"
package/worker_bundle.js CHANGED
@@ -12665,6 +12665,7 @@ const sqlanvil = $root.sqlanvil = (() => {
12665
12665
  * @interface IBound
12666
12666
  * @property {string|null} [name] Bound name
12667
12667
  * @property {string|null} [values] Bound values
12668
+ * @property {sqlanvil.PostgresOptions.IPartition|null} [subPartition] Bound subPartition
12668
12669
  */
12669
12670
 
12670
12671
  /**
@@ -12698,6 +12699,14 @@ const sqlanvil = $root.sqlanvil = (() => {
12698
12699
  */
12699
12700
  Bound.prototype.values = "";
12700
12701
 
12702
+ /**
12703
+ * Bound subPartition.
12704
+ * @member {sqlanvil.PostgresOptions.IPartition|null|undefined} subPartition
12705
+ * @memberof sqlanvil.PostgresOptions.Partition.Bound
12706
+ * @instance
12707
+ */
12708
+ Bound.prototype.subPartition = null;
12709
+
12701
12710
  /**
12702
12711
  * Creates a new Bound instance using the specified properties.
12703
12712
  * @function create
@@ -12726,6 +12735,8 @@ const sqlanvil = $root.sqlanvil = (() => {
12726
12735
  writer.uint32(/* id 1, wireType 2 =*/10).string(message.name);
12727
12736
  if (message.values != null && Object.hasOwnProperty.call(message, "values"))
12728
12737
  writer.uint32(/* id 2, wireType 2 =*/18).string(message.values);
12738
+ if (message.subPartition != null && Object.hasOwnProperty.call(message, "subPartition"))
12739
+ $root.sqlanvil.PostgresOptions.Partition.encode(message.subPartition, writer.uint32(/* id 3, wireType 2 =*/26).fork()).ldelim();
12729
12740
  return writer;
12730
12741
  };
12731
12742
 
@@ -12770,6 +12781,10 @@ const sqlanvil = $root.sqlanvil = (() => {
12770
12781
  message.values = reader.string();
12771
12782
  break;
12772
12783
  }
12784
+ case 3: {
12785
+ message.subPartition = $root.sqlanvil.PostgresOptions.Partition.decode(reader, reader.uint32());
12786
+ break;
12787
+ }
12773
12788
  default:
12774
12789
  reader.skipType(tag & 7);
12775
12790
  break;
@@ -12811,6 +12826,11 @@ const sqlanvil = $root.sqlanvil = (() => {
12811
12826
  if (message.values != null && message.hasOwnProperty("values"))
12812
12827
  if (!$util.isString(message.values))
12813
12828
  return "values: string expected";
12829
+ if (message.subPartition != null && message.hasOwnProperty("subPartition")) {
12830
+ let error = $root.sqlanvil.PostgresOptions.Partition.verify(message.subPartition);
12831
+ if (error)
12832
+ return "subPartition." + error;
12833
+ }
12814
12834
  return null;
12815
12835
  };
12816
12836
 
@@ -12830,6 +12850,11 @@ const sqlanvil = $root.sqlanvil = (() => {
12830
12850
  message.name = String(object.name);
12831
12851
  if (object.values != null)
12832
12852
  message.values = String(object.values);
12853
+ if (object.subPartition != null) {
12854
+ if (typeof object.subPartition !== "object")
12855
+ throw TypeError(".sqlanvil.PostgresOptions.Partition.Bound.subPartition: object expected");
12856
+ message.subPartition = $root.sqlanvil.PostgresOptions.Partition.fromObject(object.subPartition);
12857
+ }
12833
12858
  return message;
12834
12859
  };
12835
12860
 
@@ -12849,11 +12874,14 @@ const sqlanvil = $root.sqlanvil = (() => {
12849
12874
  if (options.defaults) {
12850
12875
  object.name = "";
12851
12876
  object.values = "";
12877
+ object.subPartition = null;
12852
12878
  }
12853
12879
  if (message.name != null && message.hasOwnProperty("name"))
12854
12880
  object.name = message.name;
12855
12881
  if (message.values != null && message.hasOwnProperty("values"))
12856
12882
  object.values = message.values;
12883
+ if (message.subPartition != null && message.hasOwnProperty("subPartition"))
12884
+ object.subPartition = $root.sqlanvil.PostgresOptions.Partition.toObject(message.subPartition, options);
12857
12885
  return object;
12858
12886
  };
12859
12887