@quenty/influxdbclient 7.19.0-canary.544.de8fcee.0 → 7.19.1-canary.545.2374fb2.0

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/CHANGELOG.md CHANGED
@@ -3,7 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- # [7.19.0-canary.544.de8fcee.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/influxdbclient@7.18.1...@quenty/influxdbclient@7.19.0-canary.544.de8fcee.0) (2025-04-01)
6
+ ## [7.19.1-canary.545.2374fb2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/influxdbclient@7.19.0...@quenty/influxdbclient@7.19.1-canary.545.2374fb2.0) (2025-04-05)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Add types to packages ([2374fb2](https://github.com/Quenty/NevermoreEngine/commit/2374fb2b043cfbe0e9b507b3316eec46a4e353a0))
12
+
13
+
14
+
15
+
16
+
17
+ # [7.19.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/influxdbclient@7.18.2...@quenty/influxdbclient@7.19.0) (2025-04-02)
7
18
 
8
19
 
9
20
  ### Bug Fixes
@@ -15,6 +26,14 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
15
26
 
16
27
 
17
28
 
29
+ ## [7.18.2](https://github.com/Quenty/NevermoreEngine/compare/@quenty/influxdbclient@7.18.1...@quenty/influxdbclient@7.18.2) (2025-03-31)
30
+
31
+ **Note:** Version bump only for package @quenty/influxdbclient
32
+
33
+
34
+
35
+
36
+
18
37
  ## [7.18.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/influxdbclient@7.18.0...@quenty/influxdbclient@7.18.1) (2025-03-21)
19
38
 
20
39
  **Note:** Version bump only for package @quenty/influxdbclient
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/influxdbclient",
3
- "version": "7.19.0-canary.544.de8fcee.0",
3
+ "version": "7.19.1-canary.545.2374fb2.0",
4
4
  "description": "Provides a Roblox Lua InfluxDB client",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -25,22 +25,22 @@
25
25
  "Quenty"
26
26
  ],
27
27
  "dependencies": {
28
- "@quenty/baseobject": "10.8.0",
29
- "@quenty/httppromise": "10.10.1",
30
- "@quenty/jsonutils": "10.10.1",
31
- "@quenty/loader": "10.8.0",
32
- "@quenty/maid": "3.4.0",
33
- "@quenty/math": "2.7.1",
34
- "@quenty/promise": "10.10.1",
35
- "@quenty/rx": "13.17.0-canary.544.de8fcee.0",
36
- "@quenty/servicebag": "11.11.1",
37
- "@quenty/signal": "7.10.0",
38
- "@quenty/string": "3.3.1",
39
- "@quenty/table": "3.7.1",
40
- "@quenty/valueobject": "13.17.0-canary.544.de8fcee.0"
28
+ "@quenty/baseobject": "10.8.1-canary.545.2374fb2.0",
29
+ "@quenty/httppromise": "10.10.2-canary.545.2374fb2.0",
30
+ "@quenty/jsonutils": "10.10.2-canary.545.2374fb2.0",
31
+ "@quenty/loader": "10.8.1-canary.545.2374fb2.0",
32
+ "@quenty/maid": "3.4.1-canary.545.2374fb2.0",
33
+ "@quenty/math": "2.7.2-canary.545.2374fb2.0",
34
+ "@quenty/promise": "10.10.2-canary.545.2374fb2.0",
35
+ "@quenty/rx": "13.17.1-canary.545.2374fb2.0",
36
+ "@quenty/servicebag": "11.11.2-canary.545.2374fb2.0",
37
+ "@quenty/signal": "7.10.1-canary.545.2374fb2.0",
38
+ "@quenty/string": "3.3.2-canary.545.2374fb2.0",
39
+ "@quenty/table": "3.7.2-canary.545.2374fb2.0",
40
+ "@quenty/valueobject": "13.17.1-canary.545.2374fb2.0"
41
41
  },
42
42
  "publishConfig": {
43
43
  "access": "public"
44
44
  },
