dropkiq
Version:
Liquid Expressions Simplified
1 lines • 1.9 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var DropkiqEngine_1=require("./DropkiqEngine"),uuid_1=require("uuid"),DropkiqEngineFromScope=function(){function e(e,t,n,o,r){void 0===o&&(o=""),void 0===r&&(r={}),this.rawTextBody=e,this.caretIndex=t,this.scope=n,this.licenseKey=o,this.optionsFromUI=Object.assign(r,{allowEmptySchema:!0}),this.schema={},this.context=this.constructContextFromScope()}return e.prototype.dropkiqEngine=function(){return new DropkiqEngine_1.DropkiqEngine(this.rawTextBody,this.caretIndex,this.schema,this.context,this.scope,this.licenseKey,this.optionsFromUI)},e.prototype.constructContextFromScope=function(){var e=this,t={};return Object.keys(this.scope).forEach((function(n){e.addValueSignature(e.scope,n,t)})),t},e.prototype.findValueType=function(e){switch(typeof e){case"undefined":return"ColumnTypes::String";case"boolean":return"ColumnTypes::Boolean";case"object":if(null===e)return"ColumnTypes::String";if("function"==typeof e.getMonth)return"ColumnTypes::DateTime";if(Array.isArray(e)){var t=e[0];return"ColumnTypes::HasOne"===this.findValueType(t)?"ColumnTypes::HasMany":"ColumnTypes::YAML"}return"ColumnTypes::HasOne";case"string":case"symbol":return"ColumnTypes::String";case"number":case"bigint":return"ColumnTypes::Numeric";default:throw new Error("Received unknown type "+typeof e+" while constructing context")}},e.prototype.constructFakeSchemaTable=function(e){var t=uuid_1.v4(),n=this;return this.schema[t]={methods:{}},Object.keys(e).forEach((function(o){n.addValueSignature(e,o,n.schema[t].methods)})),t},e.prototype.addValueSignature=function(e,t,n){var o=e[t],r=this.findValueType(o),i=null;if("ColumnTypes::HasOne"===r&&(i=this.constructFakeSchemaTable(o)),"ColumnTypes::HasMany"===r){var s=o[0];i=this.constructFakeSchemaTable(s)}n[t]={type:r,foreign_table_name:i}},e}();exports.DropkiqEngineFromScope=DropkiqEngineFromScope;