the-forest/client/node_modules/.cache/babel-loader/3bc76e497bb5104c4803eae016edd700622eaf05f9ae77410fa7250036208b58.json
2024-09-17 20:35:18 -04:00

1 line
12 KiB
JSON

{"ast":null,"code":"import { fetch, Request } from \"@libsql/isomorphic-fetch\";\nimport { Client } from \"../client.js\";\nimport { ClientError, ClosedError, ProtocolVersionError } from \"../errors.js\";\nimport { HttpStream } from \"./stream.js\";\nexport const checkEndpoints = [{\n versionPath: \"v3-protobuf\",\n pipelinePath: \"v3-protobuf/pipeline\",\n cursorPath: \"v3-protobuf/cursor\",\n version: 3,\n encoding: \"protobuf\"\n}\n/*\n{\n versionPath: \"v3\",\n pipelinePath: \"v3/pipeline\",\n cursorPath: \"v3/cursor\",\n version: 3,\n encoding: \"json\",\n},\n*/];\nconst fallbackEndpoint = {\n versionPath: \"v2\",\n pipelinePath: \"v2/pipeline\",\n cursorPath: undefined,\n version: 2,\n encoding: \"json\"\n};\n/** A client for the Hrana protocol over HTTP. */\nexport class HttpClient extends Client {\n #url;\n #jwt;\n #fetch;\n #closed;\n #streams;\n /** @private */\n _endpointPromise;\n /** @private */\n _endpoint;\n /** @private */\n constructor(url, jwt, customFetch, protocolVersion = 2) {\n super();\n this.#url = url;\n this.#jwt = jwt;\n this.#fetch = customFetch ?? fetch;\n this.#closed = undefined;\n this.#streams = new Set();\n if (protocolVersion == 3) {\n this._endpointPromise = findEndpoint(this.#fetch, this.#url);\n this._endpointPromise.then(endpoint => this._endpoint = endpoint, error => this.#setClosed(error));\n } else {\n this._endpointPromise = Promise.resolve(fallbackEndpoint);\n this._endpointPromise.then(endpoint => this._endpoint = endpoint, error => this.#setClosed(error));\n }\n }\n /** Get the protocol version supported by the server. */\n async getVersion() {\n if (this._endpoint !== undefined) {\n return this._endpoint.version;\n }\n return (await this._endpointPromise).version;\n }\n // Make sure that the negotiated version is at least `minVersion`.\n /** @private */\n _ensureVersion(minVersion, feature) {\n if (minVersion <= fallbackEndpoint.version) {\n return;\n } else if (this._endpoint === undefined) {\n throw new ProtocolVersionError(`${feature} is supported only on protocol version ${minVersion} and higher, ` + \"but the version supported by the HTTP server is not yet known. \" + \"Use Client.getVersion() to wait until the version is available.\");\n } else if (this._endpoint.version < minVersion) {\n throw new ProtocolVersionError(`${feature} is supported only on protocol version ${minVersion} and higher, ` + `but the HTTP server only supports version ${this._endpoint.version}.`);\n }\n }\n /** Open a {@link HttpStream}, a stream for executing SQL statements. */\n openStream() {\n if (this.#closed !== undefined) {\n throw new ClosedError(\"Client is closed\", this.#closed);\n }\n const stream = new HttpStream(this, this.#url, this.#jwt, this.#fetch);\n this.#streams.add(stream);\n return stream;\n }\n /** @private */\n _streamClosed(stream) {\n this.#streams.delete(stream);\n }\n /** Close the client and all its streams. */\n close() {\n this.#setClosed(new ClientError(\"Client was manually closed\"));\n }\n /** True if the client is closed. */\n get closed() {\n return this.#closed !== undefined;\n }\n #setClosed(error) {\n if (this.#closed !== undefined) {\n return;\n }\n this.#closed = error;\n for (const stream of Array.from(this.#streams)) {\n stream._setClosed(new ClosedError(\"Client was closed\", error));\n }\n }\n}\nasync function findEndpoint(customFetch, clientUrl) {\n const fetch = customFetch;\n for (const endpoint of checkEndpoints) {\n const url = new URL(endpoint.versionPath, clientUrl);\n const request = new Request(url.toString(), {\n method: \"GET\"\n });\n const response = await fetch(request);\n await response.arrayBuffer();\n if (response.ok) {\n return endpoint;\n }\n }\n return fallbackEndpoint;\n}","map":{"version":3,"names":["fetch","Request","Client","ClientError","ClosedError","ProtocolVersionError","HttpStream","checkEndpoints","versionPath","pipelinePath","cursorPath","version","encoding","fallbackEndpoint","undefined","HttpClient","url","jwt","closed","streams","_endpointPromise","_endpoint","constructor","customFetch","protocolVersion","Set","findEndpoint","then","endpoint","error","setClosed","Promise","resolve","getVersion","_ensureVersion","minVersion","feature","openStream","stream","add","_streamClosed","delete","close","#setClosed","Array","from","_setClosed","clientUrl","URL","request","toString","method","response","arrayBuffer","ok"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/hrana-client/lib-esm/http/client.js"],"sourcesContent":["import { fetch, Request } from \"@libsql/isomorphic-fetch\";\nimport { Client } from \"../client.js\";\nimport { ClientError, ClosedError, ProtocolVersionError } from \"../errors.js\";\nimport { HttpStream } from \"./stream.js\";\nexport const checkEndpoints = [\n {\n versionPath: \"v3-protobuf\",\n pipelinePath: \"v3-protobuf/pipeline\",\n cursorPath: \"v3-protobuf/cursor\",\n version: 3,\n encoding: \"protobuf\",\n },\n /*\n {\n versionPath: \"v3\",\n pipelinePath: \"v3/pipeline\",\n cursorPath: \"v3/cursor\",\n version: 3,\n encoding: \"json\",\n },\n */\n];\nconst fallbackEndpoint = {\n versionPath: \"v2\",\n pipelinePath: \"v2/pipeline\",\n cursorPath: undefined,\n version: 2,\n encoding: \"json\",\n};\n/** A client for the Hrana protocol over HTTP. */\nexport class HttpClient extends Client {\n #url;\n #jwt;\n #fetch;\n #closed;\n #streams;\n /** @private */\n _endpointPromise;\n /** @private */\n _endpoint;\n /** @private */\n constructor(url, jwt, customFetch, protocolVersion = 2) {\n super();\n this.#url = url;\n this.#jwt = jwt;\n this.#fetch = customFetch ?? fetch;\n this.#closed = undefined;\n this.#streams = new Set();\n if (protocolVersion == 3) {\n this._endpointPromise = findEndpoint(this.#fetch, this.#url);\n this._endpointPromise.then((endpoint) => this._endpoint = endpoint, (error) => this.#setClosed(error));\n }\n else {\n this._endpointPromise = Promise.resolve(fallbackEndpoint);\n this._endpointPromise.then((endpoint) => this._endpoint = endpoint, (error) => this.#setClosed(error));\n }\n }\n /** Get the protocol version supported by the server. */\n async getVersion() {\n if (this._endpoint !== undefined) {\n return this._endpoint.version;\n }\n return (await this._endpointPromise).version;\n }\n // Make sure that the negotiated version is at least `minVersion`.\n /** @private */\n _ensureVersion(minVersion, feature) {\n if (minVersion <= fallbackEndpoint.version) {\n return;\n }\n else if (this._endpoint === undefined) {\n throw new ProtocolVersionError(`${feature} is supported only on protocol version ${minVersion} and higher, ` +\n \"but the version supported by the HTTP server is not yet known. \" +\n \"Use Client.getVersion() to wait until the version is available.\");\n }\n else if (this._endpoint.version < minVersion) {\n throw new ProtocolVersionError(`${feature} is supported only on protocol version ${minVersion} and higher, ` +\n `but the HTTP server only supports version ${this._endpoint.version}.`);\n }\n }\n /** Open a {@link HttpStream}, a stream for executing SQL statements. */\n openStream() {\n if (this.#closed !== undefined) {\n throw new ClosedError(\"Client is closed\", this.#closed);\n }\n const stream = new HttpStream(this, this.#url, this.#jwt, this.#fetch);\n this.#streams.add(stream);\n return stream;\n }\n /** @private */\n _streamClosed(stream) {\n this.#streams.delete(stream);\n }\n /** Close the client and all its streams. */\n close() {\n this.#setClosed(new ClientError(\"Client was manually closed\"));\n }\n /** True if the client is closed. */\n get closed() {\n return this.#closed !== undefined;\n }\n #setClosed(error) {\n if (this.#closed !== undefined) {\n return;\n }\n this.#closed = error;\n for (const stream of Array.from(this.#streams)) {\n stream._setClosed(new ClosedError(\"Client was closed\", error));\n }\n }\n}\nasync function findEndpoint(customFetch, clientUrl) {\n const fetch = customFetch;\n for (const endpoint of checkEndpoints) {\n const url = new URL(endpoint.versionPath, clientUrl);\n const request = new Request(url.toString(), { method: \"GET\" });\n const response = await fetch(request);\n await response.arrayBuffer();\n if (response.ok) {\n return endpoint;\n }\n }\n return fallbackEndpoint;\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,OAAO,QAAQ,0BAA0B;AACzD,SAASC,MAAM,QAAQ,cAAc;AACrC,SAASC,WAAW,EAAEC,WAAW,EAAEC,oBAAoB,QAAQ,cAAc;AAC7E,SAASC,UAAU,QAAQ,aAAa;AACxC,OAAO,MAAMC,cAAc,GAAG,CAC1B;EACIC,WAAW,EAAE,aAAa;EAC1BC,YAAY,EAAE,sBAAsB;EACpCC,UAAU,EAAE,oBAAoB;EAChCC,OAAO,EAAE,CAAC;EACVC,QAAQ,EAAE;AACd;AACA;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EARI,CASH;AACD,MAAMC,gBAAgB,GAAG;EAC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