45
- "gitHead": "de8fcee995fcdae464964357b4c770c03f4c7e03"
45
+ "gitHead": "2374fb2b043cfbe0e9b507b3316eec46a4e353a0"
46
46
  }
@@ -4,13 +4,30 @@
4
4
 
5
5
  local InfluxDBClientConfigUtils = {}
6
6
 
7
- function InfluxDBClientConfigUtils.isClientConfig(config)
7
+ export type InfluxDBClientConfig = {
8
+ url: string,
9
+ token: string | Secret,
10
+ }
11
+
12
+ --[=[
13
+ Checks if the given config is a valid InfluxDB client config
14
+
15
+ @param config any
16
+ @return boolean
17
+ ]=]
18
+ function InfluxDBClientConfigUtils.isClientConfig(config: any): boolean
8
19
  return type(config) == "table"
9
20
  and type(config.url) == "string"
10
21
  and (typeof(config.token) == "string" or typeof(config.token) == "Secret")
11
22
  end
12
23
 
13
- function InfluxDBClientConfigUtils.createClientConfig(config)
24
+ --[=[
25
+ Creates a new InfluxDB client config
26
+
27
+ @param config InfluxDBClientConfig
28
+ @return InfluxDBClientConfig
29
+ ]=]
30
+ function InfluxDBClientConfigUtils.createClientConfig(config: InfluxDBClientConfig): InfluxDBClientConfig
14
31
  assert(InfluxDBClientConfigUtils.isClientConfig(config), "Bad config")
15
32
 
16
33
  return {
@@ -2,25 +2,26 @@
2
2
  @class InfluxDBPointSettings
3
3
  ]=]
4
4
 
5
- local require = require(script.Parent.loader).load(script)
6
-
7
5
  local InfluxDBPointSettings = {}
8
6
  InfluxDBPointSettings.ClassName = "InfluxDBPointSettings"
9
7
  InfluxDBPointSettings.__index = InfluxDBPointSettings
10
8
 
9
+ export type InfluxDBTags = { [string]: string }
10
+ export type ConvertTime = (number) -> number
11
+
11
12
  function InfluxDBPointSettings.new()
12
13
  local self = setmetatable({}, InfluxDBPointSettings)
13
14
 
14
15
  self._defaultTags = {}
15
- self._convertTime = nil
16
+ self._convertTime = nil :: ConvertTime?
16
17
 
17
18
  return self
18
19
  end
19
20
 
20
- function InfluxDBPointSettings:SetDefaultTags(tags)
21
+ function InfluxDBPointSettings:SetDefaultTags(tags: InfluxDBTags)
21
22
  assert(type(tags) == "table", "Bad tags")
22
23
 
23
- for key, value in pairs(tags) do
24
+ for key, value in tags do
24
25
  assert(type(value) == "string", "Bad value")
25
26
  assert(type(key) == "string", "Bad key")
26
27
  end
@@ -28,18 +29,17 @@ function InfluxDBPointSettings:SetDefaultTags(tags)
28
29
  self._defaultTags = tags
29
30
  end
30
31
 
31
-
32
- function InfluxDBPointSettings:GetDefaultTags()
32
+ function InfluxDBPointSettings:GetDefaultTags(): InfluxDBTags
33
33
  return self._defaultTags
34
34
  end
35
35
 
36
- function InfluxDBPointSettings:SetConvertTime(convertTime)
37
- assert(type(convertTime) == "function", "Bad convertTime")
36
+ function InfluxDBPointSettings:SetConvertTime(convertTime: ConvertTime?)
37
+ assert(type(convertTime) == "function" or convertTime == nil, "Bad convertTime")
38
38
 
39
39
  self._convertTime = convertTime
40
40
  end
41
41
 
42
- function InfluxDBPointSettings:GetConvertTime()
42
+ function InfluxDBPointSettings:GetConvertTime(): ConvertTime?
43
43
  return self._convertTime
44
44
  end
45
45
 
@@ -6,13 +6,19 @@ local require = require(script.Parent.loader).load(script)
6
6
 
