{"ast":null,"code":"import * as hrana from \"@libsql/hrana-client\";\nimport { LibsqlError } from \"@libsql/core/api\";\nimport { expandConfig } from \"@libsql/core/config\";\nimport { HranaTransaction, executeHranaBatch, stmtToHrana, resultSetFromHrana, mapHranaError } from \"./hrana.js\";\nimport { SqlCache } from \"./sql_cache.js\";\nimport { encodeBaseUrl } from \"@libsql/core/uri\";\nimport { supportedUrlLink } from \"@libsql/core/util\";\nimport promiseLimit from \"promise-limit\";\nexport * from \"@libsql/core/api\";\nexport function createClient(config) {\n return _createClient(expandConfig(config, false));\n}\n/** @private */\nexport function _createClient(config) {\n if (config.scheme !== \"wss\" && config.scheme !== \"ws\") {\n throw new LibsqlError('The WebSocket client supports only \"libsql:\", \"wss:\" and \"ws:\" URLs, ' + `got ${JSON.stringify(config.scheme + \":\")}. For more information, please read ${supportedUrlLink}`, \"URL_SCHEME_NOT_SUPPORTED\");\n }\n if (config.encryptionKey !== undefined) {\n throw new LibsqlError(\"Encryption key is not supported by the remote client.\", \"ENCRYPTION_KEY_NOT_SUPPORTED\");\n }\n if (config.scheme === \"ws\" && config.tls) {\n throw new LibsqlError(`A \"ws:\" URL cannot opt into TLS by using ?tls=1`, \"URL_INVALID\");\n } else if (config.scheme === \"wss\" && !config.tls) {\n throw new LibsqlError(`A \"wss:\" URL cannot opt out of TLS by using ?tls=0`, \"URL_INVALID\");\n }\n const url = encodeBaseUrl(config.scheme, config.authority, config.path);\n let client;\n try {\n client = hrana.openWs(url, config.authToken);\n } catch (e) {\n if (e instanceof hrana.WebSocketUnsupportedError) {\n const suggestedScheme = config.scheme === \"wss\" ? \"https\" : \"http\";\n const suggestedUrl = encodeBaseUrl(suggestedScheme, config.authority, config.path);\n throw new LibsqlError(\"This environment does not support WebSockets, please switch to the HTTP client by using \" + `a \"${suggestedScheme}:\" URL (${JSON.stringify(suggestedUrl)}). ` + `For more information, please read ${supportedUrlLink}`, \"WEBSOCKETS_NOT_SUPPORTED\");\n }\n throw mapHranaError(e);\n }\n return new WsClient(client, url, config.authToken, config.intMode, config.concurrency);\n}\nconst maxConnAgeMillis = 60 * 1000;\nconst sqlCacheCapacity = 100;\nexport class WsClient {\n #url;\n #authToken;\n #intMode;\n // State of the current connection. The `hrana.WsClient` inside may be closed at any moment due to an\n // asynchronous error.\n #connState;\n // If defined, this is a connection that will be used in the future, once it is ready.\n #futureConnState;\n closed;\n protocol;\n #isSchemaDatabase;\n #promiseLimitFunction;\n /** @private */\n constructor(client, url, authToken, intMode, concurrency) {\n this.#url = url;\n this.#authToken = authToken;\n this.#intMode = intMode;\n this.#connState = this.#openConn(client);\n this.#futureConnState = undefined;\n this.closed = false;\n this.protocol = \"ws\";\n this.#promiseLimitFunction = promiseLimit(concurrency);\n }\n async limit(fn) {\n return this.#promiseLimitFunction(fn);\n }\n async execute(stmtOrSql, args) {\n let stmt;\n if (typeof stmtOrSql === \"string\") {\n stmt = {\n sql: stmtOrSql,\n args: args || []\n };\n } else {\n stmt = stmtOrSql;\n }\n return this.limit(async () => {\n const streamState = await this.#openStream();\n try {\n const hranaStmt = stmtToHrana(stmt);\n // Schedule all operations synchronously, so they will be pipelined and executed in a single\n // network roundtrip.\n streamState.conn.sqlCache.apply([hranaStmt]);\n const hranaRowsPromise = streamState.stream.query(hranaStmt);\n streamState.stream.closeGracefully();\n const hranaRowsResult = await hranaRowsPromise;\n return resultSetFromHrana(hranaRowsResult);\n } catch (e) {\n throw mapHranaError(e);\n } finally {\n this._closeStream(streamState);\n }\n });\n }\n async batch(stmts, mode = \"deferred\") {\n return this.limit(async () => {\n const streamState = await this.#openStream();\n try {\n const hranaStmts = stmts.map(stmtToHrana);\n const version = await streamState.conn.client.getVersion();\n // Schedule all operations synchronously, so they will be pipelined and executed in a single\n // network roundtrip.\n streamState.conn.sqlCache.apply(hranaStmts);\n const batch = streamState.stream.batch(version >= 3);\n const resultsPromise = executeHranaBatch(mode, version, batch, hranaStmts);\n const results = await resultsPromise;\n return results;\n } catch (e) {\n throw mapHranaError(e);\n } finally {\n this._closeStream(streamState);\n }\n });\n }\n async migrate(stmts) {\n return this.limit(async () => {\n const streamState = await this.#openStream();\n try {\n const hranaStmts = stmts.map(stmtToHrana);\n const version = await streamState.conn.client.getVersion();\n // Schedule all operations synchronously, so they will be pipelined and executed in a single\n // network roundtrip.\n const batch = streamState.stream.batch(version >= 3);\n const resultsPromise = executeHranaBatch(\"deferred\", version, batch, hranaStmts, true);\n const results = await resultsPromise;\n return results;\n } catch (e) {\n throw mapHranaError(e);\n } finally {\n this._closeStream(streamState);\n }\n });\n }\n async transaction(mode = \"write\") {\n return this.limit(async () => {\n const streamState = await this.#openStream();\n try {\n const version = await streamState.conn.client.getVersion();\n // the BEGIN statement will be batched with the first statement on the transaction to save a\n // network roundtrip\n return new WsTransaction(this, streamState, mode, version);\n } catch (e) {\n this._closeStream(streamState);\n throw mapHranaError(e);\n }\n });\n }\n async executeMultiple(sql) {\n return this.limit(async () => {\n const streamState = await this.#openStream();\n try {\n // Schedule all operations synchronously, so they will be pipelined and executed in a single\n // network roundtrip.\n const promise = streamState.stream.sequence(sql);\n streamState.stream.closeGracefully();\n await promise;\n } catch (e) {\n throw mapHranaError(e);\n } finally {\n this._closeStream(streamState);\n }\n });\n }\n sync() {\n throw new LibsqlError(\"sync not supported in ws mode\", \"SYNC_NOT_SUPPORTED\");\n }\n async #openStream() {\n if (this.closed) {\n throw new LibsqlError(\"The client is closed\", \"CLIENT_CLOSED\");\n }\n const now = new Date();\n const ageMillis = now.valueOf() - this.#connState.openTime.valueOf();\n if (ageMillis > maxConnAgeMillis && this.#futureConnState === undefined) {\n // The existing connection is too old, let's open a new one.\n const futureConnState = this.#openConn();\n this.#futureConnState = futureConnState;\n // However, if we used `futureConnState` immediately, we would introduce additional latency,\n // because we would have to wait for the WebSocket handshake to complete, even though we may a\n // have perfectly good existing connection in `this.#connState`!\n //\n // So we wait until the `hrana.Client.getVersion()` operation completes (which happens when the\n // WebSocket hanshake completes), and only then we replace `this.#connState` with\n // `futureConnState`, which is stored in `this.#futureConnState` in the meantime.\n futureConnState.client.getVersion().then(_version => {\n if (this.#connState !== futureConnState) {\n // We need to close `this.#connState` before we replace it. However, it is possible\n // that `this.#connState` has already been replaced: see the code below.\n if (this.#connState.streamStates.size === 0) {\n this.#connState.client.close();\n } else {\n // If there are existing streams on the connection, we must not close it, because\n // these streams would be broken. The last stream to be closed will also close the\n // connection in `_closeStream()`.\n }\n }\n this.#connState = futureConnState;\n this.#futureConnState = undefined;\n }, _e => {\n // If the new connection could not be established, let's just ignore the error and keep\n // using the existing connection.\n this.#futureConnState = undefined;\n });\n }\n if (this.#connState.client.closed) {\n // An error happened on this connection and it has been closed. Let's try to seamlessly reconnect.\n try {\n if (this.#futureConnState !== undefined) {\n // We are already in the process of opening a new connection, so let's just use it\n // immediately.\n this.#connState = this.#futureConnState;\n } else {\n this.#connState = this.#openConn();\n }\n } catch (e) {\n throw mapHranaError(e);\n }\n }\n const connState = this.#connState;\n try {\n // Now we wait for the WebSocket handshake to complete (if it hasn't completed yet). Note that\n // this does not increase latency, because any messages that we would send on the WebSocket before\n // the handshake would be queued until the handshake is completed anyway.\n if (connState.useSqlCache === undefined) {\n connState.useSqlCache = (await connState.client.getVersion()) >= 2;\n if (connState.useSqlCache) {\n connState.sqlCache.capacity = sqlCacheCapacity;\n }\n }\n const stream = connState.client.openStream();\n stream.intMode = this.#intMode;\n const streamState = {\n conn: connState,\n stream\n };\n connState.streamStates.add(streamState);\n return streamState;\n } catch (e) {\n throw mapHranaError(e);\n }\n }\n #openConn(client) {\n try {\n client ??= hrana.openWs(this.#url, this.#authToken);\n return {\n client,\n useSqlCache: undefined,\n sqlCache: new SqlCache(client, 0),\n openTime: new Date(),\n streamStates: new Set()\n };\n } catch (e) {\n throw mapHranaError(e);\n }\n }\n _closeStream(streamState) {\n streamState.stream.close();\n const connState = streamState.conn;\n connState.streamStates.delete(streamState);\n if (connState.streamStates.size === 0 && connState !== this.#connState) {\n // We are not using this connection anymore and this is the last stream that was using it, so we\n // must close it now.\n connState.client.close();\n }\n }\n close() {\n this.#connState.client.close();\n this.closed = true;\n }\n}\nexport class WsTransaction extends HranaTransaction {\n #client;\n #streamState;\n /** @private */\n constructor(client, state, mode, version) {\n super(mode, version);\n this.#client = client;\n this.#streamState = state;\n }\n /** @private */\n _getStream() {\n return this.#streamState.stream;\n }\n /** @private */\n _getSqlCache() {\n return this.#streamState.conn.sqlCache;\n }\n close() {\n this.#client._closeStream(this.#streamState);\n }\n get closed() {\n return this.#streamState.stream.closed;\n }\n}","map":{"version":3,"names":["hrana","LibsqlError","expandConfig","HranaTransaction","executeHranaBatch","stmtToHrana","resultSetFromHrana","mapHranaError","SqlCache","encodeBaseUrl","supportedUrlLink","promiseLimit","createClient","config","_createClient","scheme","JSON","stringify","encryptionKey","undefined","tls","url","authority","path","client","openWs","authToken","e","WebSocketUnsupportedError","suggestedScheme","suggestedUrl","WsClient","intMode","concurrency","maxConnAgeMillis","sqlCacheCapacity","connState","futureConnState","closed","protocol","isSchemaDatabase","promiseLimitFunction","constructor","openConn","limit","fn","execute","stmtOrSql","args","stmt","sql","streamState","openStream","hranaStmt","conn","sqlCache","apply","hranaRowsPromise","stream","query","closeGracefully","hranaRowsResult","_closeStream","batch","stmts","mode","hranaStmts","map","version","getVersion","resultsPromise","results","migrate","transaction","WsTransaction","executeMultiple","promise","sequence","sync","#openStream","now","Date","ageMillis","valueOf","openTime","then","_version","streamStates","size","close","_e","useSqlCache","capacity","add","#openConn","Set","delete","state","_getStream","_getSqlCache"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/client/lib-esm/ws.js"],"sourcesContent":["import * as hrana from \"@libsql/hrana-client\";\nimport { LibsqlError } from \"@libsql/core/api\";\nimport { expandConfig } from \"@libsql/core/config\";\nimport { HranaTransaction, executeHranaBatch, stmtToHrana, resultSetFromHrana, mapHranaError, } from \"./hrana.js\";\nimport { SqlCache } from \"./sql_cache.js\";\nimport { encodeBaseUrl } from \"@libsql/core/uri\";\nimport { supportedUrlLink } from \"@libsql/core/util\";\nimport promiseLimit from \"promise-limit\";\nexport * from \"@libsql/core/api\";\nexport function createClient(config) {\n return _createClient(expandConfig(config, false));\n}\n/** @private */\nexport function _createClient(config) {\n if (config.scheme !== \"wss\" && config.scheme !== \"ws\") {\n throw new LibsqlError('The WebSocket client supports only \"libsql:\", \"wss:\" and \"ws:\" URLs, ' +\n `got ${JSON.stringify(config.scheme + \":\")}. For more information, please read ${supportedUrlLink}`, \"URL_SCHEME_NOT_SUPPORTED\");\n }\n if (config.encryptionKey !== undefined) {\n throw new LibsqlError(\"Encryption key is not supported by the remote client.\", \"ENCRYPTION_KEY_NOT_SUPPORTED\");\n }\n if (config.scheme === \"ws\" && config.tls) {\n throw new LibsqlError(`A \"ws:\" URL cannot opt into TLS by using ?tls=1`, \"URL_INVALID\");\n }\n else if (config.scheme === \"wss\" && !config.tls) {\n throw new LibsqlError(`A \"wss:\" URL cannot opt out of TLS by using ?tls=0`, \"URL_INVALID\");\n }\n const url = encodeBaseUrl(config.scheme, config.authority, config.path);\n let client;\n try {\n client = hrana.openWs(url, config.authToken);\n }\n catch (e) {\n if (e instanceof hrana.WebSocketUnsupportedError) {\n const suggestedScheme = config.scheme === \"wss\" ? \"https\" : \"http\";\n const suggestedUrl = encodeBaseUrl(suggestedScheme, config.authority, config.path);\n throw new LibsqlError(\"This environment does not support WebSockets, please switch to the HTTP client by using \" +\n `a \"${suggestedScheme}:\" URL (${JSON.stringify(suggestedUrl)}). ` +\n `For more information, please read ${supportedUrlLink}`, \"WEBSOCKETS_NOT_SUPPORTED\");\n }\n throw mapHranaError(e);\n }\n return new WsClient(client, url, config.authToken, config.intMode, config.concurrency);\n}\nconst maxConnAgeMillis = 60 * 1000;\nconst sqlCacheCapacity = 100;\nexport class WsClient {\n #url;\n #authToken;\n #intMode;\n // State of the current connection. The `hrana.WsClient` inside may be closed at any moment due to an\n // asynchronous error.\n #connState;\n // If defined, this is a connection that will be used in the future, once it is ready.\n #futureConnState;\n closed;\n protocol;\n #isSchemaDatabase;\n #promiseLimitFunction;\n /** @private */\n constructor(client, url, authToken, intMode, concurrency) {\n this.#url = url;\n this.#authToken = authToken;\n this.#intMode = intMode;\n this.#connState = this.#openConn(client);\n this.#futureConnState = undefined;\n this.closed = false;\n this.protocol = \"ws\";\n this.#promiseLimitFunction = promiseLimit(concurrency);\n }\n async limit(fn) {\n return this.#promiseLimitFunction(fn);\n }\n async execute(stmtOrSql, args) {\n let stmt;\n if (typeof stmtOrSql === \"string\") {\n stmt = {\n sql: stmtOrSql,\n args: args || [],\n };\n }\n else {\n stmt = stmtOrSql;\n }\n return this.limit(async () => {\n const streamState = await this.#openStream();\n try {\n const hranaStmt = stmtToHrana(stmt);\n // Schedule all operations synchronously, so they will be pipelined and executed in a single\n // network roundtrip.\n streamState.conn.sqlCache.apply([hranaStmt]);\n const hranaRowsPromise = streamState.stream.query(hranaStmt);\n streamState.stream.closeGracefully();\n const hranaRowsResult = await hranaRowsPromise;\n return resultSetFromHrana(hranaRowsResult);\n }\n catch (e) {\n throw mapHranaError(e);\n }\n finally {\n this._closeStream(streamState);\n }\n });\n }\n async batch(stmts, mode = \"deferred\") {\n return this.limit(async () => {\n const streamState = await this.#openStream();\n try {\n const hranaStmts = stmts.map(stmtToHrana);\n const version = await streamState.conn.client.getVersion();\n // Schedule all operations synchronously, so they will be pipelined and executed in a single\n // network roundtrip.\n streamState.conn.sqlCache.apply(hranaStmts);\n const batch = streamState.stream.batch(version >= 3);\n const resultsPromise = executeHranaBatch(mode, version, batch, hranaStmts);\n const results = await resultsPromise;\n return results;\n }\n catch (e) {\n throw mapHranaError(e);\n }\n finally {\n this._closeStream(streamState);\n }\n });\n }\n async migrate(stmts) {\n return this.limit(async () => {\n const streamState = await this.#openStream();\n try {\n const hranaStmts = stmts.map(stmtToHrana);\n const version = await streamState.conn.client.getVersion();\n // Schedule all operations synchronously, so they will be pipelined and executed in a single\n // network roundtrip.\n const batch = streamState.stream.batch(version >= 3);\n const resultsPromise = executeHranaBatch(\"deferred\", version, batch, hranaStmts, true);\n const results = await resultsPromise;\n return results;\n }\n catch (e) {\n throw mapHranaError(e);\n }\n finally {\n this._closeStream(streamState);\n }\n });\n }\n async transaction(mode = \"write\") {\n return this.limit(async () => {\n const streamState = await this.#openStream();\n try {\n const version = await streamState.conn.client.getVersion();\n // the BEGIN statement will be batched with the first statement on the transaction to save a\n // network roundtrip\n return new WsTransaction(this, streamState, mode, version);\n }\n catch (e) {\n this._closeStream(streamState);\n throw mapHranaError(e);\n }\n });\n }\n async executeMultiple(sql) {\n return this.limit(async () => {\n const streamState = await this.#openStream();\n try {\n // Schedule all operations synchronously, so they will be pipelined and executed in a single\n // network roundtrip.\n const promise = streamState.stream.sequence(sql);\n streamState.stream.closeGracefully();\n await promise;\n }\n catch (e) {\n throw mapHranaError(e);\n }\n finally {\n this._closeStream(streamState);\n }\n });\n }\n sync() {\n throw new LibsqlError(\"sync not supported in ws mode\", \"SYNC_NOT_SUPPORTED\");\n }\n async #openStream() {\n if (this.closed) {\n throw new LibsqlError(\"The client is closed\", \"CLIENT_CLOSED\");\n }\n const now = new Date();\n const ageMillis = now.valueOf() - this.#connState.openTime.valueOf();\n if (ageMillis > maxConnAgeMillis &&\n this.#futureConnState === undefined) {\n // The existing connection is too old, let's open a new one.\n const futureConnState = this.#openConn();\n this.#futureConnState = futureConnState;\n // However, if we used `futureConnState` immediately, we would introduce additional latency,\n // because we would have to wait for the WebSocket handshake to complete, even though we may a\n // have perfectly good existing connection in `this.#connState`!\n //\n // So we wait until the `hrana.Client.getVersion()` operation completes (which happens when the\n // WebSocket hanshake completes), and only then we replace `this.#connState` with\n // `futureConnState`, which is stored in `this.#futureConnState` in the meantime.\n futureConnState.client.getVersion().then((_version) => {\n if (this.#connState !== futureConnState) {\n // We need to close `this.#connState` before we replace it. However, it is possible\n // that `this.#connState` has already been replaced: see the code below.\n if (this.#connState.streamStates.size === 0) {\n this.#connState.client.close();\n }\n else {\n // If there are existing streams on the connection, we must not close it, because\n // these streams would be broken. The last stream to be closed will also close the\n // connection in `_closeStream()`.\n }\n }\n this.#connState = futureConnState;\n this.#futureConnState = undefined;\n }, (_e) => {\n // If the new connection could not be established, let's just ignore the error and keep\n // using the existing connection.\n this.#futureConnState = undefined;\n });\n }\n if (this.#connState.client.closed) {\n // An error happened on this connection and it has been closed. Let's try to seamlessly reconnect.\n try {\n if (this.#futureConnState !== undefined) {\n // We are already in the process of opening a new connection, so let's just use it\n // immediately.\n this.#connState = this.#futureConnState;\n }\n else {\n this.#connState = this.#openConn();\n }\n }\n catch (e) {\n throw mapHranaError(e);\n }\n }\n const connState = this.#connState;\n try {\n // Now we wait for the WebSocket handshake to complete (if it hasn't completed yet). Note that\n // this does not increase latency, because any messages that we would send on the WebSocket before\n // the handshake would be queued until the handshake is completed anyway.\n if (connState.useSqlCache === undefined) {\n connState.useSqlCache =\n (await connState.client.getVersion()) >= 2;\n if (connState.useSqlCache) {\n connState.sqlCache.capacity = sqlCacheCapacity;\n }\n }\n const stream = connState.client.openStream();\n stream.intMode = this.#intMode;\n const streamState = { conn: connState, stream };\n connState.streamStates.add(streamState);\n return streamState;\n }\n catch (e) {\n throw mapHranaError(e);\n }\n }\n #openConn(client) {\n try {\n client ??= hrana.openWs(this.#url, this.#authToken);\n return {\n client,\n useSqlCache: undefined,\n sqlCache: new SqlCache(client, 0),\n openTime: new Date(),\n streamStates: new Set(),\n };\n }\n catch (e) {\n throw mapHranaError(e);\n }\n }\n _closeStream(streamState) {\n streamState.stream.close();\n const connState = streamState.conn;\n connState.streamStates.delete(streamState);\n if (connState.streamStates.size === 0 &&\n connState !== this.#connState) {\n // We are not using this connection anymore and this is the last stream that was using it, so we\n // must close it now.\n connState.client.close();\n }\n }\n close() {\n this.#connState.client.close();\n this.closed = true;\n }\n}\nexport class WsTransaction extends HranaTransaction {\n #client;\n #streamState;\n /** @private */\n constructor(client, state, mode, version) {\n super(mode, version);\n this.#client = client;\n this.#streamState = state;\n }\n /** @private */\n _getStream() {\n return this.#streamState.stream;\n }\n /** @private */\n _getSqlCache() {\n return this.#streamState.conn.sqlCache;\n }\n close() {\n this.#client._closeStream(this.#streamState);\n }\n get closed() {\n return this.#streamState.stream.closed;\n }\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,sBAAsB;AAC7C,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,gBAAgB,EAAEC,iBAAiB,EAAEC,WAAW,EAAEC,kBAAkB,EAAEC,aAAa,QAAS,YAAY;AACjH,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,gBAAgB,QAAQ,mBAAmB;AACpD,OAAOC,YAAY,MAAM,eAAe;AACxC,cAAc,kBAAkB;AAChC,OAAO,SAASC,YAAYA,CAACC,MAAM,EAAE;EACjC,OAAOC,aAAa,CAACZ,YAAY,CAACW,MAAM,EAAE,KAAK,CAAC,CAAC;AACrD;AACA;AACA,OAAO,SAASC,aAAaA,CAACD,MAAM,EAAE;EAClC,IAAIA,MAAM,CAACE,MAAM,KAAK,KAAK,IAAIF,MAAM,CAACE,MAAM,KAAK,IAAI,EAAE;IACnD,MAAM,IAAId,WAAW,CAAC,uEAAuE,GACzF,OAAOe,IAAI,CAACC,SAAS,CAACJ,MAAM,CAACE,MAAM,GAAG,GAAG,CAAC,uCAAuCL,gBAAgB,EAAE,EAAE,0BAA0B,CAAC;EACxI;EACA,IAAIG,MAAM,CAACK,aAAa,KAAKC,SAAS,EAAE;IACpC,MAAM,IAAIlB,WAAW,CAAC,uDAAuD,EAAE,8BAA8B,CAAC;EAClH;EACA,IAAIY,MAAM,CAACE,MAAM,KAAK,IAAI,IAAIF,MAAM,CAACO,GAAG,EAAE;IACtC,MAAM,IAAInB,WAAW,CAAC,iDAAiD,EAAE,aAAa,CAAC;EAC3F,CAAC,MACI,IAAIY,MAAM,CAACE,MAAM,KAAK,KAAK,IAAI,CAACF,MAAM,CAAC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