UNPKG

@dataform/core

Version:
15 lines (14 loc) 535 kB
// Copyright 2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. (()=>{var __webpack_modules__={8142:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(2549);var o;function i(e,t){return e===o.SHOW_DOCS_LINK?` See https://dataform-co.github.io/dataform/docs/configs-reference#${t.getTypeUrl("").replace(/\./g,"-").replace(/\//,"")} for allowed properties.`:""}function a(e,t={}){return function(e){return n.util.base64.encode(e,0,e.length)}(e.encode(e.create(t)).finish())}!function(e){e[e.DEFAULT=0]="DEFAULT",e[e.SUGGEST_REPORTING_TO_DATAFORM_TEAM=1]="SUGGEST_REPORTING_TO_DATAFORM_TEAM",e[e.SHOW_DOCS_LINK=2]="SHOW_DOCS_LINK"}(o=t.VerifyProtoErrorBehaviour||(t.VerifyProtoErrorBehaviour={})),t.verifyObjectMatchesProto=function(e,t,r=o.DEFAULT){if(Array.isArray(t))throw ReferenceError("Expected a top-level object, but found an array");const n=e.create(t);return function t(n,a){Object.entries(n).forEach((([n,s])=>{const l=a[n];if(typeof l!=typeof s){if(Array.isArray(s)&&0===s.length)return;if(!s)throw ReferenceError(`Unexpected empty value for "${n}".`+i(r,e));if("object"==typeof s&&0===Object.keys(s).length)return;if(r===o.SUGGEST_REPORTING_TO_DATAFORM_TEAM)throw ReferenceError(`Unexpected property "${n}" for "${e.getTypeUrl("").replace("/","")}", please report this to the Dataform team at https://github.com/dataform-co/dataform/issues.`);throw ReferenceError(`Unexpected property "${n}", or property value type of "${typeof s}" is incorrect.`+i(r,e))}"object"==typeof s&&t(s,l)}))}(t,e.toObject(n)),n},t.encode64=a,t.decode64=function(e,t){return t?e.decode(function(e){const t=new Uint8Array(n.util.base64.length(e));return n.util.base64.decode(e,t,0),t}(t)):e.create()},t.equals=function(e,t,r){return a(e,t)===a(e,r)},t.deepClone=function(e,t){return e.fromObject(e.toObject(e.create(t)))}},3187:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.JSONObjectStringifier=class{stringify(e){return JSON.stringify(Object.keys(e).sort().reduce(((t,r)=>Object.assign(Object.assign({},t),{[r]:e[r]})),{}))}parse(e){return JSON.parse(e)}}},9350:function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(t,"__esModule",{value:!0});const o=r(8142),i=r(3186),a=n(r(6203)),s=r(9211),l=r(8869);class c extends i.ActionBuilder{constructor(e,t,r){if(super(e),this.proto=l.dataform.Assertion.create(),this.session=e,!t)return;const n=this.verifyConfig(t);n.name||(n.name=a.basename(n.filename));const o=s.actionConfigToCompiledGraphTarget(n);return this.proto.target=this.applySessionToTarget(o,e.projectConfig,n.filename,{validateTarget:!0,useDefaultAssertionDataset:!0}),this.proto.canonicalTarget=this.applySessionToTarget(o,e.canonicalProjectConfig,void 0,{validateTarget:!1,useDefaultAssertionDataset:!0}),r&&(n.filename=s.resolveActionsConfigFilename(n.filename,r),this.query(s.nativeRequire(n.filename).query)),n.dependencyTargets&&this.dependencies(n.dependencyTargets.map((e=>s.configTargetToCompiledGraphTarget(l.dataform.ActionConfig.Target.create(e))))),n.hermetic&&this.hermetic(n.hermetic),n.disabled&&this.disabled(),n.tags&&this.tags(n.tags),n.description&&this.description(n.description),n.project&&this.database(n.project),n.dataset&&this.schema(n.dataset),n.filename&&(this.proto.fileName=n.filename),this}query(e){return this.contextableQuery=e,this}dependencies(e){return(Array.isArray(e)?e:[e]).forEach((e=>{const t=s.resolvableAsTarget(e);this.session.actionAssertionMap.set(t,this),this.proto.dependencyTargets.push(t)})),this}hermetic(e){this.proto.hermeticity=e?l.dataform.ActionHermeticity.HERMETIC:l.dataform.ActionHermeticity.NON_HERMETIC}disabled(e=!0){return this.proto.disabled=e,this}tags(e){return("string"==typeof e?[e]:e).forEach((e=>{this.proto.tags.indexOf(e)<0&&this.proto.tags.push(e)})),this}description(e){return this.proto.actionDescriptor={description:e},this}database(e){return this.proto.target=this.applySessionToTarget(l.dataform.Target.create(Object.assign(Object.assign({},this.proto.target),{database:e})),this.session.projectConfig,this.proto.fileName,{validateTarget:!0,useDefaultAssertionDataset:!0}),this}schema(e){return this.proto.target=this.applySessionToTarget(l.dataform.Target.create(Object.assign(Object.assign({},this.proto.target),{schema:e})),this.session.projectConfig,this.proto.fileName,{validateTarget:!0,useDefaultAssertionDataset:!0}),this}getFileName(){return this.proto.fileName}getTarget(){return l.dataform.Target.create(this.proto.target)}getParentAction(){return l.dataform.Target.create(this.proto.parentAction)}setParentAction(e){this.proto.parentAction=e}compile(){const e=new u(this);return this.proto.query=e.apply(this.contextableQuery),s.validateQueryString(this.session,this.proto.query,this.proto.fileName),o.verifyObjectMatchesProto(l.dataform.Assertion,this.proto,o.VerifyProtoErrorBehaviour.SUGGEST_REPORTING_TO_DATAFORM_TEAM)}verifyConfig(e){return e.dependencies&&(e.dependencyTargets=e.dependencies.map((e=>s.resolvableAsActionConfigTarget(e))),delete e.dependencies),e.database&&(e.project=e.database,delete e.database),e.schema&&(e.dataset=e.schema,delete e.schema),e.fileName&&(e.filename=e.fileName,delete e.fileName),e.type&&delete e.type,o.verifyObjectMatchesProto(l.dataform.ActionConfig.AssertionConfig,e,o.VerifyProtoErrorBehaviour.SHOW_DOCS_LINK)}}t.Assertion=c;class u{constructor(e){this.assertion=e}self(){return this.resolve(this.assertion.getTarget())}name(){return this.assertion.session.finalizeName(this.assertion.getTarget().name)}ref(e,...t){return e=s.toResolvable(e,t),s.resolvableAsTarget(e)?(this.assertion.dependencies(e),this.resolve(e)):(this.assertion.session.compileError(new Error("Action name is not specified")),"")}resolve(e,...t){return this.assertion.session.resolve(e,...t)}schema(){return this.assertion.session.finalizeSchema(this.assertion.getTarget().schema)}database(){return this.assertion.getTarget().database?this.assertion.session.finalizeDatabase(this.assertion.getTarget().database):(this.assertion.session.compileError(new Error("Warehouse does not support multiple databases")),"")}dependencies(e){return this.assertion.dependencies(e),""}tags(e){return this.assertion.tags(e),""}when(e,t,r=""){return e?t:r}apply(e){return"function"==typeof e?e(this):e}}t.AssertionContext=u},6014:function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(t,"__esModule",{value:!0});const o=r(7210),i=r(8142),a=r(3186),s=n(r(6203)),l=r(9211),c=r(8869);class u extends a.ActionBuilder{constructor(e,t,r){if(super(e),this.proto=c.dataform.DataPreparation.create(),this.session=e,t.name)t.name.endsWith(".dp")&&t.filename.endsWith(".dp.sqlx")&&(t.name=t.name.slice(0,-3));else{const e=s.filename(t.filename);if(e.toLowerCase().endsWith(".dp.yaml")||e.toLowerCase().endsWith(".dp.sqlx"))t.name=e.slice(0,-8);else{if(!e.toLowerCase().endsWith(".yaml")&&!e.toLowerCase().endsWith(".sqlx"))throw new Error("Only YAML and SQLX files are supported");t.name=e.slice(0,-5)}}const n=s.fileExtension(t.filename);"yaml"===n?this.configureYaml(e,t,r):"sqlx"===n&&this.configureSqlx(e,t)}config(e){return e.database&&this.database(e.database),e.project&&this.database(e.project),e.schema&&this.schema(e.schema),e.dataset&&this.schema(e.dataset),this}query(e){return this.contextableQuery=e,this}dependencies(e){return(Array.isArray(e)?e:[e]).forEach((e=>this.proto.dependencyTargets.push(l.checkAssertionsForDependency(this,e)))),this}getFileName(){return this.proto.fileName}getTarget(){return c.dataform.Target.create(this.proto.target)}compile(){if(null!=this.contextableQuery){const e=new p(this);this.proto.query=e.apply(this.contextableQuery).trim(),l.validateQueryString(this.session,this.proto.query,this.proto.fileName)}return i.verifyObjectMatchesProto(c.dataform.DataPreparation,this.proto,i.VerifyProtoErrorBehaviour.SUGGEST_REPORTING_TO_DATAFORM_TEAM)}database(e){return this.proto.target=this.applySessionToTarget(c.dataform.Target.create(Object.assign(Object.assign({},this.proto.target),{database:e})),this.session.projectConfig,this.proto.fileName,{validateTarget:!0}),this}schema(e){return this.proto.target=this.applySessionToTarget(c.dataform.Target.create(Object.assign(Object.assign({},this.proto.target),{schema:e})),this.session.projectConfig,this.proto.fileName,{validateTarget:!0}),this}configureYamlWithoutTargets(e,t,r){const n=c.dataform.Target.create({name:r.name});this.proto.target=this.finalizeTarget(this.applySessionToTarget(n,t.projectConfig,r.filename,{validateTarget:!0})),this.proto.targets=[this.proto.target],this.proto.canonicalTarget=this.applySessionToTarget(n,t.canonicalProjectConfig),this.proto.canonicalTargets=[this.proto.canonicalTarget];const i=this.applySessionToDataPreparationContents(e);this.proto.dataPreparationYaml=o.dump(i)}configureYamlWithTargets(e,t,r,n){const i=e.map((e=>this.applySessionToTarget(e,r.projectConfig,n.filename,{validateTarget:!0})));this.proto.targets=i.map((e=>this.finalizeTarget(e))),this.proto.canonicalTargets=e.map((e=>this.applySessionToTarget(e,r.canonicalProjectConfig)));const a=this.applySessionToDataPreparationContents(t);this.proto.dataPreparationYaml=o.dump(a),this.proto.target=i[0],this.proto.canonicalTarget=this.proto.canonicalTargets[0]}applySessionToDataPreparationContents(e){var t;if(!e)return e;const r=null===(t=e.configuration)||void 0===t?void 0:t.errorTable;return r&&(e.configuration.errorTable=this.applySessionToTableReference(r)),e.nodes&&e.nodes.forEach(((t,r)=>{var n,o;const i=null===(n=t.source)||void 0===n?void 0:n.table;i&&(e.nodes[r].source.table=this.applySessionToTableReference(i));const a=null===(o=t.destination)||void 0===o?void 0:o.table;a&&(e.nodes[r].destination.table=this.applySessionToTableReference(a))})),e}applySessionToTableReference(e){const t={database:e.project,schema:e.dataset,name:e.table},r=this.applySessionToTarget(c.dataform.Target.create(t),this.session.projectConfig);let n={table:this.session.finalizeName(r.name)};return r.schema&&(n=Object.assign({dataset:this.session.finalizeSchema(r.schema)},n)),r.database&&(n=Object.assign({project:this.session.finalizeDatabase(r.database)},n)),n}getTargets(e){const t=[];return e&&e.nodes&&e.nodes.forEach((e=>{var r;const n=null===(r=e.destination)||void 0===r?void 0:r.table;if(n){const e={database:n.project,schema:n.dataset,name:n.table};t.push(c.dataform.Target.create(e))}})),t}configureYaml(e,t,r){t.filename=l.resolveActionsConfigFilename(t.filename,r);const n=l.nativeRequire(t.filename).asJson,o=this.getTargets(n);o.length>0?this.configureYamlWithTargets(o,n,e,t):this.configureYamlWithoutTargets(n,e,t),this.proto.tags=t.tags,t.dependencyTargets&&this.dependencies(t.dependencyTargets.map((e=>l.configTargetToCompiledGraphTarget(c.dataform.ActionConfig.Target.create(e))))),this.proto.fileName=t.filename,t.disabled&&(this.proto.disabled=t.disabled)}configureSqlx(e,t){var r,n;const o=[];if(o.push(l.actionConfigToCompiledGraphTarget(t)),null!=t.errorTable){const e=c.dataform.ActionConfig.DataPreparationConfig.ErrorTableConfig.create(t.errorTable),r=l.actionConfigToCompiledGraphTarget(e);this.proto.errorTableRetentionDays=e.retentionDays,o.push(r)}this.proto.load=this.mapLoadMode(null===(r=t.loadMode)||void 0===r?void 0:r.mode,null===(n=t.loadMode)||void 0===n?void 0:n.incrementalColumn),this.proto.targets=o.map((r=>this.applySessionToTarget(r,e.projectConfig,t.filename,{validateTarget:!0}))).map((e=>this.finalizeTarget(e))),this.proto.target=this.proto.targets[0],this.proto.targets.length>1&&(this.proto.errorTable=this.proto.targets[1]),this.proto.canonicalTargets=o.map((t=>this.applySessionToTarget(t,e.canonicalProjectConfig))),this.proto.canonicalTarget=this.proto.canonicalTargets[0],t.dependencyTargets&&this.dependencies(t.dependencyTargets.map((e=>l.configTargetToCompiledGraphTarget(c.dataform.ActionConfig.Target.create(e))))),this.proto.tags=t.tags,this.proto.fileName=t.filename,t.disabled&&(this.proto.disabled=t.disabled),this.query(l.nativeRequire(t.filename).query)}mapLoadMode(e,t){if(!e)return c.dataform.LoadConfiguration.create({replace:{}});switch(e.toString().toUpperCase()){case"REPLACE_TABLE":return c.dataform.LoadConfiguration.create({replace:{}});case"APPEND":return c.dataform.LoadConfiguration.create({append:{}});case"MAXIMUM":return c.dataform.LoadConfiguration.create({maximum:{columnName:this.validateLoadModeColumnName(t)}});case"UNIQUE":return c.dataform.LoadConfiguration.create({unique:{columnName:this.validateLoadModeColumnName(t)}});default:throw new Error(`LoadMode value "${e}" is not supported`)}}validateLoadModeColumnName(e){if(!e||""===e)throw new Error("columnName is required for MAXIMUM and UNIQUE load modes.");return e}}t.DataPreparation=u;class p{constructor(e,t=!1){this.dataPreparation=e,this.isIncremental=t,this.EXPECT=" /* @@VALIDATION */ WHERE "}config(e){return this.dataPreparation.config(e),""}self(){return this.resolve(this.dataPreparation.getTarget())}name(){return this.dataPreparation.session.finalizeName(this.dataPreparation.getTarget().name)}ref(e,...t){return e=l.toResolvable(e,t),l.resolvableAsTarget(e)?(this.dataPreparation.dependencies(e),this.resolve(e)):(this.dataPreparation.session.compileError(new Error("Action name is not specified")),"")}resolve(e,...t){return this.dataPreparation.session.resolve(e,...t)}schema(){return this.dataPreparation.session.finalizeSchema(this.dataPreparation.getTarget().schema)}database(){return this.dataPreparation.getTarget().database?this.dataPreparation.session.finalizeDatabase(this.dataPreparation.getTarget().database):(this.dataPreparation.session.compileError(new Error("Warehouse does not support multiple databases")),"")}when(e,t,r=""){return e?t:r}incremental(){return!!this.isIncremental}dependencies(e){return this.dataPreparation.dependencies(e),""}apply(e){return"function"==typeof e?e(this):e}}t.DataPreparationContext=p},5502:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(8142),o=r(3186),i=r(299),a=r(9211),s=r(8869);class l extends o.ActionBuilder{constructor(e,t,r){var n;if(super(e),this.proto=s.dataform.Declaration.create(),this.session=e,!t)return;const o=this.verifyConfig(t);if(!o.name)throw Error("Declarations must have a populated 'name' field.");const i=a.actionConfigToCompiledGraphTarget(o);return this.proto.target=this.applySessionToTarget(i,e.projectConfig),this.proto.canonicalTarget=this.applySessionToTarget(i,e.canonicalProjectConfig),o.description&&this.description(o.description),(null===(n=o.columns)||void 0===n?void 0:n.length)&&this.columns(o.columns.map((e=>s.dataform.ActionConfig.ColumnDescriptor.create(e)))),this.proto.fileName=r,this}description(e){return this.proto.actionDescriptor||(this.proto.actionDescriptor={}),this.proto.actionDescriptor.description=e,this}columns(e){return this.proto.actionDescriptor||(this.proto.actionDescriptor={}),this.proto.actionDescriptor.columns=i.ColumnDescriptors.mapConfigProtoToCompilationProto(e),this}getFileName(){return this.proto.fileName}getTarget(){return s.dataform.Target.create(this.proto.target)}compile(){return n.verifyObjectMatchesProto(s.dataform.Declaration,this.proto,n.VerifyProtoErrorBehaviour.SUGGEST_REPORTING_TO_DATAFORM_TEAM)}verifyConfig(e){return e.database&&(e.project=e.database,delete e.database),e.schema&&(e.dataset=e.schema,delete e.schema),e.columns&&(e.columns=i.ColumnDescriptors.mapLegacyObjectToConfigProto(e.columns)),e.type&&delete e.type,n.verifyObjectMatchesProto(s.dataform.ActionConfig.DeclarationConfig,e,n.VerifyProtoErrorBehaviour.SHOW_DOCS_LINK)}}t.Declaration=l},621:function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(t,"__esModule",{value:!0});const o=r(8142),i=r(3186),a=r(2406),s=r(2537),l=r(299),c=n(r(6203)),u=r(9211),p=r(8869);class d extends i.ActionBuilder{constructor(e,t,r){var n;if(super(e),this.dependOnDependencyAssertions=!1,this.contextablePreOps=[],this.contextablePostOps=[],this.proto=p.dataform.Table.create({type:"incremental",enumType:p.dataform.TableType.INCREMENTAL,disabled:!1,tags:[]}),this.uniqueKeyAssertions=[],this.session=e,this.configPath=r,this.unverifiedConfig=Object.assign({},t),!t)return;const o=this.verifyConfig(t);o.name||(o.name=c.basename(o.filename));const i=u.actionConfigToCompiledGraphTarget(o);return this.proto.target=this.applySessionToTarget(i,e.projectConfig,o.filename,{validateTarget:!0}),this.proto.canonicalTarget=this.applySessionToTarget(i,e.canonicalProjectConfig),r&&(o.filename=u.resolveActionsConfigFilename(o.filename,r),this.query(u.nativeRequire(o.filename).query)),o.filename&&(this.proto.fileName=o.filename),o.dependOnDependencyAssertions&&this.setDependOnDependencyAssertions(o.dependOnDependencyAssertions),o.dependencyTargets&&this.dependencies(o.dependencyTargets.map((e=>u.configTargetToCompiledGraphTarget(p.dataform.ActionConfig.Target.create(e))))),void 0!==o.hermetic&&this.hermetic(o.hermetic),o.disabled&&this.disabled(),o.tags&&this.tags(o.tags),o.description&&this.description(o.description),(null===(n=o.columns)||void 0===n?void 0:n.length)&&this.columns(o.columns.map((e=>p.dataform.ActionConfig.ColumnDescriptor.create(e)))),o.project&&this.database(o.project),o.dataset&&this.schema(o.dataset),o.assertions&&this.assertions(p.dataform.ActionConfig.TableAssertionsConfig.create(o.assertions)),o.uniqueKey&&this.uniqueKey(o.uniqueKey),this.protected(o.protected),o.preOperations&&this.preOps(o.preOperations),o.postOperations&&this.postOps(o.postOperations),this.bigquery({partitionBy:o.partitionBy,clusterBy:o.clusterBy,updatePartitionFilter:o.updatePartitionFilter,labels:o.labels,partitionExpirationDays:o.partitionExpirationDays,requirePartitionFilter:o.requirePartitionFilter,additionalOptions:o.additionalOptions}),this.proto.onSchemaChange=this.mapOnSchemaChange(o.onSchemaChange),this}type(e){let t;switch(e){case"table":t=new a.Table(this.session,Object.assign(Object.assign({},this.unverifiedConfig),{type:"table"}),this.configPath);break;case"incremental":return this;case"view":t=new s.View(this.session,Object.assign(Object.assign({},this.unverifiedConfig),{type:"view"}),this.configPath);break;default:throw new Error(`Unexpected table type: ${e}`)}const r=this.session.actions.indexOf(this);if(-1===r)throw Error("Expected pre-existing action, but none found. Please report this to the Dataform team.");this.session.actions[r]=t}query(e){return this.contextableQuery=e,this}where(e){return this.contextableWhere=e,this}preOps(e){return this.contextablePreOps.push(e),this}postOps(e){return this.contextablePostOps.push(e),this}disabled(e=!0){var t;return this.proto.disabled=e,this.uniqueKeyAssertions.forEach((t=>t.disabled(e))),null===(t=this.rowConditionsAssertion)||void 0===t||t.disabled(e),this}protected(e){return this.proto.protected=null==e||e,this}uniqueKey(e){this.proto.uniqueKey=e}bigquery(e){e.labels&&Object.keys(e.labels).length>0&&(this.proto.actionDescriptor||(this.proto.actionDescriptor={}),this.proto.actionDescriptor.bigqueryLabels=e.labels);const t=i.LegacyConfigConverter.legacyConvertBigQueryOptions(e);return Object.values(t).length>0&&(this.proto.bigquery=p.dataform.BigQueryOptions.create(t)),this}dependencies(e){return(Array.isArray(e)?e:[e]).forEach((e=>this.proto.dependencyTargets.push(u.checkAssertionsForDependency(this,e)))),this}hermetic(e){this.proto.hermeticity=e?p.dataform.ActionHermeticity.HERMETIC:p.dataform.ActionHermeticity.NON_HERMETIC}tags(e){var t;return("string"==typeof e?[e]:e).forEach((e=>{this.proto.tags.push(e)})),this.uniqueKeyAssertions.forEach((t=>t.tags(e))),null===(t=this.rowConditionsAssertion)||void 0===t||t.tags(e),this}description(e){return this.proto.actionDescriptor||(this.proto.actionDescriptor={}),this.proto.actionDescriptor.description=e,this}columns(e){return this.proto.actionDescriptor||(this.proto.actionDescriptor={}),this.proto.actionDescriptor.columns=l.ColumnDescriptors.mapConfigProtoToCompilationProto(e),this}database(e){return this.proto.target=this.applySessionToTarget(p.dataform.Target.create(Object.assign(Object.assign({},this.proto.target),{database:e})),this.session.projectConfig,this.proto.fileName,{validateTarget:!0}),this}schema(e){return this.proto.target=this.applySessionToTarget(p.dataform.Target.create(Object.assign(Object.assign({},this.proto.target),{schema:e})),this.session.projectConfig,this.proto.fileName,{validateTarget:!0}),this}assertions(e){const t=this.generateInlineAssertions(e,this.proto);return this.uniqueKeyAssertions=t.uniqueKeyAssertions,this.rowConditionsAssertion=t.rowConditionsAssertion,this}setDependOnDependencyAssertions(e){return this.dependOnDependencyAssertions=e,this}getFileName(){return this.proto.fileName}getTarget(){return p.dataform.Target.create(this.proto.target)}compile(){const e=new f(this),t=new f(this,!0);return this.proto.query=e.apply(this.contextableQuery),this.proto.incrementalQuery=t.apply(this.contextableQuery),this.proto.incrementalPreOps=this.contextifyOps(this.contextablePreOps,t),this.proto.incrementalPostOps=this.contextifyOps(this.contextablePostOps,t),this.contextableWhere&&(this.proto.where=e.apply(this.contextableWhere)),this.proto.preOps=this.contextifyOps(this.contextablePreOps,e).filter((e=>!!e.trim())),this.proto.postOps=this.contextifyOps(this.contextablePostOps,e).filter((e=>!!e.trim())),u.validateQueryString(this.session,this.proto.query,this.proto.fileName),u.validateQueryString(this.session,this.proto.incrementalQuery,this.proto.fileName),o.verifyObjectMatchesProto(p.dataform.Table,this.proto,o.VerifyProtoErrorBehaviour.SUGGEST_REPORTING_TO_DATAFORM_TEAM)}contextifyOps(e,t){let r=[];return e.forEach((e=>{const n=t.apply(e);r=r.concat("string"==typeof n?[n]:n)})),r}verifyConfig(e){e.type&&(delete e.type,e.dependencies&&(e.dependencyTargets=e.dependencies.map((e=>u.resolvableAsActionConfigTarget(e))),delete e.dependencies),e.database&&(e.project=e.database,delete e.database),e.schema&&(e.dataset=e.schema,delete e.schema),e.fileName&&(e.filename=e.fileName,delete e.fileName),e.columns&&(e.columns=l.ColumnDescriptors.mapLegacyObjectToConfigProto(e.columns)),e=i.LegacyConfigConverter.insertLegacyInlineAssertionsToConfigProto(e),(e=i.LegacyConfigConverter.insertLegacyBigQueryOptionsToConfigProto(e)).bigquery&&u.checkExcessProperties((e=>{throw e}),e.bigquery,u.strictKeysOf()(["partitionBy","clusterBy","updatePartitionFilter","labels","partitionExpirationDays","requirePartitionFilter","additionalOptions"]),"BigQuery table config"));const t=o.verifyObjectMatchesProto(p.dataform.ActionConfig.IncrementalTableConfig,e,o.VerifyProtoErrorBehaviour.SHOW_DOCS_LINK);return t.additionalOptions&&i.checkConfigAdditionalOptionsOverlap(t,this.session),t}mapOnSchemaChange(e){if(!e)return p.dataform.OnSchemaChange.IGNORE;if("number"==typeof e)switch(e){case p.dataform.ActionConfig.OnSchemaChange.IGNORE:return p.dataform.OnSchemaChange.IGNORE;case p.dataform.ActionConfig.OnSchemaChange.FAIL:return p.dataform.OnSchemaChange.FAIL;case p.dataform.ActionConfig.OnSchemaChange.EXTEND:return p.dataform.OnSchemaChange.EXTEND;case p.dataform.ActionConfig.OnSchemaChange.SYNCHRONIZE:return p.dataform.OnSchemaChange.SYNCHRONIZE;default:throw new Error(`OnSchemaChange value "${e}" is not supported`)}switch(e.toString().toUpperCase()){case"IGNORE":return p.dataform.OnSchemaChange.IGNORE;case"FAIL":return p.dataform.OnSchemaChange.FAIL;case"EXTEND":return p.dataform.OnSchemaChange.EXTEND;case"SYNCHRONIZE":return p.dataform.OnSchemaChange.SYNCHRONIZE;default:throw new Error(`OnSchemaChange value "${e}" is not supported`)}}}t.IncrementalTable=d;class f{constructor(e,t=!1){this.incrementalTable=e,this.isIncremental=t}self(){return this.resolve(this.incrementalTable.getTarget())}name(){return this.incrementalTable.session.finalizeName(this.incrementalTable.getTarget().name)}ref(e,...t){return e=u.toResolvable(e,t),u.resolvableAsTarget(e)?(this.incrementalTable.dependencies(e),this.resolve(e)):(this.incrementalTable.session.compileError(new Error("Action name is not specified")),"")}resolve(e,...t){return this.incrementalTable.session.resolve(e,...t)}schema(){return this.incrementalTable.session.finalizeSchema(this.incrementalTable.getTarget().schema)}database(){return this.incrementalTable.getTarget().database?this.incrementalTable.session.finalizeDatabase(this.incrementalTable.getTarget().database):(this.incrementalTable.session.compileError(new Error("Warehouse does not support multiple databases")),"")}where(e){return this.incrementalTable.where(e),""}when(e,t,r=""){return e?t:r}incremental(){return!!this.isIncremental}preOps(e){return this.incrementalTable.preOps(e),""}postOps(e){return this.incrementalTable.postOps(e),""}disabled(){return this.incrementalTable.disabled(),""}bigquery(e){return this.incrementalTable.bigquery(e),""}dependencies(e){return this.incrementalTable.dependencies(e),""}apply(e){return"function"==typeof e?e(this):e}tags(e){return this.incrementalTable.tags(e),""}}t.IncrementalTableContext=f},3186:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(8869);t.ActionBuilder=class{constructor(e){this.includeAssertionsForDependency=new Map,this.session=e}applySessionToTarget(e,t,r,o){const i=(null==o?void 0:o.useDefaultAssertionDataset)&&t.assertionSchema||t.defaultSchema,a=n.dataform.Target.create({name:e.name,schema:e.schema||i||void 0,database:e.database||t.defaultDatabase||void 0});return(null==o?void 0:o.validateTarget)&&this.validateTarget(e,r),a}finalizeTarget(e){return n.dataform.Target.create({name:this.session.finalizeName(e.name),schema:e.schema?this.session.finalizeSchema(e.schema):void 0,database:e.database?this.session.finalizeDatabase(e.database):void 0})}generateInlineAssertions(e,t){var r,o,i;const a={uniqueKeyAssertions:[]};(null===(r=e.uniqueKey)||void 0===r?void 0:r.length)&&(null===(o=e.uniqueKeys)||void 0===o?void 0:o.length)&&this.session.compileError(new Error("Specify at most one of 'assertions.uniqueKey' and 'assertions.uniqueKeys'."));const s=this.session.projectConfig.builtinAssertionNamePrefix?`${this.session.projectConfig.builtinAssertionNamePrefix}_`:"";let l=e.uniqueKeys.map((e=>n.dataform.ActionConfig.TableAssertionsConfig.UniqueKey.create(e)));(null===(i=e.uniqueKey)||void 0===i?void 0:i.length)&&(l=[n.dataform.ActionConfig.TableAssertionsConfig.UniqueKey.create({uniqueKey:e.uniqueKey})]),l&&l.forEach((({uniqueKey:e},r)=>{const o=this.session.assert(`${s}${t.target.schema}_${t.target.name}_assertions_uniqueKey_${r}`,n.dataform.ActionConfig.AssertionConfig.create({filename:t.fileName})).query((r=>this.session.compilationSql().indexAssertion(r.ref(t.target),e)));t.tags&&o.tags(t.tags),o.setParentAction(n.dataform.Target.create(t.target)),t.disabled&&o.disabled(),a.uniqueKeyAssertions.push(o)}));const c=e.rowConditions||[];return e.nonNull&&("string"==typeof e.nonNull?[e.nonNull]:e.nonNull).forEach((e=>c.push(`${e} IS NOT NULL`))),c&&c.length>0&&(a.rowConditionsAssertion=this.session.assert(`${s}${t.target.schema}_${t.target.name}_assertions_rowConditions`,{filename:t.fileName}).query((e=>this.session.compilationSql().rowConditionsAssertion(e.ref(t.target),c))),a.rowConditionsAssertion.setParentAction(n.dataform.Target.create(t.target)),t.disabled&&a.rowConditionsAssertion.disabled(),t.tags&&a.rowConditionsAssertion.tags(t.tags)),a}validateTarget(e,t){e.name.includes(".")&&this.session.compileError(new Error("Action target names cannot include '.'"),t,e),e.schema.includes(".")&&this.session.compileError(new Error("Action target datasets cannot include '.'"),t,e),e.database.includes(".")&&this.session.compileError(new Error("Action target projects cannot include '.'"),t,e)}},t.checkConfigAdditionalOptionsOverlap=function(e,t){const r=n.dataform.Target.create({database:e.project,schema:e.dataset,name:e.name});e.partitionExpirationDays&&e.additionalOptions.partition_expiration_days&&t.compileError("partitionExpirationDays has been declared twice",e.filename,r),e.requirePartitionFilter&&e.additionalOptions.require_partition_filter&&t.compileError("requirePartitionFilter has been declared twice",e.filename,r)},t.TableType=["table","view","incremental"],t.LegacyConfigConverter=class{static legacyConvertBigQueryOptions(e){let t={};return Object.entries(e).forEach((([e,r])=>{Array.isArray(r)&&0===r.length||"object"==typeof r&&0===Object.entries(r).length||r&&(t=Object.assign(Object.assign({},t),{[e]:r}))})),t}static insertLegacyInlineAssertionsToConfigProto(e){var t,r,o;const i=e;return(null==i?void 0:i.assertions)&&("string"==typeof(null===(t=i.assertions)||void 0===t?void 0:t.uniqueKey)&&(i.assertions.uniqueKey=[i.assertions.uniqueKey]),(null===(o=null===(r=i.assertions.uniqueKeys)||void 0===r?void 0:r[0])||void 0===o?void 0:o.length)>0&&(i.assertions.uniqueKeys=i.assertions.uniqueKeys.map((e=>n.dataform.ActionConfig.TableAssertionsConfig.UniqueKey.create({uniqueKey:e})))),"string"==typeof i.assertions.nonNull&&(i.assertions.nonNull=[i.assertions.nonNull])),i}static insertLegacyBigQueryOptionsToConfigProto(e){const t=e;return(null==t?void 0:t.bigquery)?(t.bigquery.partitionBy&&(t.partitionBy=t.bigquery.partitionBy,delete t.bigquery.partitionBy),t.bigquery.clusterBy&&(t.clusterBy=t.bigquery.clusterBy,delete t.bigquery.clusterBy),t.bigquery.updatePartitionFilter&&(t.updatePartitionFilter=t.bigquery.updatePartitionFilter,delete t.bigquery.updatePartitionFilter),t.bigquery.labels&&(t.labels=t.bigquery.labels,delete t.bigquery.labels),t.bigquery.partitionExpirationDays&&(t.partitionExpirationDays=t.bigquery.partitionExpirationDays,delete t.bigquery.partitionExpirationDays),t.bigquery.requirePartitionFilter&&(t.requirePartitionFilter=t.bigquery.requirePartitionFilter,delete t.bigquery.requirePartitionFilter),t.bigquery.additionalOptions&&(t.additionalOptions=t.bigquery.additionalOptions,delete t.bigquery.additionalOptions),0===Object.keys(t.bigquery).length&&delete t.bigquery,t):t}}},5145:function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(t,"__esModule",{value:!0});const o=r(8142),i=r(3186),a=n(r(6203)),s=r(9211),l=r(8869);class c extends i.ActionBuilder{constructor(e,t,r){super(e),this.dependOnDependencyAssertions=!1,this.proto=l.dataform.Notebook.create();const n=this.verifyConfig(t);n.name||(n.name=a.basename(n.filename));const o=s.actionConfigToCompiledGraphTarget(n);n.filename=s.resolveActionsConfigFilename(n.filename,r),this.session=e,this.proto.target=this.applySessionToTarget(o,e.projectConfig,n.filename,{validateTarget:!0}),this.proto.canonicalTarget=this.applySessionToTarget(o,e.canonicalProjectConfig),this.proto.tags=n.tags,this.dependOnDependencyAssertions=n.dependOnDependencyAssertions,n.dependencyTargets&&this.dependencies(n.dependencyTargets.map((e=>s.configTargetToCompiledGraphTarget(l.dataform.ActionConfig.Target.create(e))))),this.proto.fileName=n.filename,n.disabled&&(this.proto.disabled=n.disabled);const i=s.nativeRequire(n.filename).asJson;this.proto.notebookContents=JSON.stringify(function(e,t){if(!("cells"in e))throw new Error(`Notebook at ${t} is invalid: cells field not present`);return e.cells.forEach(((t,r)=>{"outputs"in t&&(t.outputs=[],e.cells[r]=t)})),e}(i,n.filename))}ipynb(e){return this.proto.notebookContents=JSON.stringify(e),this}dependencies(e){return(Array.isArray(e)?e:[e]).forEach((e=>{const t=s.checkAssertionsForDependency(this,e);t&&this.proto.dependencyTargets.push(t)})),this}getFileName(){return this.proto.fileName}getTarget(){return l.dataform.Target.create(this.proto.target)}compile(){return o.verifyObjectMatchesProto(l.dataform.Notebook,this.proto,o.VerifyProtoErrorBehaviour.SUGGEST_REPORTING_TO_DATAFORM_TEAM)}verifyConfig(e){return o.verifyObjectMatchesProto(l.dataform.ActionConfig.NotebookConfig,e,o.VerifyProtoErrorBehaviour.SHOW_DOCS_LINK)}}t.Notebook=c},975:function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(t,"__esModule",{value:!0});const o=r(8142),i=r(3186),a=r(299),s=n(r(6203)),l=r(9211),c=r(8869);class u extends i.ActionBuilder{constructor(e,t,r){var n;if(super(e),this.dependOnDependencyAssertions=!1,this.proto=c.dataform.Operation.create(),this.session=e,!t)return;const o=this.verifyConfig(t);o.name||(o.name=s.basename(o.filename));const i=l.actionConfigToCompiledGraphTarget(o);return this.proto.target=this.applySessionToTarget(i,e.projectConfig,o.filename,{validateTarget:!0}),this.proto.canonicalTarget=this.applySessionToTarget(i,e.canonicalProjectConfig),r&&(o.filename=l.resolveActionsConfigFilename(o.filename,r),this.queries(l.nativeRequire(o.filename).query)),o.dependOnDependencyAssertions&&this.setDependOnDependencyAssertions(o.dependOnDependencyAssertions),o.dependencyTargets&&this.dependencies(o.dependencyTargets.map((e=>l.configTargetToCompiledGraphTarget(c.dataform.ActionConfig.Target.create(e))))),void 0!==o.hermetic&&this.hermetic(o.hermetic),o.disabled&&this.disabled(),o.tags&&this.tags(o.tags),o.hasOutput&&this.hasOutput(o.hasOutput),o.description&&this.description(o.description),(null===(n=o.columns)||void 0===n?void 0:n.length)&&this.columns(o.columns.map((e=>c.dataform.ActionConfig.ColumnDescriptor.create(e)))),o.project&&this.database(o.project),o.dataset&&this.schema(o.dataset),o.filename&&(this.proto.fileName=o.filename),this}queries(e){return this.contextableQueries=e,this}dependencies(e){return(Array.isArray(e)?e:[e]).forEach((e=>{const t=l.checkAssertionsForDependency(this,e);t&&this.proto.dependencyTargets.push(t)})),this}hermetic(e){this.proto.hermeticity=e?c.dataform.ActionHermeticity.HERMETIC:c.dataform.ActionHermeticity.NON_HERMETIC}disabled(e=!0){return this.proto.disabled=e,this}tags(e){return("string"==typeof e?[e]:e).forEach((e=>{this.proto.tags.indexOf(e)<0&&this.proto.tags.push(e)})),this}hasOutput(e){return this.proto.hasOutput=e,this}description(e){return this.proto.actionDescriptor||(this.proto.actionDescriptor={}),this.proto.actionDescriptor.description=e,this}columns(e){return this.proto.actionDescriptor||(this.proto.actionDescriptor={}),this.proto.actionDescriptor.columns=a.ColumnDescriptors.mapConfigProtoToCompilationProto(e),this}database(e){return this.proto.target=this.applySessionToTarget(c.dataform.Target.create(Object.assign(Object.assign({},this.proto.target),{database:e})),this.session.projectConfig,this.proto.fileName,{validateTarget:!0}),this}schema(e){return this.proto.target=this.applySessionToTarget(c.dataform.Target.create(Object.assign(Object.assign({},this.proto.target),{schema:e})),this.session.projectConfig,this.proto.fileName,{validateTarget:!0}),this}setDependOnDependencyAssertions(e){return this.dependOnDependencyAssertions=e,this}getFileName(){return this.proto.fileName}getTarget(){return c.dataform.Target.create(this.proto.target)}getHasOutput(){return this.proto.hasOutput}compile(){var e,t;(null===(t=null===(e=this.proto.actionDescriptor)||void 0===e?void 0:e.columns)||void 0===t?void 0:t.length)>0&&!this.proto.hasOutput&&this.session.compileError(new Error("Actions of type 'operations' may only describe columns if they specify 'hasOutput: true'."),this.proto.fileName);const r=new p(this).apply(this.contextableQueries);return this.proto.queries="string"==typeof r?[r]:r,o.verifyObjectMatchesProto(c.dataform.Operation,this.proto,o.VerifyProtoErrorBehaviour.SUGGEST_REPORTING_TO_DATAFORM_TEAM)}verifyConfig(e){return e.type&&(delete e.type,e.dependencies&&(e.dependencyTargets=e.dependencies.map((e=>l.resolvableAsActionConfigTarget(e))),delete e.dependencies),e.database&&(e.project=e.database,delete e.database),e.schema&&(e.dataset=e.schema,delete e.schema),e.fileName&&(e.filename=e.fileName,delete e.fileName),e.columns&&(e.columns=a.ColumnDescriptors.mapLegacyObjectToConfigProto(e.columns))),o.verifyObjectMatchesProto(c.dataform.ActionConfig.OperationConfig,e,o.VerifyProtoErrorBehaviour.SHOW_DOCS_LINK)}}t.Operation=u;class p{constructor(e){this.operation=e}self(){return this.resolve(this.operation.getTarget())}name(){return this.operation.session.finalizeName(this.operation.getTarget().name)}ref(e,...t){return e=l.toResolvable(e,t),l.resolvableAsTarget(e)?(this.operation.dependencies(e),this.resolve(e)):(this.operation.session.compileError(new Error("Action name is not specified")),"")}resolve(e,...t){return this.operation.session.resolve(e,...t)}schema(){return this.operation.session.finalizeSchema(this.operation.getTarget().schema)}database(){return this.operation.getTarget().database?this.operation.session.finalizeDatabase(this.operation.getTarget().database):(this.operation.session.compileError(new Error("Warehouse does not support multiple databases")),"")}dependencies(e){return this.operation.dependencies(e),""}tags(e){return this.operation.tags(e),""}hasOutput(e){return this.operation.hasOutput(e),""}when(e,t,r=""){return e?t:r}apply(e){return"function"==typeof e?e(this):e}}t.OperationContext=p},2406:function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(t,"__esModule",{value:!0});const o=r(8142),i=r(3186),a=r(621),s=r(2537),l=r(299),c=n(r(6203)),u=r(9211),p=r(8869);class d extends i.ActionBuilder{constructor(e,t,r){var n;if(super(e),this.dependOnDependencyAssertions=!1,this.contextablePreOps=[],this.contextablePostOps=[],this.proto=p.dataform.Table.create({type:"table",enumType:p.dataform.TableType.TABLE,disabled:!1,tags:[]}),this.uniqueKeyAssertions=[],this.session=e,this.configPath=r,this.unverifiedConfig=Object.assign({},t),!t)return;const o=this.verifyConfig(t);o.name||(o.name=c.basename(o.filename));const i=u.actionConfigToCompiledGraphTarget(o);return this.proto.target=this.applySessionToTarget(i,e.projectConfig,o.filename,{validateTarget:!0}),this.proto.canonicalTarget=this.applySessionToTarget(i,e.canonicalProjectConfig),r&&(o.filename=u.resolveActionsConfigFilename(o.filename,r),this.query(u.nativeRequire(o.filename).query)),o.filename&&(this.proto.fileName=o.filename),o.dependOnDependencyAssertions&&this.setDependOnDependencyAssertions(o.dependOnDependencyAssertions),o.dependencyTargets&&this.dependencies(o.dependencyTargets),void 0!==o.hermetic&&this.hermetic(o.hermetic),o.disabled&&this.disabled(),o.tags&&this.tags(o.tags),o.description&&this.description(o.description),(null===(n=o.columns)||void 0===n?void 0:n.length)&&this.columns(o.columns.map((e=>p.dataform.ActionConfig.ColumnDescriptor.create(e)))),o.assertions&&this.assertions(p.dataform.ActionConfig.TableAssertionsConfig.create(o.assertions)),o.preOperations&&this.preOps(o.preOperations),o.postOperations&&this.postOps(o.postOperations),this.bigquery({partitionBy:o.partitionBy,clusterBy:o.clusterBy,labels:o.labels,partitionExpirationDays:o.partitionExpirationDays,requirePartitionFilter:o.requirePartitionFilter,additionalOptions:o.additionalOptions}),this}type(e){let t;switch(e){case"table":return this;case"incremental":t=new a.IncrementalTable(this.session,Object.assign(Object.assign({},this.unverifiedConfig),{type:"incremental"}),this.configPath);break;case"view":t=new s.View(this.session,Object.assign(Object.assign({},this.unverifiedConfig),{type:"view"}),this.configPath);break;default:throw new Error(`Unexpected table type: ${e}`)}const r=this.session.actions.indexOf(this);if(-1===r)throw Error("Expected pre-existing action, but none found. Please report this to the Dataform team.");this.session.actions[r]=t}query(e){return this.contextableQuery=e,this}where(e){return this.contextableWhere=e,this}preOps(e){return this.contextablePreOps.push(e),this}postOps(e){return this.contextablePostOps.push(e),this}disabled(e=!0){var t;return this.proto.disabled=e,this.uniqueKeyAssertions.forEach((t=>t.disabled(e))),null===(t=this.rowConditionsAssertion)||void 0===t||t.disabled(e),this}bigquery(e){e.labels&&Object.keys(e.labels).length>0&&(this.proto.actionDescriptor||(this.proto.actionDescriptor={}),this.proto.actionDescriptor.bigqueryLabels=e.labels);const t=i.LegacyConfigConverter.legacyConvertBigQueryOptions(e);return Object.values(t).length>0&&(this.proto.bigquery=p.dataform.BigQueryOptions.create(t)),this}dependencies(e){return(Array.isArray(e)?e:[e]).forEach((e=>{const t=u.checkAssertionsForDependency(this,e);t&&this.proto.dependencyTargets.push(t)})),this}hermetic(e){this.proto.hermeticity=e?p.dataform.ActionHermeticity.HERMETIC:p.dataform.ActionHermeticity.NON_HERMETIC}tags(e){var t;return("string"==typeof e?[e]:e).forEach((e=>{this.proto.tags.push(e)})),this.uniqueKeyAssertions.forEach((t=>t.tags(e))),null===(t=this.rowConditionsAssertion)||void 0===t||t.tags(e),this}description(e){return this.proto.actionDescriptor||(this.proto.actionDescriptor={}),this.proto.actionDescriptor.description=e,this}columns(e){return this.proto.actionDescriptor||(this.proto.actionDescriptor={}),this.proto.actionDescriptor.columns=l.ColumnDescriptors.mapConfigProtoToCompilationProto(e),this}database(e){return this.proto.target=this.applySessionToTarget(p.dataform.Target.create(Object.assign(Object.assign({},this.proto.target),{database:e})),this.session.projectConfig,this.proto.fileName,{validateTarget:!0}),this}schema(e){return this.proto.target=this.applySessionToTarget(p.dataform.Target.create(Object.assign(Object.assign({},this.proto.target),{schema:e})),this.session.projectConfig,this.proto.fileName,{validateTarget:!0}),this}assertions(e){const t=this.generateInlineAssertions(e,this.proto);return this.uniqueKeyAssertions=t.uniqueKeyAssertions,this.rowConditionsAssertion=t.rowConditionsAssertion,this}setDependOnDependencyAssertions(e){return this.dependOnDependencyAssertions=e,this}getFileName(){return this.proto.fileName}getTarget(){return p.dataform.Target.create(this.proto.target)}compile(){const e=new f(this),t=new f(this,!0);return this.proto.query=e.apply(this.contextableQuery),this.proto.enumType===p.dataform.TableType.INCREMENTAL&&(this.proto.incrementalQuery=t.apply(this.contextableQuery),this.proto.incrementalPreOps=this.contextifyOps(this.contextablePreOps,t),this.proto.incrementalPostOps=this.contextifyOps(this.contextablePostOps,t)),this.contextableWhere&&(this.proto.where=e.apply(this.contextableWhere)),this.proto.preOps=this.contextifyOps(this.contextablePreOps,e).filter((e=>!!e.trim())),this.proto.postOps=this.contextifyOps(this.contextablePostOps,e).filter((e=>!!e.trim())),u.validateQueryString(this.session,this.proto.query,this.proto.fileName),u.validateQueryString(this.session,this.proto.incrementalQuery,this.proto.fileName),o.verifyObjectMatchesProto(p.dataform.Table,this.proto,o.VerifyProtoErrorBehaviour.SUGGEST_REPORTING_TO_DATAFORM_TEAM)}contextifyOps(e,t){let r=[];return e.forEach((e=>{const n=t.apply(e);r=r.concat("string"==typeof n?[n]:n)})),r}verifyConfig(e){if(e.type){if("table"!==e.type)throw ReferenceError(`Unexpected type for Table; want "table", got ${e.type}`);delete e.type,e.dependencies&&(e.dependencyTargets=e.dependencies.map((e=>u.resolvableAsActionConfigTarget(e))),delete e.dependencies),e.database&&(e.project=e.database,delete e.database),e.schema&&(e.dataset=e.schema,delete e.schema),e.fileName&&(e.filename=e.fileName,delete e.fileName),e.columns&&(e.columns=l.ColumnDescriptors.mapLegacyObjectToConfigProto(e.columns)),e=i.LegacyConfigConverter.insertLegacyInlineAssertionsToConfigProto(e),(e=i.LegacyConfigConverter.insertLegacyBigQueryOptionsToConfigProto(e)).bigquery&&u.checkExcessProperties((e=>{throw e}),e.bigquery,u.strictKeysOf()(["partitionBy","clusterBy","updatePartitionFilter","labels","partitionExpirationDays","requirePartitionFilter","additionalOptions"]),"BigQuery table config")}const t=o.verifyObjectMatchesProto(p.dataform.ActionConfig.TableConfig,e,o.VerifyProtoErrorBehaviour.SHOW_DOCS_LINK);return t.partitionBy||!t.partitionExpirationDays&&!t.requirePartitionFilter||this.session.compileError("requirePartitionFilter/partitionExpirationDays are not valid for non partitioned BigQuery tables",t.filename,p.dataform.Target.create({database:t.project,schema:t.dataset,name:t.name})),t.additionalOptions&&i.checkConfigAdditionalOptionsOverlap(t,this.session),t}}t.Table=d;class f{constructor(e,t=!1){this.table=e,this.isIncremental=t}self(){return this.resolve(this.table.getTarget())}name(){return this.table.session.finalizeName(this.table.getTarget().name)}ref(e,...t){return e=u.toResolvable(e,t),u.resolvableAsTarget(e)?(this.table.dependencies(e),this.resolve(e)):(this.table.session.compileError(new Error("Action name is not specified")),"")}resolve(e,...t){return this.table.session.resolve(e,...t)}schema(){return this.table.session.finalizeSchema(this.table.getTarget().schema)}database(){return this.table.getTarget().database?this.table.session.finalizeDatabase(this.table.getTarget().database):(this.table.session.compileError(new Error("Warehouse does not support multiple databases")),"")}type(e){return this.table.type(e),""}where(e){return this.table.where(e),""}when(e,t,r=""){return e?t:r}incremental(){return!!this.isIncremental}preOps(e){return this.table.preOps(e),""}postOps(e){return this.table.postOps(e),""}disabled(){return this.table.disabled(),""}bigquery(e){return this.table.bigquery(e),""}dependencies(e){return this.table.dependencies(e),""}apply(e){return"function"==typeof e?e(this):e}tags(e){return this.table.tags(e),""}}t.TableContext=f},5900:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(8142),o=r(3186),i=r(621),a=r(2406),s=r(2537),l=r(2748),c=r(9211),u=r(8869),p=c.strictKeysOf()(["type","dataset","name"]);class d extends o.ActionBuilder{constructor(e,t){super(e),this.contextableInputs=new Map,this.proto=u.dataform.Test.create(),this.session=e,t&&this.config(t)}config(e){return c.checkExcessProperties((e=>this.session.compileError(e)),e,p,"test config"),e.name&&(this.proto.name=e.name),e.dataset&&this.dataset(e.dataset),this}dataset(e){return this.datasetToTest=e,this}input(e,t){return this.contextableInputs.set(l.targetStringifier.stringify(c.resolvableAsTarget(c.toResolvable(e))),t),this}expect(e){return this.contextableQuery=e,this}getFileName(){return this.proto.fileName}getTarget(){}setFilename(e){this.proto.fileName=e}compile(){const e=new f(this);if(this.datasetToTest){const t=this.session.indexedActions.find(c.resolvableAsTarget(this.datasetToTest));t.length>1&&this.session.compileError(new Error(c.ambiguousActionNameMsg(this.datasetToTest,t)),this.proto.fileName);const r=t.length>0?t[0]:void 0;if(r&&(r instanceof a.Table||r instanceof s.View))if(r instanceof i.IncrementalTable)this.session.compileError(new Error("Running tests on incremental datasets is not yet supported."),this.proto.fileName);else{const t=new h(e);this.proto.testQuery=t.apply(r.contextableQuery)}else this.session.compileError(new Error(`Dataset ${c.stringifyResolvable(this.datasetToTest)} could not be found.`),this.proto.fileName)}else this.session.compileError(new Error("Tests must operate upon a specified dataset."),this.proto.fileName);return this.proto.expectedOutputQuery=e.apply(this.contextableQuery),n.verifyObjectMatchesProto(u.dataform.Test,this.proto,n.VerifyProtoErrorBehaviour.SUGGEST_REPORTING_TO_DATAFORM_TEAM)}}t.Test=d;class f{constructor(e){this.test=e}apply(e){return"function"==typeof e?e(this):e}}t.TestContext=f;class h{constructor(e){this.testContext=e}ref(e,...t){return this.resolve(e,...t)}resolve(e,...t){const r=c.resolvableAsTarget(c.toResolvable(e,t));return this.testContext.test.contextableInputs.has(l.targetStringifier.stringify(r))?`(${this.testContext.apply(this.testContext.test.contextableInputs.get(l.targetStringifier.stringify(r)))})`:(this.testContext.test.session.compileError(new Error(`Input for dataset "${JSON.stringify(r)}" has not been provided. Provided inputs: ${Array.from(this.testContext.test.contextableInputs.keys()).map((e=>JSON.stringify(e)))}`)),"")}apply(e){return"function"==typeof e?e(this):e}config(e){return""}self(){return""}name(){return""}type(e){return""}schema(){return""}database(){return""}where(e){return""}when(e,t,r=""){return e?t:r}incremental(){return!1}preOps(e){return""}postOps(e){return""}disabled(){return""}dependencies(e){return""}tags(e){return""}}},2537:function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(t,"__esModule",{value:!0});const o=r(8142),i=r(3186),a=r(621),s=r(2406),l=r(299),c=n(r(6203)),u=r(9211),p=r(8869);class d extends i.ActionBuilder{constructor(e,t,r){var n;if(super(e),this.dependOnDependencyAssertions=!1,this.contextablePreOps=[],this.contextablePostOps=[],this.proto=p.dataform.Table.create({type:"view",enumType:p.dataform.TableType.VIEW,disabled:!1,tags:[]}),this.un