7
7
  local Table = require("Table")
8
8
 
9
+ export type InfluxDBWriteOptions = {
10
+ batchSize: number,
11
+ maxBatchBytes: number,
12
+ flushIntervalSeconds: number,
13
+ }
14
+
9
15
  local InfluxDBWriteOptionUtils = {}
10
16
 
11
- function InfluxDBWriteOptionUtils.getDefaultOptions()
17
+ function InfluxDBWriteOptionUtils.getDefaultOptions(): InfluxDBWriteOptions
12
18
  return InfluxDBWriteOptionUtils.createWriteOptions({
13
- batchSize = 1000;
14
- maxBatchBytes = 50_000_000; -- default max batch size in the cloud
15
- flushIntervalSeconds = 60;
19
+ batchSize = 1000,
20
+ maxBatchBytes = 50_000_000, -- default max batch size in the cloud
21
+ flushIntervalSeconds = 60,
16
22
  -- maxRetries = 5;
17
23
  -- maxRetryTimeSeconds = 180;
18
24
  -- maxBufferLines = 32_000;
@@ -24,13 +30,13 @@ function InfluxDBWriteOptionUtils.getDefaultOptions()
24
30
  })
25
31
  end
26
32
 
27
- function InfluxDBWriteOptionUtils.createWriteOptions(options)
33
+ function InfluxDBWriteOptionUtils.createWriteOptions(options: InfluxDBWriteOptions): InfluxDBWriteOptions
28
34
  assert(InfluxDBWriteOptionUtils.isWriteOptions(options), "Bad options")
29
35
 
30
36
  return Table.readonly(options)
31
37
  end
32
38
 
33
- function InfluxDBWriteOptionUtils.isWriteOptions(options)
39
+ function InfluxDBWriteOptionUtils.isWriteOptions(options: any): boolean
34
40
  return type(options) == "table"
35
41
  and type(options.batchSize) == "number"
36
42
  and type(options.maxBatchBytes) == "number"
@@ -81,8 +81,8 @@ function InfluxDBClient:PromiseFlushAll()
81
81
  end
82
82
 
83
83
  local promises = {}
84
- for _, bucketList in pairs(self._writeApis) do
85
- for _, writeAPI in pairs(bucketList) do
84
+ for _, bucketList in self._writeApis do
85
+ for _, writeAPI in bucketList do
86
86
  table.insert(promises, writeAPI:PromiseFlush())
87
87
  end
88
88
  end
@@ -6,22 +6,27 @@ local require = require(script.Parent.loader).load(script)
6
6
 
7
7
  local JSONUtils = require("JSONUtils")
8
8
 
9
+ export type InfluxDBError = {
10
+ code: string,
11
+ message: string,
12
+ }
13
+
9
14
  local InfluxDBErrorUtils = {}
10
15
 
11
- function InfluxDBErrorUtils.tryParseErrorBody(body)
16
+ function InfluxDBErrorUtils.tryParseErrorBody(body: string): InfluxDBError?
12
17
  local ok, decoded, _err = JSONUtils.jsonDecode(body)
13
18
  if not ok then
14
19
  return nil
15
20
  end
16
21
 
17
22
  if InfluxDBErrorUtils.isInfluxDBError(decoded) then
18
- return decoded
23
+ return decoded :: any
19
24
  else
20
25
  return nil
21
26
  end
22
27
  end
23
28
 
24
- function InfluxDBErrorUtils.isInfluxDBError(data)
29
+ function InfluxDBErrorUtils.isInfluxDBError(data: any): boolean
25
30
  return type(data) == "table"
26
31
  and type(data.code) == "string"
27
32
  and type(data.message) == "string"
@@ -20,7 +20,7 @@ local InfluxDBWriteAPI = setmetatable({}, BaseObject)
20
20
  InfluxDBWriteAPI.ClassName = "InfluxDBWriteAPI"
21
21
  InfluxDBWriteAPI.__index = InfluxDBWriteAPI
22
22
 
