UNPKG

@catalystlabs/tryai

Version:

Dead simple AI library. One line setup. Zero config. Just works.

1 lines 1.43 MB
{"version":3,"sources":["../node_modules/tarn/dist/TimeoutError.js","../node_modules/tarn/dist/PromiseInspection.js","../node_modules/tarn/dist/utils.js","../node_modules/tarn/dist/PendingOperation.js","../node_modules/tarn/dist/Resource.js","../node_modules/tarn/dist/Pool.js","../node_modules/tarn/dist/tarn.js","../node_modules/knex/lib/util/string.js","../node_modules/lodash/_listCacheClear.js","../node_modules/lodash/eq.js","../node_modules/lodash/_assocIndexOf.js","../node_modules/lodash/_listCacheDelete.js","../node_modules/lodash/_listCacheGet.js","../node_modules/lodash/_listCacheHas.js","../node_modules/lodash/_listCacheSet.js","../node_modules/lodash/_ListCache.js","../node_modules/lodash/_stackClear.js","../node_modules/lodash/_stackDelete.js","../node_modules/lodash/_stackGet.js","../node_modules/lodash/_stackHas.js","../node_modules/lodash/_freeGlobal.js","../node_modules/lodash/_root.js","../node_modules/lodash/_Symbol.js","../node_modules/lodash/_getRawTag.js","../node_modules/lodash/_objectToString.js","../node_modules/lodash/_baseGetTag.js","../node_modules/lodash/isObject.js","../node_modules/lodash/isFunction.js","../node_modules/lodash/_coreJsData.js","../node_modules/lodash/_isMasked.js","../node_modules/lodash/_toSource.js","../node_modules/lodash/_baseIsNative.js","../node_modules/lodash/_getValue.js","../node_modules/lodash/_getNative.js","../node_modules/lodash/_Map.js","../node_modules/lodash/_nativeCreate.js","../node_modules/lodash/_hashClear.js","../node_modules/lodash/_hashDelete.js","../node_modules/lodash/_hashGet.js","../node_modules/lodash/_hashHas.js","../node_modules/lodash/_hashSet.js","../node_modules/lodash/_Hash.js","../node_modules/lodash/_mapCacheClear.js","../node_modules/lodash/_isKeyable.js","../node_modules/lodash/_getMapData.js","../node_modules/lodash/_mapCacheDelete.js","../node_modules/lodash/_mapCacheGet.js","../node_modules/lodash/_mapCacheHas.js","../node_modules/lodash/_mapCacheSet.js","../node_modules/lodash/_MapCache.js","../node_modules/lodash/_stackSet.js","../node_modules/lodash/_Stack.js","../node_modules/lodash/_arrayEach.js","../node_modules/lodash/_defineProperty.js","../node_modules/lodash/_baseAssignValue.js","../node_modules/lodash/_assignValue.js","../node_modules/lodash/_copyObject.js","../node_modules/lodash/_baseTimes.js","../node_modules/lodash/isObjectLike.js","../node_modules/lodash/_baseIsArguments.js","../node_modules/lodash/isArguments.js","../node_modules/lodash/isArray.js","../node_modules/lodash/stubFalse.js","../node_modules/lodash/isBuffer.js","../node_modules/lodash/_isIndex.js","../node_modules/lodash/isLength.js","../node_modules/lodash/_baseIsTypedArray.js","../node_modules/lodash/_baseUnary.js","../node_modules/lodash/_nodeUtil.js","../node_modules/lodash/isTypedArray.js","../node_modules/lodash/_arrayLikeKeys.js","../node_modules/lodash/_isPrototype.js","../node_modules/lodash/_overArg.js","../node_modules/lodash/_nativeKeys.js","../node_modules/lodash/_baseKeys.js","../node_modules/lodash/isArrayLike.js","../node_modules/lodash/keys.js","../node_modules/lodash/_baseAssign.js","../node_modules/lodash/_nativeKeysIn.js","../node_modules/lodash/_baseKeysIn.js","../node_modules/lodash/keysIn.js","../node_modules/lodash/_baseAssignIn.js","../node_modules/lodash/_cloneBuffer.js","../node_modules/lodash/_copyArray.js","../node_modules/lodash/_arrayFilter.js","../node_modules/lodash/stubArray.js","../node_modules/lodash/_getSymbols.js","../node_modules/lodash/_copySymbols.js","../node_modules/lodash/_arrayPush.js","../node_modules/lodash/_getPrototype.js","../node_modules/lodash/_getSymbolsIn.js","../node_modules/lodash/_copySymbolsIn.js","../node_modules/lodash/_baseGetAllKeys.js","../node_modules/lodash/_getAllKeys.js","../node_modules/lodash/_getAllKeysIn.js","../node_modules/lodash/_DataView.js","../node_modules/lodash/_Promise.js","../node_modules/lodash/_Set.js","../node_modules/lodash/_WeakMap.js","../node_modules/lodash/_getTag.js","../node_modules/lodash/_initCloneArray.js","../node_modules/lodash/_Uint8Array.js","../node_modules/lodash/_cloneArrayBuffer.js","../node_modules/lodash/_cloneDataView.js","../node_modules/lodash/_cloneRegExp.js","../node_modules/lodash/_cloneSymbol.js","../node_modules/lodash/_cloneTypedArray.js","../node_modules/lodash/_initCloneByTag.js","../node_modules/lodash/_baseCreate.js","../node_modules/lodash/_initCloneObject.js","../node_modules/lodash/_baseIsMap.js","../node_modules/lodash/isMap.js","../node_modules/lodash/_baseIsSet.js","../node_modules/lodash/isSet.js","../node_modules/lodash/_baseClone.js","../node_modules/lodash/cloneDeep.js","../node_modules/lodash/identity.js","../node_modules/lodash/_apply.js","../node_modules/lodash/_overRest.js","../node_modules/lodash/constant.js","../node_modules/lodash/_baseSetToString.js","../node_modules/lodash/_shortOut.js","../node_modules/lodash/_setToString.js","../node_modules/lodash/_baseRest.js","../node_modules/lodash/_isIterateeCall.js","../node_modules/lodash/defaults.js","../node_modules/lodash/_arrayMap.js","../node_modules/lodash/isSymbol.js","../node_modules/lodash/_baseToString.js","../node_modules/lodash/toString.js","../node_modules/lodash/uniqueId.js","../node_modules/knex/lib/util/timeout.js","../node_modules/knex/lib/execution/internal/ensure-connection-callback.js","../node_modules/knex/lib/execution/runner.js","../node_modules/ms/index.js","../node_modules/debug/src/common.js","../node_modules/debug/src/browser.js","../node_modules/has-flag/index.js","../node_modules/supports-color/index.js","../node_modules/debug/src/node.js","../node_modules/debug/src/index.js","../node_modules/lodash/_setCacheAdd.js","../node_modules/lodash/_setCacheHas.js","../node_modules/lodash/_SetCache.js","../node_modules/lodash/_baseFindIndex.js","../node_modules/lodash/_baseIsNaN.js","../node_modules/lodash/_strictIndexOf.js","../node_modules/lodash/_baseIndexOf.js","../node_modules/lodash/_arrayIncludes.js","../node_modules/lodash/_arrayIncludesWith.js","../node_modules/lodash/_cacheHas.js","../node_modules/lodash/_baseDifference.js","../node_modules/lodash/_isFlattenable.js","../node_modules/lodash/_baseFlatten.js","../node_modules/lodash/isArrayLikeObject.js","../node_modules/lodash/last.js","../node_modules/lodash/differenceWith.js","../node_modules/lodash/_isKey.js","../node_modules/lodash/memoize.js","../node_modules/lodash/_memoizeCapped.js","../node_modules/lodash/_stringToPath.js","../node_modules/lodash/_castPath.js","../node_modules/lodash/_toKey.js","../node_modules/lodash/_baseGet.js","../node_modules/lodash/get.js","../node_modules/lodash/isEmpty.js","../node_modules/lodash/_baseExtremum.js","../node_modules/lodash/_baseGt.js","../node_modules/lodash/max.js","../node_modules/knex/lib/migrations/migrate/table-resolver.js","../node_modules/knex/lib/migrations/migrate/table-creator.js","../node_modules/knex/lib/migrations/migrate/migration-list-resolver.js","../node_modules/lodash/_createAssigner.js","../node_modules/lodash/assignInWith.js","../node_modules/lodash/isPlainObject.js","../node_modules/lodash/isError.js","../node_modules/lodash/attempt.js","../node_modules/lodash/_baseValues.js","../node_modules/lodash/_customDefaultsAssignIn.js","../node_modules/lodash/_escapeStringChar.js","../node_modules/lodash/_reInterpolate.js","../node_modules/lodash/_basePropertyOf.js","../node_modules/lodash/_escapeHtmlChar.js","../node_modules/lodash/escape.js","../node_modules/lodash/_reEscape.js","../node_modules/lodash/_reEvaluate.js","../node_modules/lodash/templateSettings.js","../node_modules/lodash/template.js","../node_modules/lodash/flatten.js","../node_modules/knex/lib/migrations/util/fs.js","../node_modules/knex/lib/migrations/util/template.js","../node_modules/lodash/_arraySome.js","../node_modules/lodash/_equalArrays.js","../node_modules/lodash/_mapToArray.js","../node_modules/lodash/_setToArray.js","../node_modules/lodash/_equalByTag.js","../node_modules/lodash/_equalObjects.js","../node_modules/lodash/_baseIsEqualDeep.js","../node_modules/lodash/_baseIsEqual.js","../node_modules/lodash/_baseIsMatch.js","../node_modules/lodash/_isStrictComparable.js","../node_modules/lodash/_getMatchData.js","../node_modules/lodash/_matchesStrictComparable.js","../node_modules/lodash/_baseMatches.js","../node_modules/lodash/_baseHasIn.js","../node_modules/lodash/_hasPath.js","../node_modules/lodash/hasIn.js","../node_modules/lodash/_baseMatchesProperty.js","../node_modules/lodash/_baseProperty.js","../node_modules/lodash/_basePropertyDeep.js","../node_modules/lodash/property.js","../node_modules/lodash/_baseIteratee.js","../node_modules/lodash/_createBaseFor.js","../node_modules/lodash/_baseFor.js","../node_modules/lodash/_baseForOwn.js","../node_modules/lodash/_createBaseEach.js","../node_modules/lodash/_baseEach.js","../node_modules/lodash/_baseMap.js","../node_modules/lodash/_baseSortBy.js","../node_modules/lodash/_compareAscending.js","../node_modules/lodash/_compareMultiple.js","../node_modules/lodash/_baseOrderBy.js","../node_modules/lodash/sortBy.js","../node_modules/get-package-type/is-node-modules.cjs","../node_modules/get-package-type/cache.cjs","../node_modules/get-package-type/async.cjs","../node_modules/get-package-type/sync.cjs","../node_modules/get-package-type/index.cjs","../node_modules/knex/lib/migrations/util/is-module-type.js","../node_modules/knex/lib/migrations/util/import-file.js","../node_modules/knex/lib/migrations/common/MigrationsLoader.js","../node_modules/knex/lib/migrations/migrate/sources/fs-migrations.js","../node_modules/colorette/index.cjs","../node_modules/knex/lib/util/is.js","../node_modules/knex/lib/logger.js","../node_modules/knex/lib/migrations/migrate/migrator-configuration-merger.js","../node_modules/knex/lib/migrations/util/timestamp.js","../node_modules/knex/lib/migrations/migrate/MigrationGenerator.js","../node_modules/knex/lib/migrations/migrate/Migrator.js","../node_modules/lodash/isString.js","../node_modules/lodash/_trimmedEndIndex.js","../node_modules/lodash/_baseTrim.js","../node_modules/lodash/toNumber.js","../node_modules/lodash/toFinite.js","../node_modules/lodash/toInteger.js","../node_modules/lodash/values.js","../node_modules/lodash/includes.js","../node_modules/knex/lib/migrations/seed/sources/fs-seeds.js","../node_modules/knex/lib/migrations/seed/seeder-configuration-merger.js","../node_modules/knex/lib/migrations/seed/Seeder.js","../node_modules/knex/lib/knex-builder/FunctionHelper.js","../node_modules/knex/lib/query/method-constants.js","../node_modules/lodash/_assignMergeValue.js","../node_modules/lodash/_safeGet.js","../node_modules/lodash/toPlainObject.js","../node_modules/lodash/_baseMergeDeep.js","../node_modules/lodash/_baseMerge.js","../node_modules/lodash/merge.js","../node_modules/lodash/_baseSlice.js","../node_modules/lodash/chunk.js","../node_modules/knex/lib/execution/internal/delay.js","../node_modules/knex/lib/execution/batch-insert.js","../node_modules/knex/lib/util/security.js","../node_modules/knex/lib/knex-builder/make-knex.js","../node_modules/knex/lib/util/noop.js","../node_modules/knex/lib/util/finally-mixin.js","../node_modules/knex/lib/execution/transaction.js","../node_modules/knex/lib/execution/internal/query-executioner.js","../node_modules/lodash/assign.js","../node_modules/lodash/clone.js","../node_modules/lodash/_castFunction.js","../node_modules/lodash/forEach.js","../node_modules/lodash/each.js","../node_modules/lodash/_baseFilter.js","../node_modules/lodash/negate.js","../node_modules/lodash/reject.js","../node_modules/lodash/tail.js","../node_modules/lodash/_iteratorToArray.js","../node_modules/lodash/_asciiToArray.js","../node_modules/lodash/_hasUnicode.js","../node_modules/lodash/_unicodeToArray.js","../node_modules/lodash/_stringToArray.js","../node_modules/lodash/toArray.js","../node_modules/knex/lib/constants.js","../node_modules/knex/lib/util/helpers.js","../node_modules/knex/lib/query/joinclause.js","../node_modules/knex/lib/query/analytic.js","../node_modules/knex/lib/util/save-async-stack.js","../node_modules/knex/lib/query/constants.js","../node_modules/knex/lib/builder-interface-augmenter.js","../node_modules/knex/lib/query/querybuilder.js","../node_modules/lodash/_arrayReduce.js","../node_modules/lodash/_baseReduce.js","../node_modules/lodash/reduce.js","../node_modules/lodash/transform.js","../node_modules/knex/lib/formatter/formatterUtils.js","../node_modules/knex/lib/formatter/wrappingFormatter.js","../node_modules/knex/lib/formatter/rawFormatter.js","../node_modules/knex/lib/util/nanoid.js","../node_modules/knex/lib/raw.js","../node_modules/lodash/compact.js","../node_modules/lodash/_arrayAggregator.js","../node_modules/lodash/_baseAggregator.js","../node_modules/lodash/_createAggregator.js","../node_modules/lodash/groupBy.js","../node_modules/lodash/_baseHas.js","../node_modules/lodash/has.js","../node_modules/lodash/map.js","../node_modules/lodash/_baseSet.js","../node_modules/lodash/_basePickBy.js","../node_modules/lodash/pickBy.js","../node_modules/lodash/omitBy.js","../node_modules/knex/lib/query/querycompiler.js","../node_modules/knex/lib/schema/builder.js","../node_modules/knex/lib/schema/internal/helpers.js","../node_modules/knex/lib/schema/compiler.js","../node_modules/lodash/assignIn.js","../node_modules/lodash/extend.js","../node_modules/knex/lib/schema/tablebuilder.js","../node_modules/lodash/indexOf.js","../node_modules/knex/lib/schema/tablecompiler.js","../node_modules/knex/lib/schema/columnbuilder.js","../node_modules/lodash/head.js","../node_modules/lodash/first.js","../node_modules/knex/lib/schema/columncompiler.js","../node_modules/knex/lib/ref.js","../node_modules/knex/lib/formatter.js","../node_modules/knex/lib/schema/viewbuilder.js","../node_modules/knex/lib/schema/viewcompiler.js","../node_modules/knex/lib/client.js","../node_modules/pg-connection-string/index.js","../node_modules/knex/lib/knex-builder/internal/parse-connection.js","../node_modules/knex/lib/dialects/sqlite3/execution/sqlite-transaction.js","../node_modules/knex/lib/dialects/sqlite3/query/sqlite-querycompiler.js","../node_modules/lodash/_baseSome.js","../node_modules/lodash/some.js","../node_modules/knex/lib/dialects/sqlite3/schema/sqlite-compiler.js","../node_modules/knex/lib/dialects/sqlite3/schema/sqlite-columncompiler.js","../node_modules/lodash/filter.js","../node_modules/knex/lib/dialects/sqlite3/schema/sqlite-tablecompiler.js","../node_modules/knex/lib/dialects/sqlite3/schema/sqlite-viewcompiler.js","../node_modules/knex/lib/dialects/sqlite3/schema/internal/sqlite-ddl-operations.js","../node_modules/knex/lib/dialects/sqlite3/schema/internal/tokenizer.js","../node_modules/knex/lib/dialects/sqlite3/schema/internal/parser-combinator.js","../node_modules/knex/lib/dialects/sqlite3/schema/internal/parser.js","../node_modules/knex/lib/dialects/sqlite3/schema/internal/compiler.js","../node_modules/knex/lib/dialects/sqlite3/schema/internal/utils.js","../node_modules/knex/lib/dialects/sqlite3/schema/ddl.js","../node_modules/knex/lib/dialects/sqlite3/query/sqlite-querybuilder.js","../node_modules/knex/lib/dialects/sqlite3/index.js","../node_modules/knex/lib/dialects/better-sqlite3/index.js","../node_modules/knex/lib/dialects/postgres/execution/pg-transaction.js","../node_modules/knex/lib/dialects/postgres/query/pg-querycompiler.js","../node_modules/knex/lib/dialects/postgres/query/pg-querybuilder.js","../node_modules/knex/lib/dialects/postgres/schema/pg-columncompiler.js","../node_modules/knex/lib/dialects/postgres/schema/pg-tablecompiler.js","../node_modules/knex/lib/dialects/postgres/schema/pg-viewcompiler.js","../node_modules/knex/lib/dialects/postgres/schema/pg-viewbuilder.js","../node_modules/knex/lib/dialects/postgres/schema/pg-compiler.js","../node_modules/knex/lib/dialects/postgres/index.js","../node_modules/knex/lib/dialects/cockroachdb/crdb-querycompiler.js","../node_modules/knex/lib/dialects/cockroachdb/crdb-columncompiler.js","../node_modules/knex/lib/dialects/cockroachdb/crdb-tablecompiler.js","../node_modules/knex/lib/dialects/cockroachdb/crdb-viewcompiler.js","../node_modules/knex/lib/dialects/cockroachdb/crdb-querybuilder.js","../node_modules/knex/lib/dialects/cockroachdb/index.js","../node_modules/lodash/isNil.js","../node_modules/knex/lib/dialects/mssql/mssql-formatter.js","../node_modules/knex/lib/dialects/mssql/transaction.js","../node_modules/knex/lib/dialects/mssql/query/mssql-querycompiler.js","../node_modules/knex/lib/dialects/mssql/schema/mssql-compiler.js","../node_modules/knex/lib/dialects/mssql/schema/mssql-tablecompiler.js","../node_modules/knex/lib/dialects/mssql/schema/mssql-viewcompiler.js","../node_modules/knex/lib/dialects/mssql/schema/mssql-columncompiler.js","../node_modules/knex/lib/dialects/mssql/index.js","../node_modules/lodash/_baseDelay.js","../node_modules/lodash/defer.js","../node_modules/knex/lib/dialects/mysql/transaction.js","../node_modules/knex/lib/dialects/mysql/query/mysql-querybuilder.js","../node_modules/knex/lib/dialects/mysql/query/mysql-querycompiler.js","../node_modules/knex/lib/dialects/mysql/schema/mysql-compiler.js","../node_modules/knex/lib/dialects/mysql/schema/mysql-tablecompiler.js","../node_modules/knex/lib/dialects/mysql/schema/mysql-columncompiler.js","../node_modules/knex/lib/dialects/mysql/schema/mysql-viewcompiler.js","../node_modules/knex/lib/dialects/mysql/schema/mysql-viewbuilder.js","../node_modules/knex/lib/dialects/mysql/index.js","../node_modules/knex/lib/dialects/mysql2/transaction.js","../node_modules/knex/lib/dialects/mysql2/index.js","../node_modules/knex/lib/dialects/oracle/utils.js","../node_modules/knex/lib/dialects/oracle/schema/internal/trigger.js","../node_modules/knex/lib/dialects/oracle/schema/oracle-compiler.js","../node_modules/knex/lib/dialects/oracle/schema/oracle-columnbuilder.js","../node_modules/lodash/noop.js","../node_modules/lodash/_createSet.js","../node_modules/lodash/_baseUniq.js","../node_modules/lodash/uniq.js","../node_modules/knex/lib/dialects/oracle/schema/internal/incrementUtils.js","../node_modules/knex/lib/dialects/oracle/schema/oracle-columncompiler.js","../node_modules/knex/lib/dialects/oracle/schema/oracle-tablecompiler.js","../node_modules/knex/lib/dialects/oracle/index.js","../node_modules/knex/lib/dialects/oracle/query/oracle-querycompiler.js","../node_modules/knex/lib/dialects/oracledb/utils.js","../node_modules/knex/lib/dialects/oracledb/query/oracledb-querycompiler.js","../node_modules/knex/lib/dialects/oracledb/schema/oracledb-tablecompiler.js","../node_modules/knex/lib/dialects/oracledb/schema/oracledb-columncompiler.js","../node_modules/knex/lib/dialects/oracledb/schema/oracledb-viewcompiler.js","../node_modules/knex/lib/dialects/oracledb/schema/oracledb-viewbuilder.js","../node_modules/knex/lib/dialects/oracledb/transaction.js","../node_modules/knex/lib/dialects/oracledb/index.js","../node_modules/knex/lib/dialects/pgnative/index.js","../node_modules/knex/lib/dialects/redshift/transaction.js","../node_modules/knex/lib/dialects/redshift/query/redshift-querycompiler.js","../node_modules/knex/lib/dialects/redshift/schema/redshift-columnbuilder.js","../node_modules/knex/lib/dialects/redshift/schema/redshift-columncompiler.js","../node_modules/knex/lib/dialects/redshift/schema/redshift-tablecompiler.js","../node_modules/knex/lib/dialects/redshift/schema/redshift-compiler.js","../node_modules/knex/lib/dialects/redshift/schema/redshift-viewcompiler.js","../node_modules/knex/lib/dialects/redshift/index.js","../node_modules/knex/lib/dialects/index.js","../node_modules/knex/lib/knex-builder/internal/config-resolver.js","../node_modules/knex/lib/knex-builder/Knex.js","../node_modules/knex/lib/index.js","../node_modules/knex/knex.js"],"sourcesContent":["\"use strict\";\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nclass TimeoutError extends Error {\r\n}\r\nexports.TimeoutError = TimeoutError;\r\n","\"use strict\";\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nclass PromiseInspection {\r\n constructor(args) {\r\n this._value = args.value;\r\n this._error = args.error;\r\n }\r\n value() {\r\n return this._value;\r\n }\r\n reason() {\r\n return this._error;\r\n }\r\n isRejected() {\r\n return !!this._error;\r\n }\r\n isFulfilled() {\r\n return !!this._value;\r\n }\r\n}\r\nexports.PromiseInspection = PromiseInspection;\r\n","\"use strict\";\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst PromiseInspection_1 = require(\"./PromiseInspection\");\r\nfunction defer() {\r\n let resolve = null;\r\n let reject = null;\r\n const promise = new Promise((resolver, rejecter) => {\r\n resolve = resolver;\r\n reject = rejecter;\r\n });\r\n return {\r\n promise,\r\n resolve,\r\n reject\r\n };\r\n}\r\nexports.defer = defer;\r\nfunction now() {\r\n return Date.now();\r\n}\r\nexports.now = now;\r\nfunction duration(t1, t2) {\r\n return Math.abs(t2 - t1);\r\n}\r\nexports.duration = duration;\r\nfunction checkOptionalTime(time) {\r\n if (typeof time === 'undefined') {\r\n return true;\r\n }\r\n return checkRequiredTime(time);\r\n}\r\nexports.checkOptionalTime = checkOptionalTime;\r\nfunction checkRequiredTime(time) {\r\n return typeof time === 'number' && time === Math.round(time) && time > 0;\r\n}\r\nexports.checkRequiredTime = checkRequiredTime;\r\nfunction delay(millis) {\r\n return new Promise(resolve => setTimeout(resolve, millis));\r\n}\r\nexports.delay = delay;\r\nfunction reflect(promise) {\r\n return promise\r\n .then(value => {\r\n return new PromiseInspection_1.PromiseInspection({ value });\r\n })\r\n .catch(error => {\r\n return new PromiseInspection_1.PromiseInspection({ error });\r\n });\r\n}\r\nexports.reflect = reflect;\r\nfunction tryPromise(cb) {\r\n try {\r\n const result = cb();\r\n return Promise.resolve(result);\r\n }\r\n catch (err) {\r\n return Promise.reject(err);\r\n }\r\n}\r\nexports.tryPromise = tryPromise;\r\n","\"use strict\";\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst TimeoutError_1 = require(\"./TimeoutError\");\r\nconst utils_1 = require(\"./utils\");\r\nclass PendingOperation {\r\n constructor(timeoutMillis) {\r\n this.timeoutMillis = timeoutMillis;\r\n this.deferred = utils_1.defer();\r\n this.possibleTimeoutCause = null;\r\n this.isRejected = false;\r\n this.promise = timeout(this.deferred.promise, timeoutMillis).catch(err => {\r\n if (err instanceof TimeoutError_1.TimeoutError) {\r\n if (this.possibleTimeoutCause) {\r\n err = new TimeoutError_1.TimeoutError(this.possibleTimeoutCause.message);\r\n }\r\n else {\r\n err = new TimeoutError_1.TimeoutError('operation timed out for an unknown reason');\r\n }\r\n }\r\n this.isRejected = true;\r\n return Promise.reject(err);\r\n });\r\n }\r\n abort() {\r\n this.reject(new Error('aborted'));\r\n }\r\n reject(err) {\r\n this.deferred.reject(err);\r\n }\r\n resolve(value) {\r\n this.deferred.resolve(value);\r\n }\r\n}\r\nexports.PendingOperation = PendingOperation;\r\nfunction timeout(promise, time) {\r\n return new Promise((resolve, reject) => {\r\n const timeoutHandle = setTimeout(() => reject(new TimeoutError_1.TimeoutError()), time);\r\n promise\r\n .then(result => {\r\n clearTimeout(timeoutHandle);\r\n resolve(result);\r\n })\r\n .catch(err => {\r\n clearTimeout(timeoutHandle);\r\n reject(err);\r\n });\r\n });\r\n}\r\n","\"use strict\";\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst utils_1 = require(\"./utils\");\r\nclass Resource {\r\n constructor(resource) {\r\n this.resource = resource;\r\n this.resource = resource;\r\n this.timestamp = utils_1.now();\r\n this.deferred = utils_1.defer();\r\n }\r\n get promise() {\r\n return this.deferred.promise;\r\n }\r\n resolve() {\r\n this.deferred.resolve(undefined);\r\n return new Resource(this.resource);\r\n }\r\n}\r\nexports.Resource = Resource;\r\n","\"use strict\";\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst PendingOperation_1 = require(\"./PendingOperation\");\r\nconst Resource_1 = require(\"./Resource\");\r\nconst utils_1 = require(\"./utils\");\r\nconst events_1 = require(\"events\");\r\nconst timers_1 = require(\"timers\");\r\nclass Pool {\r\n constructor(opt) {\r\n this.destroyed = false;\r\n this.emitter = new events_1.EventEmitter();\r\n opt = opt || {};\r\n if (!opt.create) {\r\n throw new Error('Tarn: opt.create function most be provided');\r\n }\r\n if (!opt.destroy) {\r\n throw new Error('Tarn: opt.destroy function most be provided');\r\n }\r\n if (typeof opt.min !== 'number' || opt.min < 0 || opt.min !== Math.round(opt.min)) {\r\n throw new Error('Tarn: opt.min must be an integer >= 0');\r\n }\r\n if (typeof opt.max !== 'number' || opt.max <= 0 || opt.max !== Math.round(opt.max)) {\r\n throw new Error('Tarn: opt.max must be an integer > 0');\r\n }\r\n if (opt.min > opt.max) {\r\n throw new Error('Tarn: opt.max is smaller than opt.min');\r\n }\r\n if (!utils_1.checkOptionalTime(opt.acquireTimeoutMillis)) {\r\n throw new Error('Tarn: invalid opt.acquireTimeoutMillis ' + JSON.stringify(opt.acquireTimeoutMillis));\r\n }\r\n if (!utils_1.checkOptionalTime(opt.createTimeoutMillis)) {\r\n throw new Error('Tarn: invalid opt.createTimeoutMillis ' + JSON.stringify(opt.createTimeoutMillis));\r\n }\r\n if (!utils_1.checkOptionalTime(opt.destroyTimeoutMillis)) {\r\n throw new Error('Tarn: invalid opt.destroyTimeoutMillis ' + JSON.stringify(opt.destroyTimeoutMillis));\r\n }\r\n if (!utils_1.checkOptionalTime(opt.idleTimeoutMillis)) {\r\n throw new Error('Tarn: invalid opt.idleTimeoutMillis ' + JSON.stringify(opt.idleTimeoutMillis));\r\n }\r\n if (!utils_1.checkOptionalTime(opt.reapIntervalMillis)) {\r\n throw new Error('Tarn: invalid opt.reapIntervalMillis ' + JSON.stringify(opt.reapIntervalMillis));\r\n }\r\n if (!utils_1.checkOptionalTime(opt.createRetryIntervalMillis)) {\r\n throw new Error('Tarn: invalid opt.createRetryIntervalMillis ' +\r\n JSON.stringify(opt.createRetryIntervalMillis));\r\n }\r\n const allowedKeys = {\r\n create: true,\r\n validate: true,\r\n destroy: true,\r\n log: true,\r\n min: true,\r\n max: true,\r\n acquireTimeoutMillis: true,\r\n createTimeoutMillis: true,\r\n destroyTimeoutMillis: true,\r\n idleTimeoutMillis: true,\r\n reapIntervalMillis: true,\r\n createRetryIntervalMillis: true,\r\n propagateCreateError: true\r\n };\r\n for (const key of Object.keys(opt)) {\r\n if (!allowedKeys[key]) {\r\n throw new Error(`Tarn: unsupported option opt.${key}`);\r\n }\r\n }\r\n this.creator = opt.create;\r\n this.destroyer = opt.destroy;\r\n this.validate = typeof opt.validate === 'function' ? opt.validate : () => true;\r\n this.log = opt.log || (() => { });\r\n this.acquireTimeoutMillis = opt.acquireTimeoutMillis || 30000;\r\n this.createTimeoutMillis = opt.createTimeoutMillis || 30000;\r\n this.destroyTimeoutMillis = opt.destroyTimeoutMillis || 5000;\r\n this.idleTimeoutMillis = opt.idleTimeoutMillis || 30000;\r\n this.reapIntervalMillis = opt.reapIntervalMillis || 1000;\r\n this.createRetryIntervalMillis = opt.createRetryIntervalMillis || 200;\r\n this.propagateCreateError = !!opt.propagateCreateError;\r\n this.min = opt.min;\r\n this.max = opt.max;\r\n // All the resources, which are either already acquired or which are\r\n // considered for being passed to acquire in async validation phase.\r\n this.used = [];\r\n // All the resources, which are either just created and free or returned\r\n // back to pool after using.\r\n this.free = [];\r\n this.pendingCreates = [];\r\n this.pendingAcquires = [];\r\n this.pendingDestroys = [];\r\n // When acquire is pending, but also still in validation phase\r\n this.pendingValidations = [];\r\n this.destroyed = false;\r\n this.interval = null;\r\n this.eventId = 1;\r\n }\r\n numUsed() {\r\n return this.used.length;\r\n }\r\n numFree() {\r\n return this.free.length;\r\n }\r\n numPendingAcquires() {\r\n return this.pendingAcquires.length;\r\n }\r\n numPendingValidations() {\r\n return this.pendingValidations.length;\r\n }\r\n numPendingCreates() {\r\n return this.pendingCreates.length;\r\n }\r\n acquire() {\r\n const eventId = this.eventId++;\r\n this._executeEventHandlers('acquireRequest', eventId);\r\n const pendingAcquire = new PendingOperation_1.PendingOperation(this.acquireTimeoutMillis);\r\n this.pendingAcquires.push(pendingAcquire);\r\n // If the acquire fails for whatever reason\r\n // remove it from the pending queue.\r\n pendingAcquire.promise = pendingAcquire.promise\r\n .then(resource => {\r\n this._executeEventHandlers('acquireSuccess', eventId, resource);\r\n return resource;\r\n })\r\n .catch(err => {\r\n this._executeEventHandlers('acquireFail', eventId, err);\r\n remove(this.pendingAcquires, pendingAcquire);\r\n return Promise.reject(err);\r\n });\r\n this._tryAcquireOrCreate();\r\n return pendingAcquire;\r\n }\r\n release(resource) {\r\n this._executeEventHandlers('release', resource);\r\n for (let i = 0, l = this.used.length; i < l; ++i) {\r\n const used = this.used[i];\r\n if (used.resource === resource) {\r\n this.used.splice(i, 1);\r\n this.free.push(used.resolve());\r\n this._tryAcquireOrCreate();\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n isEmpty() {\r\n return ([\r\n this.numFree(),\r\n this.numUsed(),\r\n this.numPendingAcquires(),\r\n this.numPendingValidations(),\r\n this.numPendingCreates()\r\n ].reduce((total, value) => total + value) === 0);\r\n }\r\n /**\r\n * Reaping cycle.\r\n */\r\n check() {\r\n const timestamp = utils_1.now();\r\n const newFree = [];\r\n const minKeep = this.min - this.used.length;\r\n const maxDestroy = this.free.length - minKeep;\r\n let numDestroyed = 0;\r\n this.free.forEach(free => {\r\n if (utils_1.duration(timestamp, free.timestamp) >= this.idleTimeoutMillis &&\r\n numDestroyed < maxDestroy) {\r\n numDestroyed++;\r\n this._destroy(free.resource);\r\n }\r\n else {\r\n newFree.push(free);\r\n }\r\n });\r\n this.free = newFree;\r\n // Pool is completely empty, stop reaping.\r\n // Next .acquire will start reaping interval again.\r\n if (this.isEmpty()) {\r\n this._stopReaping();\r\n }\r\n }\r\n destroy() {\r\n const eventId = this.eventId++;\r\n this._executeEventHandlers('poolDestroyRequest', eventId);\r\n this._stopReaping();\r\n this.destroyed = true;\r\n // First wait for all the pending creates get ready.\r\n return utils_1.reflect(Promise.all(this.pendingCreates.map(create => utils_1.reflect(create.promise)))\r\n .then(() => {\r\n // eslint-disable-next-line\r\n return new Promise((resolve, reject) => {\r\n // poll every 100ms and wait that all validations are ready\r\n if (this.numPendingValidations() === 0) {\r\n resolve();\r\n return;\r\n }\r\n const interval = setInterval(() => {\r\n if (this.numPendingValidations() === 0) {\r\n timers_1.clearInterval(interval);\r\n resolve();\r\n }\r\n }, 100);\r\n });\r\n })\r\n .then(() => {\r\n // Wait for all the used resources to be freed.\r\n return Promise.all(this.used.map(used => utils_1.reflect(used.promise)));\r\n })\r\n .then(() => {\r\n // Abort all pending acquires.\r\n return Promise.all(this.pendingAcquires.map(acquire => {\r\n acquire.abort();\r\n return utils_1.reflect(acquire.promise);\r\n }));\r\n })\r\n .then(() => {\r\n // Now we can destroy all the freed resources.\r\n return Promise.all(this.free.map(free => utils_1.reflect(this._destroy(free.resource))));\r\n })\r\n .then(() => {\r\n // Also wait rest of the pending destroys to finish\r\n return Promise.all(this.pendingDestroys.map(pd => pd.promise));\r\n })\r\n .then(() => {\r\n this.free = [];\r\n this.pendingAcquires = [];\r\n })).then(res => {\r\n this._executeEventHandlers('poolDestroySuccess', eventId);\r\n this.emitter.removeAllListeners();\r\n return res;\r\n });\r\n }\r\n on(event, listener) {\r\n this.emitter.on(event, listener);\r\n }\r\n removeListener(event, listener) {\r\n this.emitter.removeListener(event, listener);\r\n }\r\n removeAllListeners(event) {\r\n this.emitter.removeAllListeners(event);\r\n }\r\n /**\r\n * The most important method that is called always when resources\r\n * are created / destroyed / acquired / released. In other words\r\n * every time when resources are moved from used to free or vice\r\n * versa.\r\n *\r\n * Either assigns free resources to pendingAcquires or creates new\r\n * resources if there is room for it in the pool.\r\n */\r\n _tryAcquireOrCreate() {\r\n if (this.destroyed) {\r\n return;\r\n }\r\n if (this._hasFreeResources()) {\r\n this._doAcquire();\r\n }\r\n else if (this._shouldCreateMoreResources()) {\r\n this._doCreate();\r\n }\r\n }\r\n _hasFreeResources() {\r\n return this.free.length > 0;\r\n }\r\n _doAcquire() {\r\n // Acquire as many pending acquires as possible concurrently\r\n while (this._canAcquire()) {\r\n // To allow async validation, we actually need to move free resource\r\n // and pending acquire temporary from their respective arrays and depending\r\n // on validation result to either leave the free resource to used resources array\r\n // or destroy the free resource if validation did fail.\r\n const pendingAcquire = this.pendingAcquires.shift();\r\n const free = this.free.pop();\r\n if (free === undefined || pendingAcquire === undefined) {\r\n const errMessage = 'this.free was empty while trying to acquire resource';\r\n this.log(`Tarn: ${errMessage}`, 'warn');\r\n throw new Error(`Internal error, should never happen. ${errMessage}`);\r\n }\r\n // Make sure that pendingAcquire that is being validated is not lost and\r\n // can be freed when pool is destroyed.\r\n this.pendingValidations.push(pendingAcquire);\r\n // Must be added here pre-emptively to prevent logic that decides\r\n // if new resources are created will keep on working correctly.\r\n this.used.push(free);\r\n // if acquire fails also pending validation, must be aborted so that pre reserved\r\n // resource will be returned to free resources immediately\r\n const abortAbleValidation = new PendingOperation_1.PendingOperation(this.acquireTimeoutMillis);\r\n // eslint-disable-next-line\r\n pendingAcquire.promise.catch(err => {\r\n abortAbleValidation.abort();\r\n });\r\n abortAbleValidation.promise\r\n .catch(err => {\r\n // There's nothing we can do here but log the error. This would otherwise\r\n // leak out as an unhandled exception.\r\n this.log('Tarn: resource validator threw an exception ' + err.stack, 'warn');\r\n return false;\r\n })\r\n .then(validationSuccess => {\r\n try {\r\n if (validationSuccess && !pendingAcquire.isRejected) {\r\n // At least one active resource exist, start reaping.\r\n this._startReaping();\r\n pendingAcquire.resolve(free.resource);\r\n }\r\n else {\r\n remove(this.used, free);\r\n // Only destroy the resource if the validation has failed\r\n if (!validationSuccess) {\r\n this._destroy(free.resource);\r\n // Since we destroyed an invalid resource and were not able to fulfill\r\n // all the pending acquires, we may need to create new ones or at\r\n // least run this acquire loop again to verify it. But not immediately\r\n // to prevent starving event loop.\r\n setTimeout(() => {\r\n this._tryAcquireOrCreate();\r\n }, 0);\r\n }\r\n else {\r\n this.free.push(free);\r\n }\r\n // is acquire was canceled, failed or timed out already\r\n // no need to return it to pending queries\r\n if (!pendingAcquire.isRejected) {\r\n this.pendingAcquires.unshift(pendingAcquire);\r\n }\r\n }\r\n }\r\n finally {\r\n remove(this.pendingValidations, pendingAcquire);\r\n }\r\n });\r\n // try to validate\r\n this._validateResource(free.resource)\r\n .then(validationSuccess => {\r\n abortAbleValidation.resolve(validationSuccess);\r\n })\r\n .catch(err => {\r\n abortAbleValidation.reject(err);\r\n });\r\n }\r\n }\r\n _canAcquire() {\r\n return this.free.length > 0 && this.pendingAcquires.length > 0;\r\n }\r\n _validateResource(resource) {\r\n try {\r\n return Promise.resolve(this.validate(resource));\r\n }\r\n catch (err) {\r\n // prevent leaking of sync exception\r\n return Promise.reject(err);\r\n }\r\n }\r\n _shouldCreateMoreResources() {\r\n return (this.used.length + this.pendingCreates.length < this.max &&\r\n this.pendingCreates.length < this.pendingAcquires.length);\r\n }\r\n _doCreate() {\r\n const pendingAcquiresBeforeCreate = this.pendingAcquires.slice();\r\n const pendingCreate = this._create();\r\n pendingCreate.promise\r\n .then(() => {\r\n // Not returned on purpose.\r\n this._tryAcquireOrCreate();\r\n return null;\r\n })\r\n .catch(err => {\r\n if (this.propagateCreateError && this.pendingAcquires.length !== 0) {\r\n // If propagateCreateError is true, we don't retry the create\r\n // but reject the first pending acquire immediately. Intentionally\r\n // use `this.pendingAcquires` instead of `pendingAcquiresBeforeCreate`\r\n // in case some acquires in pendingAcquiresBeforeCreate have already\r\n // been resolved.\r\n this.pendingAcquires[0].reject(err);\r\n }\r\n // Save the create error to all pending acquires so that we can use it\r\n // as the error to reject the acquire if it times out.\r\n pendingAcquiresBeforeCreate.forEach(pendingAcquire => {\r\n pendingAcquire.possibleTimeoutCause = err;\r\n });\r\n // Not returned on purpose.\r\n utils_1.delay(this.createRetryIntervalMillis).then(() => this._tryAcquireOrCreate());\r\n });\r\n }\r\n _create() {\r\n const eventId = this.eventId++;\r\n this._executeEventHandlers('createRequest', eventId);\r\n const pendingCreate = new PendingOperation_1.PendingOperation(this.createTimeoutMillis);\r\n // If an error occurs (likely a create timeout) remove this creation from\r\n // the list of pending creations so we try to create a new one.\r\n pendingCreate.promise = pendingCreate.promise.catch(err => {\r\n if (remove(this.pendingCreates, pendingCreate)) {\r\n // TODO: figure out more consistent way for different error handlers in next rewrite\r\n this._executeEventHandlers('createFail', eventId, err);\r\n }\r\n throw err;\r\n });\r\n this.pendingCreates.push(pendingCreate);\r\n callbackOrPromise(this.creator)\r\n .then(resource => {\r\n if (pendingCreate.isRejected) {\r\n this.destroyer(resource);\r\n return null;\r\n }\r\n remove(this.pendingCreates, pendingCreate);\r\n this.free.push(new Resource_1.Resource(resource));\r\n // Not returned on purpose.\r\n pendingCreate.resolve(resource);\r\n this._executeEventHandlers('createSuccess', eventId, resource);\r\n return null;\r\n })\r\n .catch(err => {\r\n if (pendingCreate.isRejected) {\r\n return null;\r\n }\r\n if (remove(this.pendingCreates, pendingCreate)) {\r\n this._executeEventHandlers('createFail', eventId, err);\r\n }\r\n // Not returned on purpose.\r\n pendingCreate.reject(err);\r\n return null;\r\n });\r\n return pendingCreate;\r\n }\r\n _destroy(resource) {\r\n const eventId = this.eventId++;\r\n this._executeEventHandlers('destroyRequest', eventId, resource);\r\n // this.destroyer can be both synchronous and asynchronous.\r\n // so we wrap it to promise to get all exceptions through same pipeline\r\n const pendingDestroy = new PendingOperation_1.PendingOperation(this.destroyTimeoutMillis);\r\n const retVal = Promise.resolve().then(() => this.destroyer(resource));\r\n retVal\r\n .then(() => {\r\n pendingDestroy.resolve(resource);\r\n })\r\n .catch((err) => {\r\n pendingDestroy.reject(err);\r\n });\r\n this.pendingDestroys.push(pendingDestroy);\r\n // In case of an error there's nothing we can do here but log it.\r\n return pendingDestroy.promise\r\n .then(res => {\r\n this._executeEventHandlers('destroySuccess', eventId, resource);\r\n return res;\r\n })\r\n .catch(err => this._logDestroyerError(eventId, resource, err))\r\n .then(res => {\r\n const index = this.pendingDestroys.findIndex(pd => pd === pendingDestroy);\r\n this.pendingDestroys.splice(index, 1);\r\n return res;\r\n });\r\n }\r\n _logDestroyerError(eventId, resource, err) {\r\n this._executeEventHandlers('destroyFail', eventId, resource, err);\r\n this.log('Tarn: resource destroyer threw an exception ' + err.stack, 'warn');\r\n }\r\n _startReaping() {\r\n if (!this.interval) {\r\n this._executeEventHandlers('startReaping');\r\n this.interval = setInterval(() => this.check(), this.reapIntervalMillis);\r\n }\r\n }\r\n _stopReaping() {\r\n if (this.interval !== null) {\r\n this._executeEventHandlers('stopReaping');\r\n timers_1.clearInterval(this.interval);\r\n }\r\n this.interval = null;\r\n }\r\n _executeEventHandlers(eventName, ...args) {\r\n const listeners = this.emitter.listeners(eventName);\r\n // just calling .emit() would stop running rest of the listeners if one them fails\r\n listeners.forEach(listener => {\r\n try {\r\n listener(...args);\r\n }\r\n catch (err) {\r\n // There's nothing we can do here but log the error. This would otherwise\r\n // leak out as an unhandled exception.\r\n this.log(`Tarn: event handler \"${eventName}\" threw an exception ${err.stack}`, 'warn');\r\n }\r\n });\r\n }\r\n}\r\nexports.Pool = Pool;\r\nfunction remove(arr, item) {\r\n const idx = arr.indexOf(item);\r\n if (idx === -1) {\r\n return false;\r\n }\r\n else {\r\n arr.splice(idx, 1);\r\n return true;\r\n }\r\n}\r\nfunction callbackOrPromise(func) {\r\n return new Promise((resolve, reject) => {\r\n const callback = (err, resource) => {\r\n if (err) {\r\n reject(err);\r\n }\r\n else {\r\n resolve(resource);\r\n }\r\n };\r\n utils_1.tryPromise(() => func(callback))\r\n .then(res => {\r\n // If the result is falsy, we assume that the callback will\r\n // be called instead of interpreting the falsy value as a\r\n // result value.\r\n if (res) {\r\n resolve(res);\r\n }\r\n })\r\n .catch(err => {\r\n reject(err);\r\n });\r\n });\r\n}\r\n","\"use strict\";\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst Pool_1 = require(\"./Pool\");\r\nexports.Pool = Pool_1.Pool;\r\nconst TimeoutError_1 = require(\"./TimeoutError\");\r\nexports.TimeoutError = TimeoutError_1.TimeoutError;\r\nmodule.exports = {\r\n Pool: Pool_1.Pool,\r\n TimeoutError: TimeoutError_1.TimeoutError\r\n};\r\n","/*eslint max-len: 0, no-var:0 */\n\nconst charsRegex = /[\\0\\b\\t\\n\\r\\x1a\"'\\\\]/g; // eslint-disable-line no-control-regex\nconst charsMap = {\n '\\0': '\\\\0',\n '\\b': '\\\\b',\n '\\t': '\\\\t',\n '\\n': '\\\\n',\n '\\r': '\\\\r',\n '\\x1a': '\\\\Z',\n '\"': '\\\\\"',\n \"'\": \"\\\\'\",\n '\\\\': '\\\\\\\\',\n};\n\nfunction wrapEscape(escapeFn) {\n return function finalEscape(val, ctx = {}) {\n return escapeFn(val, finalEscape, ctx);\n };\n}\n\nfunction makeEscape(config = {}) {\n const finalEscapeDate = config.escapeDate || dateToString;\n const finalEscapeArray = config.escapeArray || arrayToList;\n const finalEscapeBuffer = config.escapeBuffer || bufferToString;\n const finalEscapeString = config.escapeString || escapeString;\n const finalEscapeObject = config.escapeObject || escapeObject;\n const finalWrap = config.wrap || wrapEscape;\n\n function escapeFn(val, finalEscape, ctx) {\n if (val === undefined || val === null) {\n return 'NULL';\n }\n switch (typeof val) {\n case 'boolean':\n return val ? 'true' : 'false';\n case 'number':\n return val + '';\n case 'object':\n if (val instanceof Date) {\n val = finalEscapeDate(val, finalEscape, ctx);\n } else if (Array.isArray(val)) {\n return finalEscapeArray(val, finalEscape, ctx);\n } else if (Buffer.isBuffer(val)) {\n return finalEscapeBuffer(val, finalEscape, ctx);\n } else {\n return finalEscapeObject(val, finalEscape, ctx);\n }\n }\n return finalEscapeString(val, finalEscape, ctx);\n }\n\n return finalWrap ? finalWrap(escapeFn) : escapeFn;\n}\n\nfunction escapeObject(val, finalEscape, ctx) {\n if (val && typeof val.toSQL === 'function') {\n return val.toSQL(ctx);\n } else {\n return JSON.stringify(val);\n }\n}\n\nfunction arrayToList(array, finalEscape, ctx) {\n let sql = '';\n for (let i = 0; i < array.length; i++) {\n const val = array[i];\n if (Array.isArray(val)) {\n sql +=\n (i === 0 ? '' : ', ') + '(' + arrayToList(val, finalEscape, ctx) + ')';\n } else {\n sql += (i === 0 ? '' : ', ') + finalEscape(val, ctx);\n }\n }\n return sql;\n}\n\nfunction bufferToString(buffer) {\n return 'X' + escapeString(buffer.toString('hex'));\n}\n\nfunction escapeString(val, finalEscape, ctx) {\n let chunkIndex = (charsRegex.lastIndex = 0);\n let escapedVal = '';\n let match;\n\n while ((match = charsRegex.exec(val