1 | {"version":3,"file":"rpcrequest-payload.js","names":["_writableTrackingBuffer","_interopRequireDefault","require","_allHeaders","obj","__esModule","default","STATUS","BY_REF_VALUE","DEFAULT_VALUE","RpcRequestPayload","constructor","procedure","parameters","txnDescriptor","options","collation","Symbol","iterator","generateData","buffer","WritableTrackingBuffer","tdsVersion","outstandingRequestCount","writeToTrackingBuffer","writeUsVarchar","writeUShort","optionFlags","writeUInt16LE","data","parametersLength","length","i","generateParameterData","toString","indent","parameter","Buffer","byteLength","name","writeBVarchar","statusFlags","output","writeUInt8","param","value","type","id","resolveLength","precision","resolvePrecision","scale","resolveScale","generateTypeInfo","generateParameterLength","_default","exports","module"],"sources":["../src/rpcrequest-payload.ts"],"sourcesContent":["import WritableTrackingBuffer from './tracking-buffer/writable-tracking-buffer';\nimport { writeToTrackingBuffer } from './all-headers';\nimport { type Parameter, type ParameterData } from './data-type';\nimport { type InternalConnectionOptions } from './connection';\nimport { Collation } from './collation';\n\n// const OPTION = {\n// WITH_RECOMPILE: 0x01,\n// NO_METADATA: 0x02,\n// REUSE_METADATA: 0x04\n// };\n\nconst STATUS = {\n BY_REF_VALUE: 0x01,\n DEFAULT_VALUE: 0x02\n};\n\n/*\n s2.2.6.5\n */\nclass RpcRequestPayload implements Iterable<Buffer> {\n declare procedure: string | number;\n declare parameters: Parameter[];\n\n declare options: InternalConnectionOptions;\n declare txnDescriptor: Buffer;\n declare collation: Collation | undefined;\n\n constructor(procedure: string | number, parameters: Parameter[], txnDescriptor: Buffer, options: InternalConnectionOptions, collation: Collation | undefined) {\n this.procedure = procedure;\n this.parameters = parameters;\n this.options = options;\n this.txnDescriptor = txnDescriptor;\n this.collation = collation;\n }\n\n [Symbol.iterator]() {\n return this.generateData();\n }\n\n * generateData() {\n const buffer = new WritableTrackingBuffer(500);\n if (this.options.tdsVersion >= '7_2') {\n const outstandingRequestCount = 1;\n writeToTrackingBuffer(buffer, this.txnDescriptor, outstandingRequestCount);\n }\n\n if (typeof this.procedure === 'string') {\n buffer.writeUsVarchar(this.procedure);\n } else {\n buffer.writeUShort(0xFFFF);\n buffer.writeUShort(this.procedure);\n }\n\n const optionFlags = 0;\n buffer.writeUInt16LE(optionFlags);\n yield buffer.data;\n\n const parametersLength = this.parameters.length;\n for (let i = 0; i < parametersLength; i++) {\n yield * this.generateParameterData(this.parameters[i]);\n }\n }\n\n toString(indent = '') {\n return indent + ('RPC Request - ' + this.procedure);\n }\n\n * generateParameterData(parameter: Parameter) {\n const buffer = new WritableTrackingBuffer(1 + 2 + Buffer.byteLength(parameter.name, 'ucs-2') + 1);\n\n if (parameter.name) {\n buffer.writeBVarchar('@' + parameter.name);\n } else {\n buffer.writeBVarchar('');\n }\n\n let statusFlags = 0;\n if (parameter.output) {\n statusFlags |= STATUS.BY_REF_VALUE;\n }\n buffer.writeUInt8(statusFlags);\n\n yield buffer.data;\n\n const param: ParameterData = { value: parameter.value };\n\n const type = parameter.type;\n\n if ((type.id & 0x30) === 0x20) {\n if (parameter.length) {\n param.length = parameter.length;\n } else if (type.resolveLength) {\n param.length = type.resolveLength(parameter);\n }\n }\n\n if (parameter.precision) {\n param.precision = parameter.precision;\n } else if (type.resolvePrecision) {\n param.precision = type.resolvePrecision(parameter);\n }\n\n if (parameter.scale) {\n param.scale = parameter.scale;\n } else if (type.resolveScale) {\n param.scale = type.resolveScale(parameter);\n }\n\n if (this.collation) {\n param.collation = this.collation;\n }\n\n yield type.generateTypeInfo(param, this.options);\n yield type.generateParameterLength(param, this.options);\n yield * type.generateParameterData(param, this.options);\n }\n}\n\nexport default RpcRequestPayload;\nmodule.exports = RpcRequestPayload;\n"],"mappings":";;;;;;AAAA,IAAAA,uBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAAsD,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAKtD;AACA;AACA;AACA;AACA;;AAEA,M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