23
- function InfluxDBWriteAPI.new(org, bucket, precision)
23
+ function InfluxDBWriteAPI.new(org: string, bucket: string, precision: string?)
24
24
  local self = setmetatable(BaseObject.new(), InfluxDBWriteAPI)
25
25
 
26
26
  assert(type(org) == "string", "Bad org")
@@ -53,13 +53,13 @@ function InfluxDBWriteAPI.new(org, bucket, precision)
53
53
  return self
54
54
  end
55
55
 
56
- function InfluxDBWriteAPI:SetPrintDebugWriteEnabled(printDebugEnabled)
56
+ function InfluxDBWriteAPI:SetPrintDebugWriteEnabled(printDebugEnabled: boolean)
57
57
  assert(type(printDebugEnabled) == "boolean", "Bad printDebugEnabled")
58
58
 
59
59
  self._printDebugWriteEnabled = printDebugEnabled
60
60
  end
61
61
 
62
- function InfluxDBWriteAPI:SetClientConfig(clientConfig)
62
+ function InfluxDBWriteAPI:SetClientConfig(clientConfig: InfluxDBClientConfigUtils.InfluxDBClientConfig)
63
63
  assert(InfluxDBClientConfigUtils.isClientConfig(clientConfig), "Bad clientConfig")
64
64
 
65
65
  self._clientConfig.Value = InfluxDBClientConfigUtils.createClientConfig(clientConfig)
@@ -73,7 +73,7 @@ function InfluxDBWriteAPI:SetConvertTime(convertTime)
73
73
  self._pointSettings:SetConvertTime(convertTime)
74
74
  end
75
75
 
76
- function InfluxDBWriteAPI:QueuePoint(point)
76
+ function InfluxDBWriteAPI:QueuePoint(point: InfluxDBPoint.InfluxDBPoint)
77
77
  assert(InfluxDBPoint.isInfluxDBPoint(point), "Bad point")
78
78
 
79
79
  local line = point:ToLineProtocol(self._pointSettings)
@@ -86,10 +86,10 @@ function InfluxDBWriteAPI:QueuePoint(point)
86
86
  end
87
87
  end
88
88
 
89
- function InfluxDBWriteAPI:QueuePoints(points)
89
+ function InfluxDBWriteAPI:QueuePoints(points: { InfluxDBPoint.InfluxDBPoint })
90
90
  assert(type(points) == "table", "Bad points")
91
91
 
92
- for _, point in pairs(points) do
92
+ for _, point in points do
93
93
  assert(InfluxDBPoint.isInfluxDBPoint(point), "Bad point")
94
94
 
95
95
  local line = point:ToLineProtocol(self._pointSettings)
@@ -103,7 +103,7 @@ function InfluxDBWriteAPI:QueuePoints(points)
103
103
  end
104
104
  end
105
105
 
106
- function InfluxDBWriteAPI:_promiseSendBatch(toSend)
106
+ function InfluxDBWriteAPI:_promiseSendBatch(toSend: { InfluxDBPoint.InfluxDBPoint }): Promise.Promise<()>
107
107
  assert(type(toSend) == "table", "Bad toSend")
108
108
 
109
109
  local clientConfig = self._clientConfig.Value
@@ -123,22 +123,23 @@ function InfluxDBWriteAPI:_promiseSendBatch(toSend)
123
123
 
124
124
  local body = table.concat(toSend, "\n")
125
125
  local request = {
126
- Method = "POST";
126
+ Method = "POST",
127
127
  Headers = {
128
- ["Content-Type"] = "application/json";
129
- ["Accept"] = "application/json";
130
- ["Authorization"] = authHeader;
131
- };
132
- Compress = Enum.HttpCompression.Gzip;
133
- Url = self:_getWriteUrl();
134
- Body = body;
128
+ ["Content-Type"] = "application/json",
129
+ ["Accept"] = "application/json",
130
+ ["Authorization"] = authHeader,
131
+ },
132
+ Compress = Enum.HttpCompression.Gzip,
133
+ Url = self:_getWriteUrl(),
134
+ Body = body,
135
135
  }
