@milaboratories/pl-client 2.11.7 → 2.11.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/auth.cjs +24 -0
- package/dist/core/auth.cjs.map +1 -0
- package/dist/core/auth.d.ts +0 -1
- package/dist/core/auth.js +21 -0
- package/dist/core/auth.js.map +1 -0
- package/dist/core/cache.d.ts +0 -1
- package/dist/core/client.cjs +288 -0
- package/dist/core/client.cjs.map +1 -0
- package/dist/core/client.d.ts +0 -1
- package/dist/core/client.js +267 -0
- package/dist/core/client.js.map +1 -0
- package/dist/core/config.cjs +111 -0
- package/dist/core/config.cjs.map +1 -0
- package/dist/core/config.d.ts +2 -1
- package/dist/core/config.js +95 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/default_client.cjs +143 -0
- package/dist/core/default_client.cjs.map +1 -0
- package/dist/core/default_client.d.ts +0 -1
- package/dist/core/default_client.js +120 -0
- package/dist/core/default_client.js.map +1 -0
- package/dist/core/driver.cjs +14 -0
- package/dist/core/driver.cjs.map +1 -0
- package/dist/core/driver.d.ts +0 -1
- package/dist/core/driver.js +12 -0
- package/dist/core/driver.js.map +1 -0
- package/dist/core/error_resource.cjs +9 -0
- package/dist/core/error_resource.cjs.map +1 -0
- package/dist/core/error_resource.d.ts +0 -1
- package/dist/core/error_resource.js +7 -0
- package/dist/core/error_resource.js.map +1 -0
- package/dist/core/errors.cjs +106 -0
- package/dist/core/errors.cjs.map +1 -0
- package/dist/core/errors.d.ts +0 -1
- package/dist/core/errors.js +93 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/final.cjs +98 -0
- package/dist/core/final.cjs.map +1 -0
- package/dist/core/final.d.ts +0 -1
- package/dist/core/final.js +96 -0
- package/dist/core/final.js.map +1 -0
- package/dist/core/grpc.d.ts +0 -1
- package/dist/core/http.d.ts +1 -1
- package/dist/core/ll_client.cjs +266 -0
- package/dist/core/ll_client.cjs.map +1 -0
- package/dist/core/ll_client.d.ts +0 -1
- package/dist/core/ll_client.js +264 -0
- package/dist/core/ll_client.js.map +1 -0
- package/dist/core/ll_transaction.cjs +236 -0
- package/dist/core/ll_transaction.cjs.map +1 -0
- package/dist/core/ll_transaction.d.ts +0 -1
- package/dist/core/ll_transaction.js +233 -0
- package/dist/core/ll_transaction.js.map +1 -0
- package/dist/core/stat.cjs +74 -0
- package/dist/core/stat.cjs.map +1 -0
- package/dist/core/stat.d.ts +0 -1
- package/dist/core/stat.js +70 -0
- package/dist/core/stat.js.map +1 -0
- package/dist/core/transaction.cjs +626 -0
- package/dist/core/transaction.cjs.map +1 -0
- package/dist/core/transaction.d.ts +0 -1
- package/dist/core/transaction.js +613 -0
- package/dist/core/transaction.js.map +1 -0
- package/dist/core/type_conversion.cjs +106 -0
- package/dist/core/type_conversion.cjs.map +1 -0
- package/dist/core/type_conversion.d.ts +0 -1
- package/dist/core/type_conversion.js +102 -0
- package/dist/core/type_conversion.js.map +1 -0
- package/dist/core/types.cjs +159 -0
- package/dist/core/types.cjs.map +1 -0
- package/dist/core/types.d.ts +0 -1
- package/dist/core/types.js +134 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/unauth_client.cjs +43 -0
- package/dist/core/unauth_client.cjs.map +1 -0
- package/dist/core/unauth_client.d.ts +0 -1
- package/dist/core/unauth_client.js +41 -0
- package/dist/core/unauth_client.js.map +1 -0
- package/dist/helpers/pl.cjs +124 -0
- package/dist/helpers/pl.cjs.map +1 -0
- package/dist/helpers/pl.d.ts +0 -1
- package/dist/helpers/pl.js +94 -0
- package/dist/helpers/pl.js.map +1 -0
- package/dist/helpers/poll.cjs +148 -0
- package/dist/helpers/poll.cjs.map +1 -0
- package/dist/helpers/poll.d.ts +0 -1
- package/dist/helpers/poll.js +123 -0
- package/dist/helpers/poll.js.map +1 -0
- package/dist/helpers/rich_resource_types.d.ts +1 -1
- package/dist/helpers/smart_accessors.d.ts +1 -1
- package/dist/helpers/state_helpers.d.ts +0 -1
- package/dist/helpers/tx_helpers.cjs +25 -0
- package/dist/helpers/tx_helpers.cjs.map +1 -0
- package/dist/helpers/tx_helpers.d.ts +0 -1
- package/dist/helpers/tx_helpers.js +23 -0
- package/dist/helpers/tx_helpers.js.map +1 -0
- package/dist/index.cjs +99 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.cjs +71 -0
- package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.cjs.map +1 -0
- package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.d.ts +0 -1
- package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.js +69 -0
- package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.js.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts +3 -5
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts +3 -5
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts +3 -5
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts +3 -5
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.cjs +12238 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.cjs.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs +223 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.cjs.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts +3 -5
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.js +221 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.js.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.js +12086 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.js.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs +1127 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.cjs.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.js +1113 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.js.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs +152 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.cjs.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.js +149 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.js.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs +500 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.cjs.map +1 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js +496 -0
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.js.map +1 -0
- package/dist/proto/google/api/http.d.ts +0 -1
- package/dist/proto/google/protobuf/any.cjs +151 -0
- package/dist/proto/google/protobuf/any.cjs.map +1 -0
- package/dist/proto/google/protobuf/any.d.ts +0 -1
- package/dist/proto/google/protobuf/any.js +149 -0
- package/dist/proto/google/protobuf/any.js.map +1 -0
- package/dist/proto/google/protobuf/descriptor.d.ts +0 -1
- package/dist/proto/google/protobuf/duration.cjs +105 -0
- package/dist/proto/google/protobuf/duration.cjs.map +1 -0
- package/dist/proto/google/protobuf/duration.d.ts +0 -1
- package/dist/proto/google/protobuf/duration.js +103 -0
- package/dist/proto/google/protobuf/duration.js.map +1 -0
- package/dist/proto/google/protobuf/empty.d.ts +0 -1
- package/dist/proto/google/protobuf/struct.d.ts +0 -1
- package/dist/proto/google/protobuf/timestamp.cjs +133 -0
- package/dist/proto/google/protobuf/timestamp.cjs.map +1 -0
- package/dist/proto/google/protobuf/timestamp.d.ts +0 -1
- package/dist/proto/google/protobuf/timestamp.js +131 -0
- package/dist/proto/google/protobuf/timestamp.js.map +1 -0
- package/dist/proto/google/protobuf/wrappers.d.ts +0 -1
- package/dist/test/test_config.cjs +149 -0
- package/dist/test/test_config.cjs.map +1 -0
- package/dist/test/test_config.d.ts +0 -1
- package/dist/test/test_config.js +123 -0
- package/dist/test/test_config.js.map +1 -0
- package/dist/util/branding.d.ts +0 -1
- package/dist/util/pl.cjs +8 -0
- package/dist/util/pl.cjs.map +1 -0
- package/dist/util/pl.d.ts +0 -1
- package/dist/util/pl.js +6 -0
- package/dist/util/pl.js.map +1 -0
- package/dist/util/util.cjs +17 -0
- package/dist/util/util.cjs.map +1 -0
- package/dist/util/util.d.ts +0 -1
- package/dist/util/util.js +15 -0
- package/dist/util/util.js.map +1 -0
- package/package.json +14 -11
- package/src/core/client.test.ts +1 -0
- package/src/core/config.test.ts +1 -0
- package/src/core/config.ts +10 -0
- package/src/core/error.test.ts +1 -0
- package/src/core/ll_client.test.ts +1 -0
- package/src/core/ll_transaction.test.ts +1 -0
- package/src/core/transaction.test.ts +1 -0
- package/src/core/types.test.ts +1 -0
- package/src/core/unauth_client.test.ts +1 -0
- package/src/helpers/rich_resource_types.test.ts +2 -0
- package/src/test/test_config.test.ts +1 -0
- package/src/util/util.test.ts +1 -0
- package/dist/core/auth.d.ts.map +0 -1
- package/dist/core/cache.d.ts.map +0 -1
- package/dist/core/client.d.ts.map +0 -1
- package/dist/core/config.d.ts.map +0 -1
- package/dist/core/default_client.d.ts.map +0 -1
- package/dist/core/driver.d.ts.map +0 -1
- package/dist/core/error_resource.d.ts.map +0 -1
- package/dist/core/errors.d.ts.map +0 -1
- package/dist/core/final.d.ts.map +0 -1
- package/dist/core/grpc.d.ts.map +0 -1
- package/dist/core/http.d.ts.map +0 -1
- package/dist/core/ll_client.d.ts.map +0 -1
- package/dist/core/ll_transaction.d.ts.map +0 -1
- package/dist/core/stat.d.ts.map +0 -1
- package/dist/core/transaction.d.ts.map +0 -1
- package/dist/core/type_conversion.d.ts.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/unauth_client.d.ts.map +0 -1
- package/dist/helpers/pl.d.ts.map +0 -1
- package/dist/helpers/poll.d.ts.map +0 -1
- package/dist/helpers/rich_resource_types.d.ts.map +0 -1
- package/dist/helpers/smart_accessors.d.ts.map +0 -1
- package/dist/helpers/state_helpers.d.ts.map +0 -1
- package/dist/helpers/tx_helpers.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.mjs +0 -14530
- package/dist/index.mjs.map +0 -1
- package/dist/proto/github.com/googleapis/googleapis/google/rpc/status.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.client.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/api_types.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/base_types.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/import.d.ts.map +0 -1
- package/dist/proto/github.com/milaboratory/pl/plapi/plapiproto/resource_types.d.ts.map +0 -1
- package/dist/proto/google/api/http.d.ts.map +0 -1
- package/dist/proto/google/protobuf/any.d.ts.map +0 -1
- package/dist/proto/google/protobuf/descriptor.d.ts.map +0 -1
- package/dist/proto/google/protobuf/duration.d.ts.map +0 -1
- package/dist/proto/google/protobuf/empty.d.ts.map +0 -1
- package/dist/proto/google/protobuf/struct.d.ts.map +0 -1
- package/dist/proto/google/protobuf/timestamp.d.ts.map +0 -1
- package/dist/proto/google/protobuf/wrappers.d.ts.map +0 -1
- package/dist/test/test_config.d.ts.map +0 -1
- package/dist/util/branding.d.ts.map +0 -1
- package/dist/util/pl.d.ts.map +0 -1
- package/dist/util/util.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timestamp.js","sources":["../../../../src/proto/google/protobuf/timestamp.ts"],"sourcesContent":["// @generated by protobuf-ts 2.11.0 with parameter client_generic,optimize_speed,generate_dependencies,force_server_none\n// @generated from protobuf file \"google/protobuf/timestamp.proto\" (package \"google.protobuf\", syntax proto3)\n// tslint:disable\n//\n// Protocol Buffers - Google's data interchange format\n// Copyright 2008 Google Inc. All rights reserved.\n// https://developers.google.com/protocol-buffers/\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n// * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n// * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n// * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n//\nimport type { BinaryWriteOptions } from \"@protobuf-ts/runtime\";\nimport type { IBinaryWriter } from \"@protobuf-ts/runtime\";\nimport { WireType } from \"@protobuf-ts/runtime\";\nimport type { BinaryReadOptions } from \"@protobuf-ts/runtime\";\nimport type { IBinaryReader } from \"@protobuf-ts/runtime\";\nimport { UnknownFieldHandler } from \"@protobuf-ts/runtime\";\nimport type { PartialMessage } from \"@protobuf-ts/runtime\";\nimport { reflectionMergePartial } from \"@protobuf-ts/runtime\";\nimport { typeofJsonValue } from \"@protobuf-ts/runtime\";\nimport type { JsonValue } from \"@protobuf-ts/runtime\";\nimport type { JsonReadOptions } from \"@protobuf-ts/runtime\";\nimport type { JsonWriteOptions } from \"@protobuf-ts/runtime\";\nimport { PbLong } from \"@protobuf-ts/runtime\";\nimport { MessageType } from \"@protobuf-ts/runtime\";\n/**\n * A Timestamp represents a point in time independent of any time zone or local\n * calendar, encoded as a count of seconds and fractions of seconds at\n * nanosecond resolution. The count is relative to an epoch at UTC midnight on\n * January 1, 1970, in the proleptic Gregorian calendar which extends the\n * Gregorian calendar backwards to year one.\n *\n * All minutes are 60 seconds long. Leap seconds are \"smeared\" so that no leap\n * second table is needed for interpretation, using a [24-hour linear\n * smear](https://developers.google.com/time/smear).\n *\n * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By\n * restricting to that range, we ensure that we can convert to and from [RFC\n * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.\n *\n * # Examples\n *\n * Example 1: Compute Timestamp from POSIX `time()`.\n *\n * Timestamp timestamp;\n * timestamp.set_seconds(time(NULL));\n * timestamp.set_nanos(0);\n *\n * Example 2: Compute Timestamp from POSIX `gettimeofday()`.\n *\n * struct timeval tv;\n * gettimeofday(&tv, NULL);\n *\n * Timestamp timestamp;\n * timestamp.set_seconds(tv.tv_sec);\n * timestamp.set_nanos(tv.tv_usec * 1000);\n *\n * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.\n *\n * FILETIME ft;\n * GetSystemTimeAsFileTime(&ft);\n * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;\n *\n * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z\n * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.\n * Timestamp timestamp;\n * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));\n * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));\n *\n * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.\n *\n * long millis = System.currentTimeMillis();\n *\n * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)\n * .setNanos((int) ((millis % 1000) * 1000000)).build();\n *\n * Example 5: Compute Timestamp from Java `Instant.now()`.\n *\n * Instant now = Instant.now();\n *\n * Timestamp timestamp =\n * Timestamp.newBuilder().setSeconds(now.getEpochSecond())\n * .setNanos(now.getNano()).build();\n *\n * Example 6: Compute Timestamp from current time in Python.\n *\n * timestamp = Timestamp()\n * timestamp.GetCurrentTime()\n *\n * # JSON Mapping\n *\n * In JSON format, the Timestamp type is encoded as a string in the\n * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the\n * format is \"{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z\"\n * where {year} is always expressed using four digits while {month}, {day},\n * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional\n * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),\n * are optional. The \"Z\" suffix indicates the timezone (\"UTC\"); the timezone\n * is required. A proto3 JSON serializer should always use UTC (as indicated by\n * \"Z\") when printing the Timestamp type and a proto3 JSON parser should be\n * able to accept both UTC and other timezones (as indicated by an offset).\n *\n * For example, \"2017-01-15T01:30:15.01Z\" encodes 15.01 seconds past\n * 01:30 UTC on January 15, 2017.\n *\n * In JavaScript, one can convert a Date object to this format using the\n * standard\n * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)\n * method. In Python, a standard `datetime.datetime` object can be converted\n * to this format using\n * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with\n * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use\n * the Joda Time's [`ISODateTimeFormat.dateTime()`](\n * http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()\n * ) to obtain a formatter capable of generating timestamps in this format.\n *\n *\n * @generated from protobuf message google.protobuf.Timestamp\n */\nexport interface Timestamp {\n /**\n * Represents seconds of UTC time since Unix epoch\n * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to\n * 9999-12-31T23:59:59Z inclusive.\n *\n * @generated from protobuf field: int64 seconds = 1\n */\n seconds: bigint;\n /**\n * Non-negative fractions of a second at nanosecond resolution. Negative\n * second values with fractions must still have non-negative nanos values\n * that count forward in time. Must be from 0 to 999,999,999\n * inclusive.\n *\n * @generated from protobuf field: int32 nanos = 2\n */\n nanos: number;\n}\n// @generated message type with reflection information, may provide speed optimized methods\nclass Timestamp$Type extends MessageType<Timestamp> {\n constructor() {\n super(\"google.protobuf.Timestamp\", [\n { no: 1, name: \"seconds\", kind: \"scalar\", T: 3 /*ScalarType.INT64*/, L: 0 /*LongType.BIGINT*/ },\n { no: 2, name: \"nanos\", kind: \"scalar\", T: 5 /*ScalarType.INT32*/ }\n ]);\n }\n /**\n * Creates a new `Timestamp` for the current time.\n */\n now(): Timestamp {\n const msg = this.create();\n const ms = Date.now();\n msg.seconds = PbLong.from(Math.floor(ms / 1000)).toBigInt();\n msg.nanos = (ms % 1000) * 1000000;\n return msg;\n }\n /**\n * Converts a `Timestamp` to a JavaScript Date.\n */\n toDate(message: Timestamp): Date {\n return new Date(PbLong.from(message.seconds).toNumber() * 1000 + Math.ceil(message.nanos / 1000000));\n }\n /**\n * Converts a JavaScript Date to a `Timestamp`.\n */\n fromDate(date: Date): Timestamp {\n const msg = this.create();\n const ms = date.getTime();\n msg.seconds = PbLong.from(Math.floor(ms / 1000)).toBigInt();\n msg.nanos = ((ms % 1000) + (ms < 0 && ms % 1000 !== 0 ? 1000 : 0)) * 1000000;\n return msg;\n }\n /**\n * In JSON format, the `Timestamp` type is encoded as a string\n * in the RFC 3339 format.\n */\n internalJsonWrite(message: Timestamp, options: JsonWriteOptions): JsonValue {\n let ms = PbLong.from(message.seconds).toNumber() * 1000;\n if (ms < Date.parse(\"0001-01-01T00:00:00Z\") || ms > Date.parse(\"9999-12-31T23:59:59Z\"))\n throw new Error(\"Unable to encode Timestamp to JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.\");\n if (message.nanos < 0)\n throw new Error(\"Unable to encode invalid Timestamp to JSON. Nanos must not be negative.\");\n let z = \"Z\";\n if (message.nanos > 0) {\n let nanosStr = (message.nanos + 1000000000).toString().substring(1);\n if (nanosStr.substring(3) === \"000000\")\n z = \".\" + nanosStr.substring(0, 3) + \"Z\";\n else if (nanosStr.substring(6) === \"000\")\n z = \".\" + nanosStr.substring(0, 6) + \"Z\";\n else\n z = \".\" + nanosStr + \"Z\";\n }\n return new Date(ms).toISOString().replace(\".000Z\", z);\n }\n /**\n * In JSON format, the `Timestamp` type is encoded as a string\n * in the RFC 3339 format.\n */\n internalJsonRead(json: JsonValue, options: JsonReadOptions, target?: Timestamp): Timestamp {\n if (typeof json !== \"string\")\n throw new Error(\"Unable to parse Timestamp from JSON \" + typeofJsonValue(json) + \".\");\n let matches = json.match(/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:Z|\\.([0-9]{3,9})Z|([+-][0-9][0-9]:[0-9][0-9]))$/);\n if (!matches)\n throw new Error(\"Unable to parse Timestamp from JSON. Invalid format.\");\n let ms = Date.parse(matches[1] + \"-\" + matches[2] + \"-\" + matches[3] + \"T\" + matches[4] + \":\" + matches[5] + \":\" + matches[6] + (matches[8] ? matches[8] : \"Z\"));\n if (Number.isNaN(ms))\n throw new Error(\"Unable to parse Timestamp from JSON. Invalid value.\");\n if (ms < Date.parse(\"0001-01-01T00:00:00Z\") || ms > Date.parse(\"9999-12-31T23:59:59Z\"))\n throw new globalThis.Error(\"Unable to parse Timestamp from JSON. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.\");\n if (!target)\n target = this.create();\n target.seconds = PbLong.from(ms / 1000).toBigInt();\n target.nanos = 0;\n if (matches[7])\n target.nanos = (parseInt(\"1\" + matches[7] + \"0\".repeat(9 - matches[7].length)) - 1000000000);\n return target;\n }\n create(value?: PartialMessage<Timestamp>): Timestamp {\n const message = globalThis.Object.create((this.messagePrototype!));\n message.seconds = 0n;\n message.nanos = 0;\n if (value !== undefined)\n reflectionMergePartial<Timestamp>(this, message, value);\n return message;\n }\n internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Timestamp): Timestamp {\n let message = target ?? this.create(), end = reader.pos + length;\n while (reader.pos < end) {\n let [fieldNo, wireType] = reader.tag();\n switch (fieldNo) {\n case /* int64 seconds */ 1:\n message.seconds = reader.int64().toBigInt();\n break;\n case /* int32 nanos */ 2:\n message.nanos = reader.int32();\n break;\n default:\n let u = options.readUnknownField;\n if (u === \"throw\")\n throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);\n let d = reader.skip(wireType);\n if (u !== false)\n (u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);\n }\n }\n return message;\n }\n internalBinaryWrite(message: Timestamp, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {\n /* int64 seconds = 1; */\n if (message.seconds !== 0n)\n writer.tag(1, WireType.Varint).int64(message.seconds);\n /* int32 nanos = 2; */\n if (message.nanos !== 0)\n writer.tag(2, WireType.Varint).int32(message.nanos);\n let u = options.writeUnknownFields;\n if (u !== false)\n (u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);\n return writer;\n }\n}\n/**\n * @generated MessageType for protobuf message google.protobuf.Timestamp\n */\nexport const Timestamp = new Timestamp$Type();\n"],"names":[],"mappings":";;AAiKA;AACA,MAAM,cAAe,SAAQ,WAAsB,CAAA;AAC/C,IAAA,WAAA,GAAA;QACI,KAAK,CAAC,2BAA2B,EAAE;YAC/B,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,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client = require('../core/ll_client.cjs');
|
|
5
|
+
var config = require('../core/config.cjs');
|
|
6
|
+
var unauth_client = require('../core/unauth_client.cjs');
|
|
7
|
+
var client = require('../core/client.cjs');
|
|
8
|
+
var node_crypto = require('node:crypto');
|
|
9
|
+
var types = require('../core/types.cjs');
|
|
10
|
+
var auth = require('../core/auth.cjs');
|
|
11
|
+
var path = require('node:path');
|
|
12
|
+
|
|
13
|
+
function _interopNamespaceDefault(e) {
|
|
14
|
+
var n = Object.create(null);
|
|
15
|
+
if (e) {
|
|
16
|
+
Object.keys(e).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') {
|
|
18
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return e[k]; }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
n.default = e;
|
|
27
|
+
return Object.freeze(n);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
31
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
32
|
+
|
|
33
|
+
const CONFIG_FILE = 'test_config.json';
|
|
34
|
+
// const AUTH_DATA_FILE = '.test_auth.json';
|
|
35
|
+
let authDataFilePath;
|
|
36
|
+
function getFullAuthDataFilePath() {
|
|
37
|
+
if (authDataFilePath === undefined)
|
|
38
|
+
authDataFilePath = path__namespace.resolve('.test_auth.json');
|
|
39
|
+
return authDataFilePath;
|
|
40
|
+
}
|
|
41
|
+
function getTestConfig() {
|
|
42
|
+
let conf = {};
|
|
43
|
+
if (fs__namespace.existsSync(CONFIG_FILE))
|
|
44
|
+
conf = JSON.parse(fs__namespace.readFileSync(CONFIG_FILE, { encoding: 'utf-8' }));
|
|
45
|
+
if (process.env.PL_ADDRESS !== undefined)
|
|
46
|
+
conf.address = process.env.PL_ADDRESS;
|
|
47
|
+
if (process.env.PL_TEST_USER !== undefined)
|
|
48
|
+
conf.test_user = process.env.PL_TEST_USER;
|
|
49
|
+
if (process.env.PL_TEST_PASSWORD !== undefined)
|
|
50
|
+
conf.test_password = process.env.PL_TEST_PASSWORD;
|
|
51
|
+
if (process.env.PL_TEST_PROXY !== undefined)
|
|
52
|
+
conf.test_proxy = process.env.PL_TEST_PROXY;
|
|
53
|
+
if (conf.address === undefined)
|
|
54
|
+
throw new Error(`can't resolve platform address (checked ${CONFIG_FILE} file and PL_ADDRESS environment var)`);
|
|
55
|
+
return conf;
|
|
56
|
+
}
|
|
57
|
+
function saveAuthInfoCallback(tConf) {
|
|
58
|
+
return (authInformation) => {
|
|
59
|
+
const dst = getFullAuthDataFilePath();
|
|
60
|
+
const tmpDst = getFullAuthDataFilePath() + node_crypto.randomUUID();
|
|
61
|
+
fs__namespace.writeFileSync(tmpDst, Buffer.from(JSON.stringify({
|
|
62
|
+
conf: tConf,
|
|
63
|
+
authInformation,
|
|
64
|
+
expiration: auth.inferAuthRefreshTime(authInformation, 24 * 60 * 60),
|
|
65
|
+
})), 'utf8');
|
|
66
|
+
fs__namespace.renameSync(tmpDst, dst);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const cleanAuthInfoCallback = () => {
|
|
70
|
+
console.warn(`Removing: ${getFullAuthDataFilePath()}`);
|
|
71
|
+
fs__namespace.rmSync(getFullAuthDataFilePath());
|
|
72
|
+
};
|
|
73
|
+
async function getTestClientConf() {
|
|
74
|
+
const tConf = getTestConfig();
|
|
75
|
+
let authInformation = undefined;
|
|
76
|
+
// try recover from cache
|
|
77
|
+
if (fs__namespace.existsSync(getFullAuthDataFilePath())) {
|
|
78
|
+
try {
|
|
79
|
+
const cache = JSON.parse(fs__namespace.readFileSync(getFullAuthDataFilePath(), { encoding: 'utf-8' })); // TODO runtime validation
|
|
80
|
+
if (cache.conf.address === tConf.address
|
|
81
|
+
&& cache.conf.test_user === tConf.test_user
|
|
82
|
+
&& cache.conf.test_password === tConf.test_password
|
|
83
|
+
&& cache.expiration > Date.now())
|
|
84
|
+
authInformation = cache.authInformation;
|
|
85
|
+
}
|
|
86
|
+
catch (_e) {
|
|
87
|
+
// removing cache file on any error
|
|
88
|
+
fs__namespace.rmSync(getFullAuthDataFilePath());
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const plConf = config.plAddressToConfig(tConf.address);
|
|
92
|
+
const uClient = new unauth_client.UnauthenticatedPlClient(plConf);
|
|
93
|
+
const requireAuth = await uClient.requireAuth();
|
|
94
|
+
if (!requireAuth && (tConf.test_user !== undefined || tConf.test_password !== undefined))
|
|
95
|
+
throw new Error(`Server require no auth, but test user name or test password are provided via (${CONFIG_FILE}) or env variables: PL_TEST_USER and PL_TEST_PASSWORD`);
|
|
96
|
+
if (requireAuth && (tConf.test_user === undefined || tConf.test_password === undefined))
|
|
97
|
+
throw new Error(`No auth information found in config (${CONFIG_FILE}) or env variables: PL_TEST_USER and PL_TEST_PASSWORD`);
|
|
98
|
+
if (authInformation === undefined) {
|
|
99
|
+
if (requireAuth)
|
|
100
|
+
authInformation = await uClient.login(tConf.test_user, tConf.test_password);
|
|
101
|
+
// No authorization is required
|
|
102
|
+
else
|
|
103
|
+
authInformation = {};
|
|
104
|
+
// saving cache
|
|
105
|
+
saveAuthInfoCallback(tConf)(authInformation);
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
conf: plConf,
|
|
109
|
+
auth: {
|
|
110
|
+
authInformation,
|
|
111
|
+
onUpdate: saveAuthInfoCallback(tConf),
|
|
112
|
+
onAuthError: cleanAuthInfoCallback,
|
|
113
|
+
onUpdateError: cleanAuthInfoCallback,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
async function getTestLLClient(confOverrides = {}) {
|
|
118
|
+
const { conf, auth } = await getTestClientConf();
|
|
119
|
+
return new ll_client.LLPlClient({ ...conf, ...confOverrides }, { auth });
|
|
120
|
+
}
|
|
121
|
+
async function getTestClient(alternativeRoot) {
|
|
122
|
+
const { conf, auth } = await getTestClientConf();
|
|
123
|
+
if (alternativeRoot !== undefined && conf.alternativeRoot !== undefined)
|
|
124
|
+
throw new Error('test pl address configured with alternative root');
|
|
125
|
+
return await client.PlClient.init({ ...conf, alternativeRoot }, auth);
|
|
126
|
+
}
|
|
127
|
+
async function withTempRoot(body) {
|
|
128
|
+
const alternativeRoot = `test_${Date.now()}_${node_crypto.randomUUID()}`;
|
|
129
|
+
let altRootId = types.NullResourceId;
|
|
130
|
+
try {
|
|
131
|
+
const client = await getTestClient(alternativeRoot);
|
|
132
|
+
altRootId = client.clientRoot;
|
|
133
|
+
const value = await body(client);
|
|
134
|
+
const rawClient = await getTestClient();
|
|
135
|
+
await rawClient.deleteAlternativeRoot(alternativeRoot);
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
console.log(`ALTERNATIVE ROOT: ${alternativeRoot} (${types.resourceIdToString(altRootId)})`);
|
|
140
|
+
throw new Error(err.message, { cause: err });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
exports.getTestClient = getTestClient;
|
|
145
|
+
exports.getTestClientConf = getTestClientConf;
|
|
146
|
+
exports.getTestConfig = getTestConfig;
|
|
147
|
+
exports.getTestLLClient = getTestLLClient;
|
|
148
|
+
exports.withTempRoot = withTempRoot;
|
|
149
|
+
//# sourceMappingURL=test_config.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test_config.cjs","sources":["../../src/test/test_config.ts"],"sourcesContent":["import * as fs from 'node:fs';\nimport { LLPlClient } from '../core/ll_client';\nimport type { AuthInformation, AuthOps, PlClientConfig } from '../core/config';\nimport { plAddressToConfig } from '../core/config';\nimport { UnauthenticatedPlClient } from '../core/unauth_client';\nimport { PlClient } from '../core/client';\nimport { randomUUID } from 'node:crypto';\nimport type { OptionalResourceId } from '../core/types';\nimport { NullResourceId, resourceIdToString } from '../core/types';\nimport { inferAuthRefreshTime } from '../core/auth';\nimport * as path from 'node:path';\n\nexport interface TestConfig {\n address: string;\n test_proxy?: string;\n test_user?: string;\n test_password?: string;\n}\n\nconst CONFIG_FILE = 'test_config.json';\n// const AUTH_DATA_FILE = '.test_auth.json';\n\nlet authDataFilePath: string | undefined;\n\nfunction getFullAuthDataFilePath() {\n if (authDataFilePath === undefined) authDataFilePath = path.resolve('.test_auth.json');\n return authDataFilePath;\n}\n\nexport function getTestConfig(): TestConfig {\n let conf: Partial<TestConfig> = {};\n if (fs.existsSync(CONFIG_FILE))\n conf = JSON.parse(fs.readFileSync(CONFIG_FILE, { encoding: 'utf-8' })) as TestConfig;\n\n if (process.env.PL_ADDRESS !== undefined) conf.address = process.env.PL_ADDRESS;\n\n if (process.env.PL_TEST_USER !== undefined) conf.test_user = process.env.PL_TEST_USER;\n\n if (process.env.PL_TEST_PASSWORD !== undefined) conf.test_password = process.env.PL_TEST_PASSWORD;\n\n if (process.env.PL_TEST_PROXY !== undefined) conf.test_proxy = process.env.PL_TEST_PROXY;\n\n if (conf.address === undefined)\n throw new Error(\n `can't resolve platform address (checked ${CONFIG_FILE} file and PL_ADDRESS environment var)`,\n );\n\n return conf as TestConfig;\n}\n\ninterface AuthCache {\n /** To check if config changed */\n conf: TestConfig;\n expiration: number;\n authInformation: AuthInformation;\n}\n\nfunction saveAuthInfoCallback(tConf: TestConfig): (authInformation: AuthInformation) => void {\n return (authInformation) => {\n const dst = getFullAuthDataFilePath();\n const tmpDst = getFullAuthDataFilePath() + randomUUID();\n fs.writeFileSync(\n tmpDst,\n Buffer.from(\n JSON.stringify({\n conf: tConf,\n authInformation,\n expiration: inferAuthRefreshTime(authInformation, 24 * 60 * 60),\n } as AuthCache),\n ),\n 'utf8',\n );\n fs.renameSync(tmpDst, dst);\n };\n}\n\nconst cleanAuthInfoCallback = () => {\n console.warn(`Removing: ${getFullAuthDataFilePath()}`);\n fs.rmSync(getFullAuthDataFilePath());\n};\n\nexport async function getTestClientConf(): Promise<{ conf: PlClientConfig; auth: AuthOps }> {\n const tConf = getTestConfig();\n\n let authInformation: AuthInformation | undefined = undefined;\n\n // try recover from cache\n if (fs.existsSync(getFullAuthDataFilePath())) {\n try {\n const cache: AuthCache = JSON.parse(\n fs.readFileSync(getFullAuthDataFilePath(), { encoding: 'utf-8' }),\n ) as AuthCache; // TODO runtime validation\n if (\n cache.conf.address === tConf.address\n && cache.conf.test_user === tConf.test_user\n && cache.conf.test_password === tConf.test_password\n && cache.expiration > Date.now()\n )\n authInformation = cache.authInformation;\n } catch (_e) {\n // removing cache file on any error\n fs.rmSync(getFullAuthDataFilePath());\n }\n }\n\n const plConf = plAddressToConfig(tConf.address);\n\n const uClient = new UnauthenticatedPlClient(plConf);\n\n const requireAuth = await uClient.requireAuth();\n\n if (!requireAuth && (tConf.test_user !== undefined || tConf.test_password !== undefined))\n throw new Error(\n `Server require no auth, but test user name or test password are provided via (${CONFIG_FILE}) or env variables: PL_TEST_USER and PL_TEST_PASSWORD`,\n );\n\n if (requireAuth && (tConf.test_user === undefined || tConf.test_password === undefined))\n throw new Error(\n `No auth information found in config (${CONFIG_FILE}) or env variables: PL_TEST_USER and PL_TEST_PASSWORD`,\n );\n\n if (authInformation === undefined) {\n if (requireAuth) authInformation = await uClient.login(tConf.test_user!, tConf.test_password!);\n // No authorization is required\n else authInformation = {};\n\n // saving cache\n saveAuthInfoCallback(tConf)(authInformation);\n }\n\n return {\n conf: plConf,\n auth: {\n authInformation,\n onUpdate: saveAuthInfoCallback(tConf),\n onAuthError: cleanAuthInfoCallback,\n onUpdateError: cleanAuthInfoCallback,\n },\n };\n}\n\nexport async function getTestLLClient(confOverrides: Partial<PlClientConfig> = {}) {\n const { conf, auth } = await getTestClientConf();\n return new LLPlClient({ ...conf, ...confOverrides }, { auth });\n}\n\nexport async function getTestClient(alternativeRoot?: string) {\n const { conf, auth } = await getTestClientConf();\n if (alternativeRoot !== undefined && conf.alternativeRoot !== undefined)\n throw new Error('test pl address configured with alternative root');\n return await PlClient.init({ ...conf, alternativeRoot }, auth);\n}\n\nexport async function withTempRoot<T>(body: (pl: PlClient) => Promise<T>): Promise<T> {\n const alternativeRoot = `test_${Date.now()}_${randomUUID()}`;\n let altRootId: OptionalResourceId = NullResourceId;\n try {\n const client = await getTestClient(alternativeRoot);\n altRootId = client.clientRoot;\n const value = await body(client);\n const rawClient = await getTestClient();\n await rawClient.deleteAlternativeRoot(alternativeRoot);\n return value;\n } catch (err: any) {\n console.log(`ALTERNATIVE ROOT: ${alternativeRoot} (${resourceIdToString(altRootId)})`);\n throw new Error(err.message, { cause: err });\n }\n}\n"],"names":["path","fs","randomUUID","inferAuthRefreshTime","plAddressToConfig","UnauthenticatedPlClient","LLPlClient","PlClient","NullResourceId","resourceIdToString"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAM,WAAW,GAAG,kBAAkB;AACtC;AAEA,IAAI,gBAAoC;AAExC,SAAS,uBAAuB,GAAA;IAC9B,IAAI,gBAAgB,KAAK,SAAS;AAAE,QAAA,gBAAgB,GAAGA,eAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC;AACtF,IAAA,OAAO,gBAAgB;AACzB;SAEgB,aAAa,GAAA;IAC3B,IAAI,IAAI,GAAwB,EAAE;AAClC,IAAA,IAAIC,aAAE,CAAC,UAAU,CAAC,WAAW,CAAC;AAC5B,QAAA,IAAI,GAAG,IAAI,CAAC,KAAK,CAACA,aAAE,CAAC,YAAY,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAe;AAEtF,IAAA,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,KAAK,SAAS;QAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU;AAE/E,IAAA,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,KAAK,SAAS;QAAE,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC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QAAA,SAAS,GAAG,MAAM,CAAC,UAAU;AAC7B,QAAA,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC;AAChC,QAAA,MAAM,SAAS,GAAG,MAAM,aAAa,EAAE;AACvC,QAAA,MAAM,SAAS,CAAC,qBAAqB,CAAC,eAAe,CAAC;AACtD,QAAA,OAAO,KAAK;IACd;IAAE,OAAO,GAAQ,EAAE;AACjB,QAAA,OAAO,CAAC,GAAG,CAAC,CAAA,kBAAA,EAAqB,eAAe,CAAA,EAAA,EAAKC,wBAAkB,CAAC,SAAS,CAAC,CAAA,CAAA,CAAG,CAAC;AACtF,QAAA,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;IAC9C;AACF;;;;;;;;"}
|
|
@@ -15,4 +15,3 @@ export declare function getTestClientConf(): Promise<{
|
|
|
15
15
|
export declare function getTestLLClient(confOverrides?: Partial<PlClientConfig>): Promise<LLPlClient>;
|
|
16
16
|
export declare function getTestClient(alternativeRoot?: string): Promise<PlClient>;
|
|
17
17
|
export declare function withTempRoot<T>(body: (pl: PlClient) => Promise<T>): Promise<T>;
|
|
18
|
-
//# sourceMappingURL=test_config.d.ts.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import { LLPlClient } from '../core/ll_client.js';
|
|
3
|
+
import { plAddressToConfig } from '../core/config.js';
|
|
4
|
+
import { UnauthenticatedPlClient } from '../core/unauth_client.js';
|
|
5
|
+
import { PlClient } from '../core/client.js';
|
|
6
|
+
import { randomUUID } from 'node:crypto';
|
|
7
|
+
import { NullResourceId, resourceIdToString } from '../core/types.js';
|
|
8
|
+
import { inferAuthRefreshTime } from '../core/auth.js';
|
|
9
|
+
import * as path from 'node:path';
|
|
10
|
+
|
|
11
|
+
const CONFIG_FILE = 'test_config.json';
|
|
12
|
+
// const AUTH_DATA_FILE = '.test_auth.json';
|
|
13
|
+
let authDataFilePath;
|
|
14
|
+
function getFullAuthDataFilePath() {
|
|
15
|
+
if (authDataFilePath === undefined)
|
|
16
|
+
authDataFilePath = path.resolve('.test_auth.json');
|
|
17
|
+
return authDataFilePath;
|
|
18
|
+
}
|
|
19
|
+
function getTestConfig() {
|
|
20
|
+
let conf = {};
|
|
21
|
+
if (fs.existsSync(CONFIG_FILE))
|
|
22
|
+
conf = JSON.parse(fs.readFileSync(CONFIG_FILE, { encoding: 'utf-8' }));
|
|
23
|
+
if (process.env.PL_ADDRESS !== undefined)
|
|
24
|
+
conf.address = process.env.PL_ADDRESS;
|
|
25
|
+
if (process.env.PL_TEST_USER !== undefined)
|
|
26
|
+
conf.test_user = process.env.PL_TEST_USER;
|
|
27
|
+
if (process.env.PL_TEST_PASSWORD !== undefined)
|
|
28
|
+
conf.test_password = process.env.PL_TEST_PASSWORD;
|
|
29
|
+
if (process.env.PL_TEST_PROXY !== undefined)
|
|
30
|
+
conf.test_proxy = process.env.PL_TEST_PROXY;
|
|
31
|
+
if (conf.address === undefined)
|
|
32
|
+
throw new Error(`can't resolve platform address (checked ${CONFIG_FILE} file and PL_ADDRESS environment var)`);
|
|
33
|
+
return conf;
|
|
34
|
+
}
|
|
35
|
+
function saveAuthInfoCallback(tConf) {
|
|
36
|
+
return (authInformation) => {
|
|
37
|
+
const dst = getFullAuthDataFilePath();
|
|
38
|
+
const tmpDst = getFullAuthDataFilePath() + randomUUID();
|
|
39
|
+
fs.writeFileSync(tmpDst, Buffer.from(JSON.stringify({
|
|
40
|
+
conf: tConf,
|
|
41
|
+
authInformation,
|
|
42
|
+
expiration: inferAuthRefreshTime(authInformation, 24 * 60 * 60),
|
|
43
|
+
})), 'utf8');
|
|
44
|
+
fs.renameSync(tmpDst, dst);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const cleanAuthInfoCallback = () => {
|
|
48
|
+
console.warn(`Removing: ${getFullAuthDataFilePath()}`);
|
|
49
|
+
fs.rmSync(getFullAuthDataFilePath());
|
|
50
|
+
};
|
|
51
|
+
async function getTestClientConf() {
|
|
52
|
+
const tConf = getTestConfig();
|
|
53
|
+
let authInformation = undefined;
|
|
54
|
+
// try recover from cache
|
|
55
|
+
if (fs.existsSync(getFullAuthDataFilePath())) {
|
|
56
|
+
try {
|
|
57
|
+
const cache = JSON.parse(fs.readFileSync(getFullAuthDataFilePath(), { encoding: 'utf-8' })); // TODO runtime validation
|
|
58
|
+
if (cache.conf.address === tConf.address
|
|
59
|
+
&& cache.conf.test_user === tConf.test_user
|
|
60
|
+
&& cache.conf.test_password === tConf.test_password
|
|
61
|
+
&& cache.expiration > Date.now())
|
|
62
|
+
authInformation = cache.authInformation;
|
|
63
|
+
}
|
|
64
|
+
catch (_e) {
|
|
65
|
+
// removing cache file on any error
|
|
66
|
+
fs.rmSync(getFullAuthDataFilePath());
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const plConf = plAddressToConfig(tConf.address);
|
|
70
|
+
const uClient = new UnauthenticatedPlClient(plConf);
|
|
71
|
+
const requireAuth = await uClient.requireAuth();
|
|
72
|
+
if (!requireAuth && (tConf.test_user !== undefined || tConf.test_password !== undefined))
|
|
73
|
+
throw new Error(`Server require no auth, but test user name or test password are provided via (${CONFIG_FILE}) or env variables: PL_TEST_USER and PL_TEST_PASSWORD`);
|
|
74
|
+
if (requireAuth && (tConf.test_user === undefined || tConf.test_password === undefined))
|
|
75
|
+
throw new Error(`No auth information found in config (${CONFIG_FILE}) or env variables: PL_TEST_USER and PL_TEST_PASSWORD`);
|
|
76
|
+
if (authInformation === undefined) {
|
|
77
|
+
if (requireAuth)
|
|
78
|
+
authInformation = await uClient.login(tConf.test_user, tConf.test_password);
|
|
79
|
+
// No authorization is required
|
|
80
|
+
else
|
|
81
|
+
authInformation = {};
|
|
82
|
+
// saving cache
|
|
83
|
+
saveAuthInfoCallback(tConf)(authInformation);
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
conf: plConf,
|
|
87
|
+
auth: {
|
|
88
|
+
authInformation,
|
|
89
|
+
onUpdate: saveAuthInfoCallback(tConf),
|
|
90
|
+
onAuthError: cleanAuthInfoCallback,
|
|
91
|
+
onUpdateError: cleanAuthInfoCallback,
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async function getTestLLClient(confOverrides = {}) {
|
|
96
|
+
const { conf, auth } = await getTestClientConf();
|
|
97
|
+
return new LLPlClient({ ...conf, ...confOverrides }, { auth });
|
|
98
|
+
}
|
|
99
|
+
async function getTestClient(alternativeRoot) {
|
|
100
|
+
const { conf, auth } = await getTestClientConf();
|
|
101
|
+
if (alternativeRoot !== undefined && conf.alternativeRoot !== undefined)
|
|
102
|
+
throw new Error('test pl address configured with alternative root');
|
|
103
|
+
return await PlClient.init({ ...conf, alternativeRoot }, auth);
|
|
104
|
+
}
|
|
105
|
+
async function withTempRoot(body) {
|
|
106
|
+
const alternativeRoot = `test_${Date.now()}_${randomUUID()}`;
|
|
107
|
+
let altRootId = NullResourceId;
|
|
108
|
+
try {
|
|
109
|
+
const client = await getTestClient(alternativeRoot);
|
|
110
|
+
altRootId = client.clientRoot;
|
|
111
|
+
const value = await body(client);
|
|
112
|
+
const rawClient = await getTestClient();
|
|
113
|
+
await rawClient.deleteAlternativeRoot(alternativeRoot);
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
console.log(`ALTERNATIVE ROOT: ${alternativeRoot} (${resourceIdToString(altRootId)})`);
|
|
118
|
+
throw new Error(err.message, { cause: err });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { getTestClient, getTestClientConf, getTestConfig, getTestLLClient, withTempRoot };
|
|
123
|
+
//# sourceMappingURL=test_config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test_config.js","sources":["../../src/test/test_config.ts"],"sourcesContent":["import * as fs from 'node:fs';\nimport { LLPlClient } from '../core/ll_client';\nimport type { AuthInformation, AuthOps, PlClientConfig } from '../core/config';\nimport { plAddressToConfig } from '../core/config';\nimport { UnauthenticatedPlClient } from '../core/unauth_client';\nimport { PlClient } from '../core/client';\nimport { randomUUID } from 'node:crypto';\nimport type { OptionalResourceId } from '../core/types';\nimport { NullResourceId, resourceIdToString } from '../core/types';\nimport { inferAuthRefreshTime } from '../core/auth';\nimport * as path from 'node:path';\n\nexport interface TestConfig {\n address: string;\n test_proxy?: string;\n test_user?: string;\n test_password?: string;\n}\n\nconst CONFIG_FILE = 'test_config.json';\n// const AUTH_DATA_FILE = '.test_auth.json';\n\nlet authDataFilePath: string | undefined;\n\nfunction getFullAuthDataFilePath() {\n if (authDataFilePath === undefined) authDataFilePath = path.resolve('.test_auth.json');\n return authDataFilePath;\n}\n\nexport function getTestConfig(): TestConfig {\n let conf: Partial<TestConfig> = {};\n if (fs.existsSync(CONFIG_FILE))\n conf = JSON.parse(fs.readFileSync(CONFIG_FILE, { encoding: 'utf-8' })) as TestConfig;\n\n if (process.env.PL_ADDRESS !== undefined) conf.address = process.env.PL_ADDRESS;\n\n if (process.env.PL_TEST_USER !== undefined) conf.test_user = process.env.PL_TEST_USER;\n\n if (process.env.PL_TEST_PASSWORD !== undefined) conf.test_password = process.env.PL_TEST_PASSWORD;\n\n if (process.env.PL_TEST_PROXY !== undefined) conf.test_proxy = process.env.PL_TEST_PROXY;\n\n if (conf.address === undefined)\n throw new Error(\n `can't resolve platform address (checked ${CONFIG_FILE} file and PL_ADDRESS environment var)`,\n );\n\n return conf as TestConfig;\n}\n\ninterface AuthCache {\n /** To check if config changed */\n conf: TestConfig;\n expiration: number;\n authInformation: AuthInformation;\n}\n\nfunction saveAuthInfoCallback(tConf: TestConfig): (authInformation: AuthInformation) => void {\n return (authInformation) => {\n const dst = getFullAuthDataFilePath();\n const tmpDst = getFullAuthDataFilePath() + randomUUID();\n fs.writeFileSync(\n tmpDst,\n Buffer.from(\n JSON.stringify({\n conf: tConf,\n authInformation,\n expiration: inferAuthRefreshTime(authInformation, 24 * 60 * 60),\n } as AuthCache),\n ),\n 'utf8',\n );\n fs.renameSync(tmpDst, dst);\n };\n}\n\nconst cleanAuthInfoCallback = () => {\n console.warn(`Removing: ${getFullAuthDataFilePath()}`);\n fs.rmSync(getFullAuthDataFilePath());\n};\n\nexport async function getTestClientConf(): Promise<{ conf: PlClientConfig; auth: AuthOps }> {\n const tConf = getTestConfig();\n\n let authInformation: AuthInformation | undefined = undefined;\n\n // try recover from cache\n if (fs.existsSync(getFullAuthDataFilePath())) {\n try {\n const cache: AuthCache = JSON.parse(\n fs.readFileSync(getFullAuthDataFilePath(), { encoding: 'utf-8' }),\n ) as AuthCache; // TODO runtime validation\n if (\n cache.conf.address === tConf.address\n && cache.conf.test_user === tConf.test_user\n && cache.conf.test_password === tConf.test_password\n && cache.expiration > Date.now()\n )\n authInformation = cache.authInformation;\n } catch (_e) {\n // removing cache file on any error\n fs.rmSync(getFullAuthDataFilePath());\n }\n }\n\n const plConf = plAddressToConfig(tConf.address);\n\n const uClient = new UnauthenticatedPlClient(plConf);\n\n const requireAuth = await uClient.requireAuth();\n\n if (!requireAuth && (tConf.test_user !== undefined || tConf.test_password !== undefined))\n throw new Error(\n `Server require no auth, but test user name or test password are provided via (${CONFIG_FILE}) or env variables: PL_TEST_USER and PL_TEST_PASSWORD`,\n );\n\n if (requireAuth && (tConf.test_user === undefined || tConf.test_password === undefined))\n throw new Error(\n `No auth information found in config (${CONFIG_FILE}) or env variables: PL_TEST_USER and PL_TEST_PASSWORD`,\n );\n\n if (authInformation === undefined) {\n if (requireAuth) authInformation = await uClient.login(tConf.test_user!, tConf.test_password!);\n // No authorization is required\n else authInformation = {};\n\n // saving cache\n saveAuthInfoCallback(tConf)(authInformation);\n }\n\n return {\n conf: plConf,\n auth: {\n authInformation,\n onUpdate: saveAuthInfoCallback(tConf),\n onAuthError: cleanAuthInfoCallback,\n onUpdateError: cleanAuthInfoCallback,\n },\n };\n}\n\nexport async function getTestLLClient(confOverrides: Partial<PlClientConfig> = {}) {\n const { conf, auth } = await getTestClientConf();\n return new LLPlClient({ ...conf, ...confOverrides }, { auth });\n}\n\nexport async function getTestClient(alternativeRoot?: string) {\n const { conf, auth } = await getTestClientConf();\n if (alternativeRoot !== undefined && conf.alternativeRoot !== undefined)\n throw new Error('test pl address configured with alternative root');\n return await PlClient.init({ ...conf, alternativeRoot }, auth);\n}\n\nexport async function withTempRoot<T>(body: (pl: PlClient) => Promise<T>): Promise<T> {\n const alternativeRoot = `test_${Date.now()}_${randomUUID()}`;\n let altRootId: OptionalResourceId = NullResourceId;\n try {\n const client = await getTestClient(alternativeRoot);\n altRootId = client.clientRoot;\n const value = await body(client);\n const rawClient = await getTestClient();\n await rawClient.deleteAlternativeRoot(alternativeRoot);\n return value;\n } catch (err: any) {\n console.log(`ALTERNATIVE ROOT: ${alternativeRoot} (${resourceIdToString(altRootId)})`);\n throw new Error(err.message, { cause: err });\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAmBA,MAAM,WAAW,GAAG,kBAAkB;AACtC;AAEA,IAAI,gBAAoC;AAExC,SAAS,uBAAuB,GAAA;IAC9B,IAAI,gBAAgB,KAAK,SAAS;AAAE,QAAA,gBAAgB,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC;AACtF,IAAA,OAAO,gBAAgB;AACzB;SAEgB,aAAa,GAAA;IAC3B,IAAI,IAAI,GAAwB,EAAE;AAClC,IAAA,IAAI,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;AAC5B,QAAA,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAe;AAEtF,IAAA,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,KAAK,SAAS;QAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU;AAE/E,IAAA,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY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M,GAAG,MAAM,aAAa,CAAC,eAAe,CAAC;AACnD,QAAA,SAAS,GAAG,MAAM,CAAC,UAAU;AAC7B,QAAA,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC;AAChC,QAAA,MAAM,SAAS,GAAG,MAAM,aAAa,EAAE;AACvC,QAAA,MAAM,SAAS,CAAC,qBAAqB,CAAC,eAAe,CAAC;AACtD,QAAA,OAAO,KAAK;IACd;IAAE,OAAO,GAAQ,EAAE;AACjB,QAAA,OAAO,CAAC,GAAG,CAAC,CAAA,kBAAA,EAAqB,eAAe,CAAA,EAAA,EAAK,kBAAkB,CAAC,SAAS,CAAC,CAAA,CAAA,CAAG,CAAC;AACtF,QAAA,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;IAC9C;AACF;;;;"}
|
package/dist/util/branding.d.ts
CHANGED
package/dist/util/pl.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pl.cjs","sources":["../../src/util/pl.ts"],"sourcesContent":["export type PlJWTPayload = {\n user: {\n login: string;\n };\n exp: number;\n iat: number;\n};\n\nexport function parsePlJwt(token: string): PlJWTPayload {\n return JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());\n}\n"],"names":[],"mappings":";;AAQM,SAAU,UAAU,CAAC,KAAa,EAAA;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC1E;;;;"}
|
package/dist/util/pl.d.ts
CHANGED
package/dist/util/pl.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pl.js","sources":["../../src/util/pl.ts"],"sourcesContent":["export type PlJWTPayload = {\n user: {\n login: string;\n };\n exp: number;\n iat: number;\n};\n\nexport function parsePlJwt(token: string): PlJWTPayload {\n return JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());\n}\n"],"names":[],"mappings":"AAQM,SAAU,UAAU,CAAC,KAAa,EAAA;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC1E;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function isArrayBufferOrView(value) {
|
|
4
|
+
return value instanceof ArrayBuffer || ArrayBuffer.isView(value);
|
|
5
|
+
}
|
|
6
|
+
function toBytes(value) {
|
|
7
|
+
if (typeof value === 'string')
|
|
8
|
+
return Buffer.from(value);
|
|
9
|
+
else if (isArrayBufferOrView(value))
|
|
10
|
+
return value;
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
12
|
+
else
|
|
13
|
+
throw new Error(`Unexpected type: ${value}`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.toBytes = toBytes;
|
|
17
|
+
//# sourceMappingURL=util.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.cjs","sources":["../../src/util/util.ts"],"sourcesContent":["function isArrayBufferOrView(value: unknown): value is ArrayBufferLike {\n return value instanceof ArrayBuffer || ArrayBuffer.isView(value);\n}\n\nexport function toBytes(value: string | Uint8Array): Uint8Array {\n if (typeof value === 'string') return Buffer.from(value);\n else if (isArrayBufferOrView(value)) return value;\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n else throw new Error(`Unexpected type: ${value}`);\n}\n"],"names":[],"mappings":";;AAAA,SAAS,mBAAmB,CAAC,KAAc,EAAA;IACzC,OAAO,KAAK,YAAY,WAAW,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC;AAClE;AAEM,SAAU,OAAO,CAAC,KAA0B,EAAA;IAChD,IAAI,OAAO,KAAK,KAAK,QAAQ;AAAE,QAAA,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;SACnD,IAAI,mBAAmB,CAAC,KAAK,CAAC;AAAE,QAAA,OAAO,KAAK;;;AAE5C,QAAA,MAAM,IAAI,KAAK,CAAC,oBAAoB,KAAK,CAAA,CAAE,CAAC;AACnD;;;;"}
|
package/dist/util/util.d.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function isArrayBufferOrView(value) {
|
|
2
|
+
return value instanceof ArrayBuffer || ArrayBuffer.isView(value);
|
|
3
|
+
}
|
|
4
|
+
function toBytes(value) {
|
|
5
|
+
if (typeof value === 'string')
|
|
6
|
+
return Buffer.from(value);
|
|
7
|
+
else if (isArrayBufferOrView(value))
|
|
8
|
+
return value;
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
10
|
+
else
|
|
11
|
+
throw new Error(`Unexpected type: ${value}`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { toBytes };
|
|
15
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sources":["../../src/util/util.ts"],"sourcesContent":["function isArrayBufferOrView(value: unknown): value is ArrayBufferLike {\n return value instanceof ArrayBuffer || ArrayBuffer.isView(value);\n}\n\nexport function toBytes(value: string | Uint8Array): Uint8Array {\n if (typeof value === 'string') return Buffer.from(value);\n else if (isArrayBufferOrView(value)) return value;\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n else throw new Error(`Unexpected type: ${value}`);\n}\n"],"names":[],"mappings":"AAAA,SAAS,mBAAmB,CAAC,KAAc,EAAA;IACzC,OAAO,KAAK,YAAY,WAAW,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC;AAClE;AAEM,SAAU,OAAO,CAAC,KAA0B,EAAA;IAChD,IAAI,OAAO,KAAK,KAAK,QAAQ;AAAE,QAAA,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;SACnD,IAAI,mBAAmB,CAAC,KAAK,CAAC;AAAE,QAAA,OAAO,KAAK;;;AAE5C,QAAA,MAAM,IAAI,KAAK,CAAC,oBAAoB,KAAK,CAAA,CAAE,CAAC;AACnD;;;;"}
|
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milaboratories/pl-client",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.9",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=20.3.0"
|
|
6
6
|
},
|
|
7
7
|
"description": "New TS/JS client for Platform API",
|
|
8
|
+
"type": "module",
|
|
8
9
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"main": "./dist/index.
|
|
10
|
-
"module": "./dist/index.
|
|
10
|
+
"main": "./dist/index.cjs",
|
|
11
|
+
"module": "./dist/index.js",
|
|
11
12
|
"exports": {
|
|
12
13
|
".": {
|
|
13
14
|
"types": "./dist/index.d.ts",
|
|
14
|
-
"require": "./dist/index.
|
|
15
|
-
"import": "./dist/index.
|
|
15
|
+
"require": "./dist/index.cjs",
|
|
16
|
+
"import": "./dist/index.js"
|
|
16
17
|
}
|
|
17
18
|
},
|
|
18
19
|
"files": [
|
|
@@ -32,12 +33,11 @@
|
|
|
32
33
|
"undici": "~7.13.0",
|
|
33
34
|
"utility-types": "^3.11.0",
|
|
34
35
|
"yaml": "^2.8.0",
|
|
35
|
-
"@milaboratories/pl-http": "^1.1.
|
|
36
|
-
"@milaboratories/ts-helpers": "^1.4.
|
|
36
|
+
"@milaboratories/pl-http": "^1.1.6",
|
|
37
|
+
"@milaboratories/ts-helpers": "^1.4.4"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"typescript": "~5.6.3",
|
|
40
|
-
"vite": "^6.3.5",
|
|
41
41
|
"@types/node": "~20.16.15",
|
|
42
42
|
"@protobuf-ts/plugin": "2.11.1",
|
|
43
43
|
"@types/http-proxy": "^1.17.16",
|
|
@@ -45,11 +45,14 @@
|
|
|
45
45
|
"jest": "^29.7.0",
|
|
46
46
|
"@jest/globals": "^29.7.0",
|
|
47
47
|
"ts-jest": "^29.2.6",
|
|
48
|
-
"@milaboratories/
|
|
48
|
+
"@milaboratories/ts-configs": "1.0.6",
|
|
49
|
+
"@milaboratories/build-configs": "1.0.6",
|
|
50
|
+
"@milaboratories/ts-builder": "1.0.1"
|
|
49
51
|
},
|
|
50
52
|
"scripts": {
|
|
51
|
-
"type-check": "
|
|
52
|
-
"build": "
|
|
53
|
+
"type-check": "ts-builder types --target node",
|
|
54
|
+
"build": "ts-builder build --target node",
|
|
55
|
+
"watch": "ts-builder build --target node --watch",
|
|
53
56
|
"lint": "eslint .",
|
|
54
57
|
"test": "jest --runInBand",
|
|
55
58
|
"do-pack": "rm -f *.tgz && pnpm pack && mv *.tgz package.tgz"
|
package/src/core/client.test.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { PlClient } from './client';
|
|
|
3
3
|
import { PlDriver, PlDriverDefinition } from './driver';
|
|
4
4
|
import { Dispatcher, request } from 'undici';
|
|
5
5
|
import { GrpcClientProviderFactory } from './grpc';
|
|
6
|
+
import { test, expect } from '@jest/globals';
|
|
6
7
|
|
|
7
8
|
test('test client init', async () => {
|
|
8
9
|
const client = await getTestClient(undefined);
|
package/src/core/config.test.ts
CHANGED
package/src/core/config.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ExponentialBackoffRetryOptions } from '@milaboratories/ts-helpers';
|
|
2
|
+
|
|
1
3
|
/** Base configuration structure for PL client */
|
|
2
4
|
export interface PlClientConfig {
|
|
3
5
|
/** Port and host of remote pl server */
|
|
@@ -93,6 +95,14 @@ export const DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER = 1.5; // + 50% on eac
|
|
|
93
95
|
export const DEFAULT_RETRY_LINEAR_BACKOFF_STEP = 50; // + 50 ms
|
|
94
96
|
export const DEFAULT_RETRY_JITTER = 0.3; // 30%
|
|
95
97
|
|
|
98
|
+
export const DefaultRetryOptions: ExponentialBackoffRetryOptions = {
|
|
99
|
+
type: 'exponentialBackoff',
|
|
100
|
+
maxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,
|
|
101
|
+
initialDelay: DEFAULT_RETRY_INITIAL_DELAY,
|
|
102
|
+
backoffMultiplier: DEFAULT_RETRY_EXPONENTIAL_BACKOFF_MULTIPLIER,
|
|
103
|
+
jitter: DEFAULT_RETRY_JITTER,
|
|
104
|
+
};
|
|
105
|
+
|
|
96
106
|
type PlConfigOverrides = Partial<
|
|
97
107
|
Pick<
|
|
98
108
|
PlClientConfig,
|
package/src/core/error.test.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { getTestConfig, getTestLLClient, getTestClientConf } from '../test/test_
|
|
|
3
3
|
import { TxAPI_Open_Request_WritableTx } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api';
|
|
4
4
|
import { request } from 'undici';
|
|
5
5
|
import * as tp from 'node:timers/promises';
|
|
6
|
+
import { test, expect } from '@jest/globals';
|
|
6
7
|
|
|
7
8
|
import { UnauthenticatedError } from './errors';
|
|
8
9
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getTestLLClient } from '../test/test_config';
|
|
2
2
|
import { TxAPI_Open_Request_WritableTx } from '../proto/github.com/milaboratory/pl/plapi/plapiproto/api';
|
|
3
3
|
import { createLocalResourceId } from './types';
|
|
4
|
+
import { test, expect } from '@jest/globals';
|
|
4
5
|
|
|
5
6
|
import { isTimeoutOrCancelError } from './errors';
|
|
6
7
|
import { Aborted } from '@milaboratories/ts-helpers';
|
|
@@ -3,6 +3,7 @@ import { StructTestResource, ValueTestResource } from '../helpers/pl';
|
|
|
3
3
|
import { field, toGlobalFieldId, toGlobalResourceId } from './transaction';
|
|
4
4
|
import { RecoverablePlError } from './errors';
|
|
5
5
|
import * as tp from 'node:timers/promises';
|
|
6
|
+
import { test, expect } from '@jest/globals';
|
|
6
7
|
|
|
7
8
|
test('get field', async () => {
|
|
8
9
|
await withTempRoot(async (pl) => {
|
package/src/core/types.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { UnauthenticatedPlClient } from './unauth_client';
|
|
2
2
|
import { getTestConfig } from '../test/test_config';
|
|
3
3
|
import { UnauthenticatedError } from './errors';
|
|
4
|
+
import { test, expect } from '@jest/globals';
|
|
4
5
|
|
|
5
6
|
test('ping test', async () => {
|
|
6
7
|
const client = new UnauthenticatedPlClient(getTestConfig().address);
|