136
136
 
137
137
  if self._printDebugWriteEnabled then
138
138
  print(string.format("[InfluxDBWriteAPI._promiseSendBatch] - Sending data %s", body))
139
139
  end
140
140
 
141
- return self._maid:GivePromise(HttpPromise.request(request))
141
+ return self._maid
142
+ :GivePromise(HttpPromise.request(request))
142
143
  :Then(function(result)
143
144
  if result.Success then
144
145
  if self.Destroy then
@@ -159,32 +160,40 @@ function InfluxDBWriteAPI:_promiseSendBatch(toSend)
159
160
  local errorBody = InfluxDBErrorUtils.tryParseErrorBody(err.Body)
160
161
 
161
162
  if errorBody then
162
- local message = string.format("[InfluxDBWriteAPI:QueuePoint] - %d: %s - %s",
163
+ local message = string.format(
164
+ "[InfluxDBWriteAPI:QueuePoint] - %d: %s - %s",
163
165
  err.StatusCode,
164
166
  errorBody.code,
165
- errorBody.message)
167
+ errorBody.message
168
+ )
166
169
  warn(message)
167
170
 
168
171
  return Promise.rejected(errorBody)
169
172
  end
170
173
 
171
- warn(string.format("[InfluxDBWriteAPI:QueuePoint] - %d: %s - %s",
172
- err.StatusCode,
173
- err.StatusMessage,
174
- tostring(err.Body)))
175
-
176
- return Promise.rejected(string.format("[InfluxDBWriteAPI:QueuePoint] - %d: %s", err.StatusCode, err.StatusMessage))
174
+ warn(
175
+ string.format(
176
+ "[InfluxDBWriteAPI:QueuePoint] - %d: %s - %s",
177
+ err.StatusCode,
178
+ err.StatusMessage,
179
+ tostring(err.Body)
180
+ )
181
+ )
182
+
183
+ return Promise.rejected(
184
+ string.format("[InfluxDBWriteAPI:QueuePoint] - %d: %s", err.StatusCode, err.StatusMessage)
185
+ )
177
186
  else
178
187
  return Promise.rejected(err or "Request got cancelled")
179
188
  end
180
189
  end)
181
190
  end
182
191
 
183
- function InfluxDBWriteAPI:PromiseFlush()
192
+ function InfluxDBWriteAPI:PromiseFlush(): Promise.Promise<()>
184
193
  return self._writeBuffer:PromiseFlush()
185
194
  end
186
195
 
187
- function InfluxDBWriteAPI:_getWriteUrl()
196
+ function InfluxDBWriteAPI:_getWriteUrl(): string
188
197
  local config = self._clientConfig.Value
189
198
  local url = config.url
190
199
 
@@ -7,12 +7,15 @@ local require = require(script.Parent.loader).load(script)
7
7
  local BaseObject = require("BaseObject")
8
8
  local Promise = require("Promise")
9
9
  local Signal = require("Signal")
10
+ local _InfluxDBWriteOptionUtils = require("InfluxDBWriteOptionUtils")
10
11
 
11
12
  local InfluxDBWriteBuffer = setmetatable({}, BaseObject)
12
13
  InfluxDBWriteBuffer.ClassName = "InfluxDBWriteBuffer"
13
14
  InfluxDBWriteBuffer.__index = InfluxDBWriteBuffer
14
15
 
15
- function InfluxDBWriteBuffer.new(writeOptions, promiseHandleFlush)
16
+ export type InfluxDBWriteBuffer = typeof(setmetatable({}, InfluxDBWriteBuffer))
17
+
18
+ function InfluxDBWriteBuffer.new(writeOptions: _InfluxDBWriteOptionUtils.InfluxDBWriteOptions, promiseHandleFlush)
16
19
  local self = setmetatable(BaseObject.new(), InfluxDBWriteBuffer)
17
20
 
18
21
  self._writeOptions = assert(writeOptions, "Bad writeOptions")
@@ -24,11 +27,10 @@ function InfluxDBWriteBuffer.new(writeOptions, promiseHandleFlush)
24
27
 
25
28
  self._requestQueueNext = self._maid:Add(Signal.new())
26
29
 
27
-
28
30
  return self
29
31
  end
30
32
 
31
- function InfluxDBWriteBuffer:Add(entry)
33
+ function InfluxDBWriteBuffer:Add(entry: string)
32
34
  assert(type(entry) == "string", "Bad entry")
33
35
 
34
36
 
@@ -2,26 +2,28 @@
2
2
  @class InfluxDBEscapeUtils
3
3
  ]=]
4
4
 
5
- local require = require(script.Parent.loader).load(script)
6
-
7
5
  local InfluxDBEscapeUtils = {}
8
6
 
9
- local function gsubEscpae(str)
10
- return str:gsub('%%', '%%%%')
11
- :gsub('^%^', '%%^')
12
- :gsub('%$$', '%%$')
13
- :gsub('%(', '%%(')
14
- :gsub('%)', '%%)')
15
- :gsub('%.', '%%.')
16
- :gsub('%[', '%%[')
17
- :gsub('%]', '%%]')
18
- :gsub('%*', '%%*')
19
- :gsub('%+', '%%+')
20
- :gsub('%-', '%%-')
21
- :gsub('%?', '%%?')
7
+ local function gsubEscpae(str: string): string
8
+ return (
9
+ str:gsub("%%", "%%%%")
10
+ :gsub("^%^", "%%^")
11
+ :gsub("%$$", "%%$")
12
+ :gsub("%(", "%%(")
13
+ :gsub("%)", "%%)")
14
+ :gsub("%.", "%%.")
15
+ :gsub("%[", "%%[")
16
+ :gsub("%]", "%%]")
17
+ :gsub("%*", "%%*")
18
+ :gsub("%+", "%%+")
19
+ :gsub("%-", "%%-")
20
+ :gsub("%?", "%%?")
21
+ )
22
22
  end
23
23
 
24
- function InfluxDBEscapeUtils.createEscaper(subTable)
24
+ export type EscapeTable = { [string]: string }
25
+
26
+ function InfluxDBEscapeUtils.createEscaper(subTable: EscapeTable): (string) -> string
25
27
  assert(type(subTable) == "table", "Bad subTable")
26
28
 
27
29
  local function replace(char)
@@ -29,24 +31,24 @@ function InfluxDBEscapeUtils.createEscaper(subTable)
29
31
  end
30
32
 
31
33
  local gsubStr = "(["
32
- for char, _ in pairs(subTable) do
34
+ for char, _ in subTable do
33
35
  assert(#char == 1, "Bad char")
34
36
 
35
37
  gsubStr = gsubStr .. gsubEscpae(char)
36
38
  end
37
39
  gsubStr = gsubStr .. "])"
38
40
 
39
- return function(str)
40
- return string.gsub(str, gsubStr, replace)
41
+ return function(str: string): string
42
+ return (string.gsub(str, gsubStr, replace))
41
43
  end
42
44
  end
43
45
 
44
- function InfluxDBEscapeUtils.createQuotedEscaper(subTable)
46
+ function InfluxDBEscapeUtils.createQuotedEscaper(subTable: EscapeTable): (string) -> string
45
47
  assert(type(subTable) == "table", "Bad subTable")
46
48
 
47
49
  local escaper = InfluxDBEscapeUtils.createEscaper(subTable)
48
50
 
49
- return function(str)
51
+ return function(str: string)
50
52
  return string.format("\"%s\"", escaper(str))
51
53
  end
52
54
  end
@@ -13,7 +13,9 @@ local InfluxDBPoint = {}
13
13
  InfluxDBPoint.ClassName = "InfluxDBPoint"
14
14
  InfluxDBPoint.__index = InfluxDBPoint
15
15
 
16
- function InfluxDBPoint.new(measurementName)
16
+ export type InfluxDBPoint = typeof(setmetatable({}, InfluxDBPoint))
17
+
18
+ function InfluxDBPoint.new(measurementName: string?): InfluxDBPoint
17
19
  local self = setmetatable({}, InfluxDBPoint)
18
20
 
19
21
  assert(type(measurementName) == "string" or measurementName == nil, "Bad measurementName")
@@ -36,7 +38,7 @@ function InfluxDBPoint.fromTableData(data)
36
38
  if data.tags then
37
39
  assert(type(data.tags) == "table", "Bad data.tags")
38
40
 
39
- for tagKey, tagValue in pairs(data.tags) do
41
+ for tagKey, tagValue in data.tags do
40
42
  assert(type(tagKey) == "string", "Bad tagKey")
41
43
  assert(type(tagValue) == "string", "Bad tagValue")
42
44
  end
@@ -46,7 +48,7 @@ function InfluxDBPoint.fromTableData(data)
46
48
  if data.fields then
47
49
  assert(type(data.fields) == "table", "Bad data.fields")
48
50
 
49
- for fieldKey, fieldValue in pairs(data.fields) do
51
+ for fieldKey, fieldValue in data.fields do
50
52
  assert(type(fieldKey) == "string", "Bad fieldKey")
51
53
  assert(type(fieldValue) == "string", "Bad fieldValue")
52
54
 
@@ -59,12 +61,11 @@ function InfluxDBPoint.fromTableData(data)
59
61
  return copy
60
62
  end
61
63
 
62
- function InfluxDBPoint.isInfluxDBPoint(point)
63
- return type(point) == "table"
64
- and getmetatable(point) == InfluxDBPoint
64
+ function InfluxDBPoint.isInfluxDBPoint(point: any): boolean
65
+ return type(point) == "table" and getmetatable(point) == InfluxDBPoint
65
66
  end
66
67
 
67
- function InfluxDBPoint:SetMeasurementName(name)
68
+ function InfluxDBPoint:SetMeasurementName(name: string)
68
69
  assert(type(name) == "string" or name == nil, "Bad name")
69
70
 
70
71
  self._measurementName = name
@@ -76,10 +77,10 @@ end
76
77
 
77
78
  function InfluxDBPoint:ToTableData()
78
79
  return {
79
- measurementName = self._measurementName;
80
- timestamp = self._timestamp;
81
- tags = table.clone(self._tags);
82
- fields = table.clone(self._fields);
80
+ measurementName = self._measurementName,
81
+ timestamp = self._timestamp,
82
+ tags = table.clone(self._tags),
83
+ fields = table.clone(self._fields),
83
84
  }
84
85
  end
85
86
 
@@ -88,7 +89,7 @@ end
88
89
 
89
90
  @param timestamp DateTime | nil
90
91
  ]=]
91
- function InfluxDBPoint:SetTimestamp(timestamp)
92
+ function InfluxDBPoint:SetTimestamp(timestamp: DateTime?)
92
93
  assert(typeof(timestamp) == "DateTime" or timestamp == nil, "Bad timestamp")
93
94
 
94
95
  self._timestamp = timestamp
@@ -100,7 +101,7 @@ end
100
101
  @param tagKey string
101
102
  @param tagValue string
102
103
  ]=]
103
- function InfluxDBPoint:AddTag(tagKey, tagValue)
104
+ function InfluxDBPoint:AddTag(tagKey: string, tagValue: string)
104
105
  assert(type(tagKey) == "string", "Bad tagKey")
105
106
  assert(type(tagValue) == "string", "Bad tagValue")
106
107
 
@@ -113,18 +114,16 @@ end
113
114
  @param fieldName string
114
115
  @param value number
115
116
  ]=]
116
- function InfluxDBPoint:AddIntField(fieldName, value)
117
+ function InfluxDBPoint:AddIntField(fieldName: string, value: number)
117
118
  assert(type(fieldName) == "string", "Bad fieldName")
118
119
  assert(type(value) == "number", "Bad value")
119
120
 
120
- if Math.isNaN(value)
121
- or value <= -9223372036854776e3
122
- or value >= 9223372036854776e3 then
123
- error(string.format("invalid integer value for field '%s': %s", fieldName, value))
121
+ if Math.isNaN(value) or value <= -9223372036854776e3 or value >= 9223372036854776e3 then
122
+ error(string.format("invalid integer value for field '%s': %d", fieldName, value))
124
123
  end
125
124
 
126
125
  if not Math.isFinite(value) then
127
- error(string.format("invalid integer value for field '%s': %s", fieldName, value))
126
+ error(string.format("invalid integer value for field '%s': %d", fieldName, value))
128
127
  end
129
128
 
130
129
  self._fields[fieldName] = string.format("%di", value)
@@ -136,18 +135,16 @@ end
136
135
  @param fieldName string
137
136
  @param value number
138
137
  ]=]
139
- function InfluxDBPoint:AddUintField(fieldName, value)
138
+ function InfluxDBPoint:AddUintField(fieldName: string, value: number)
140
139
  assert(type(fieldName) == "string", "Bad fieldName")
141
140
  assert(type(value) == "number", "Bad value")
142
141
 
143
- if Math.isNaN(value)
144
- or value < 0
145
- or value >= 9007199254740991 then
146
- error(string.format("invalid uint value for field '%s': %s", fieldName, value))
142
+ if Math.isNaN(value) or value < 0 or value >= 9007199254740991 then
143
+ error(string.format("invalid uint value for field '%s': %d", fieldName, value))
147
144
  end
148
145
 
149
146
  if not Math.isFinite(value) then
150
- error(string.format("invalid uint value for field '%s': %s", fieldName, value))
147
+ error(string.format("invalid uint value for field '%s': %d", fieldName, value))
151
148
  end
152
149
 
153
150
  -- TODO: Support larger uint sizes
@@ -160,12 +157,12 @@ end
160
157
  @param fieldName string
161
158
  @param value number
162
159
  ]=]
163
- function InfluxDBPoint:AddFloatField(fieldName, value)
160
+ function InfluxDBPoint:AddFloatField(fieldName: string, value: number)
164
161
  assert(type(fieldName) == "string", "Bad fieldName")
165
162
  assert(type(value) == "number", "Bad value")
166
163
 
167
164
  if not Math.isFinite(value) then
168
- error(string.format("invalid float value for field '%s': %s", fieldName, value))
165
+ error(string.format("invalid float value for field '%s': %d", fieldName, value))
169
166
  end
170
167
 
171
168
  self._fields[fieldName] = tostring(value)
@@ -206,7 +203,7 @@ function InfluxDBPoint:ToLineProtocol(pointSettings)
206
203
  table.sort(fieldKeys)
207
204
 
208
205
  local fields = {}
209
- for _, key in pairs(fieldKeys) do
206
+ for _, key in fieldKeys do
210
207
  local value = self._fields[key]
211
208
  table.insert(fields, InfluxDBEscapeUtils.tag(key) .. "=" .. value)
212
209
  end
@@ -222,14 +219,14 @@ function InfluxDBPoint:ToLineProtocol(pointSettings)
222
219
  local defaultTags = pointSettings:GetDefaultTags()
223
220
  if next(defaultTags) or next(self._tags) then
224
221
  local tagKeysSet = table.clone(self._tags)
225
- for key, value in pairs(defaultTags) do
222
+ for key, value in defaultTags do
226
223
  tagKeysSet[key] = value
227
224
  end
228
225
  local tagKeys = Set.toList(tagKeysSet)
229
226
  table.sort(tagKeys)
230
227
 
231
228
  tags = {}
232
- for _, key in pairs(tagKeys) do
229
+ for _, key in tagKeys do
233
230
  local value = self._tags[key] or defaultTags[key]
234
231
  table.insert(tags, InfluxDBEscapeUtils.tag(key) .. "=" .. InfluxDBEscapeUtils.tag(value))
235
232
  end