@quenty/influxdbclient 7.19.3-canary.550.afa1b3b.0 → 7.19.4-canary.11a5dcf.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,23 @@
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.3-canary.550.afa1b3b.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/influxdbclient@7.19.2...@quenty/influxdbclient@7.19.3-canary.550.afa1b3b.0) (2025-04-10)
6
+ ## [7.19.4-canary.11a5dcf.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/influxdbclient@7.19.3...@quenty/influxdbclient@7.19.4-canary.11a5dcf.0) (2025-05-10)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Additional type checking updates ([05ba29a](https://github.com/Quenty/NevermoreEngine/commit/05ba29a03efc9f3feed74b34f1d9dfb237496214))
12
+
13
+
14
+ ### Features
15
+
16
+ * Add even more types ([b31717d](https://github.com/Quenty/NevermoreEngine/commit/b31717d8c9f7620c457f5018a2affa760a65334a))
17
+
18
+
19
+
20
+
21
+
22
+ ## [7.19.3](https://github.com/Quenty/NevermoreEngine/compare/@quenty/influxdbclient@7.19.2...@quenty/influxdbclient@7.19.3) (2025-04-10)
7
23
 
8
24
  **Note:** Version bump only for package @quenty/influxdbclient
9
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/influxdbclient",
3
- "version": "7.19.3-canary.550.afa1b3b.0",
3
+ "version": "7.19.4-canary.11a5dcf.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.3-canary.550.afa1b3b.0",
29
- "@quenty/httppromise": "10.10.4-canary.550.afa1b3b.0",
30
- "@quenty/jsonutils": "10.10.4-canary.550.afa1b3b.0",
31
- "@quenty/loader": "10.8.3-canary.550.afa1b3b.0",
32
- "@quenty/maid": "3.4.3-canary.550.afa1b3b.0",
28
+ "@quenty/baseobject": "10.8.4-canary.11a5dcf.0",
29
+ "@quenty/httppromise": "10.10.5-canary.11a5dcf.0",
30
+ "@quenty/jsonutils": "10.10.5-canary.11a5dcf.0",
31
+ "@quenty/loader": "10.8.4-canary.11a5dcf.0",
32
+ "@quenty/maid": "3.4.4-canary.11a5dcf.0",
33
33
  "@quenty/math": "2.7.3",
34
- "@quenty/promise": "10.10.4-canary.550.afa1b3b.0",
35
- "@quenty/rx": "13.17.3-canary.550.afa1b3b.0",
36
- "@quenty/servicebag": "11.11.4-canary.550.afa1b3b.0",
37
- "@quenty/signal": "7.10.3-canary.550.afa1b3b.0",
34
+ "@quenty/promise": "10.10.5-canary.11a5dcf.0",
35
+ "@quenty/rx": "13.17.4-canary.11a5dcf.0",
36
+ "@quenty/servicebag": "11.11.5-canary.11a5dcf.0",
37
+ "@quenty/signal": "7.10.4-canary.11a5dcf.0",
38
38
  "@quenty/string": "3.3.3",
39
- "@quenty/table": "3.7.4-canary.550.afa1b3b.0",
40
- "@quenty/valueobject": "13.17.3-canary.550.afa1b3b.0"
39
+ "@quenty/table": "3.7.5-canary.11a5dcf.0",
40
+ "@quenty/valueobject": "13.17.4-canary.11a5dcf.0"
41
41
  },
42
42
  "publishConfig": {
43
43
  "access": "public"
44
44
  },
45
- "gitHead": "afa1b3b99b862698c3ab46009497bd507150867c"
45
+ "gitHead": "11a5dcf7d4c7a0bfbf3337e97d30e8346ea09d3f"
46
46
  }
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  @class InfluxDBClientConfigUtils
3
4
  ]=]
@@ -31,9 +32,9 @@ function InfluxDBClientConfigUtils.createClientConfig(config: InfluxDBClientConf
31
32
  assert(InfluxDBClientConfigUtils.isClientConfig(config), "Bad config")
32
33
 
33
34
  return {
34
- url = config.url;
35
- token = config.token;
35
+ url = config.url,
36
+ token = config.token,
36
37
  }
37
38
  end
38
39
 
39
- return InfluxDBClientConfigUtils
40
+ return InfluxDBClientConfigUtils
@@ -1,4 +1,7 @@
1
+ --!strict
1
2
  --[=[
3
+ Holds settings for the InfluxDB point API
4
+
2
5
  @class InfluxDBPointSettings
3
6
  ]=]
4
7
 
@@ -7,10 +10,23 @@ InfluxDBPointSettings.ClassName = "InfluxDBPointSettings"
7
10
  InfluxDBPointSettings.__index = InfluxDBPointSettings
8
11
 
9
12
  export type InfluxDBTags = { [string]: string }
10
- export type ConvertTime = (number) -> number
13
+ export type ConvertTime = ((DateTime | number | string)?) -> number
14
+
15
+ export type InfluxDBPointSettings = typeof(setmetatable(
16
+ {} :: {
17
+ _defaultTags: InfluxDBTags,
18
+ _convertTime: ConvertTime?,
19
+ },
20
+ {} :: typeof({ __index = InfluxDBPointSettings })
21
+ ))
11
22
 
12
- function InfluxDBPointSettings.new()
13
- local self = setmetatable({}, InfluxDBPointSettings)
23
+ --[=[
24
+ Creates a new InfluxDB point settings
25
+
26
+ @return InfluxDBPointSettings
27
+ ]=]
28
+ function InfluxDBPointSettings.new(): InfluxDBPointSettings
29
+ local self: InfluxDBPointSettings = setmetatable({} :: any, InfluxDBPointSettings)
14
30
 
15
31
  self._defaultTags = {}
16
32
  self._convertTime = nil :: ConvertTime?
@@ -18,7 +34,12 @@ function InfluxDBPointSettings.new()
18
34
  return self
19
35
  end
20
36
 
21
- function InfluxDBPointSettings:SetDefaultTags(tags: InfluxDBTags)
37
+ --[=[
38
+ Sets the default tags for the InfluxDB point settings
39
+
40
+ @param tags InfluxDBTags
41
+ ]=]
42
+ function InfluxDBPointSettings.SetDefaultTags(self: InfluxDBPointSettings, tags: InfluxDBTags): ()
22
43
  assert(type(tags) == "table", "Bad tags")
23
44
 
24
45
  for key, value in tags do
@@ -29,19 +50,33 @@ function InfluxDBPointSettings:SetDefaultTags(tags: InfluxDBTags)
29
50
  self._defaultTags = tags
30
51
  end
31
52
 
32
- function InfluxDBPointSettings:GetDefaultTags(): InfluxDBTags
53
+ --[=[
54
+ Gets the default tags for the InfluxDB point settings
55
+
56
+ @return InfluxDBTags
57
+ ]=]
58
+ function InfluxDBPointSettings.GetDefaultTags(self: InfluxDBPointSettings): InfluxDBTags
33
59
  return self._defaultTags
34
60
  end
35
61
 
36
- function InfluxDBPointSettings:SetConvertTime(convertTime: ConvertTime?)
62
+ --[=[
63
+ Sets the conversion time function for the InfluxDB point settings
64
+
65
+ @param convertTime (number) -> number
66
+ ]=]
67
+ function InfluxDBPointSettings.SetConvertTime(self: InfluxDBPointSettings, convertTime: ConvertTime?)
37
68
  assert(type(convertTime) == "function" or convertTime == nil, "Bad convertTime")
38
69
 
39
70
  self._convertTime = convertTime
40
71
  end
41
72
 
42
- function InfluxDBPointSettings:GetConvertTime(): ConvertTime?
73
+ --[=[
74
+ Gets the conversion time function for the InfluxDB point settings
75
+
76
+ @return (number) -> number
77
+ ]=]
78
+ function InfluxDBPointSettings.GetConvertTime(self: InfluxDBPointSettings): ConvertTime?
43
79
  return self._convertTime
44
80
  end
45
81
 
46
-
47
- return InfluxDBPointSettings
82
+ return InfluxDBPointSettings
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  @class InfluxDBWriteOptionUtils
3
4
  ]=]
@@ -41,14 +42,14 @@ function InfluxDBWriteOptionUtils.isWriteOptions(options: any): boolean
41
42
  and type(options.batchSize) == "number"
42
43
  and type(options.maxBatchBytes) == "number"
43
44
  and type(options.flushIntervalSeconds) == "number"
44
- -- and type(options.maxRetries) == "number"
45
- -- and type(options.maxRetryTimeSeconds) == "number"
46
- -- and type(options.maxBufferLines) == "number"
47
- -- and type(options.retryJitterSeconds) == "number"
48
- -- and type(options.minRetryDelaySeconds) == "number"
49
- -- and type(options.maxRetryDelaySeconds) == "number"
50
- -- and type(options.exponentialBase) == "number"
51
- -- and type(options.randomRetry) == "boolean"
45
+ -- and type(options.maxRetries) == "number"
46
+ -- and type(options.maxRetryTimeSeconds) == "number"
47
+ -- and type(options.maxBufferLines) == "number"
48
+ -- and type(options.retryJitterSeconds) == "number"
49
+ -- and type(options.minRetryDelaySeconds) == "number"
50
+ -- and type(options.maxRetryDelaySeconds) == "number"
51
+ -- and type(options.exponentialBase) == "number"
52
+ -- and type(options.randomRetry) == "boolean"
52
53
  end
53
54
 
54
- return InfluxDBWriteOptionUtils
55
+ return InfluxDBWriteOptionUtils
@@ -1,4 +1,8 @@
1
+ --!strict
1
2
  --[=[
3
+ Client to write InfluxDB points to the server.
4
+
5
+ @server
2
6
  @class InfluxDBClient
3
7
  ]=]
4
8
 
@@ -7,16 +11,32 @@ local require = require(script.Parent.loader).load(script)
7
11
  local BaseObject = require("BaseObject")
8
12
  local InfluxDBClientConfigUtils = require("InfluxDBClientConfigUtils")
9
13
  local InfluxDBWriteAPI = require("InfluxDBWriteAPI")
10
- local ValueObject = require("ValueObject")
11
14
  local Maid = require("Maid")
15
+ local Promise = require("Promise")
12
16
  local PromiseUtils = require("PromiseUtils")
17
+ local ValueObject = require("ValueObject")
13
18
 
14
19
  local InfluxDBClient = setmetatable({}, BaseObject)
15
20
  InfluxDBClient.ClassName = "InfluxDBClient"
16
21
  InfluxDBClient.__index = InfluxDBClient
17
22
 
18
- function InfluxDBClient.new(clientConfig)
19
- local self = setmetatable(BaseObject.new(), InfluxDBClient)
23
+ export type InfluxDBClient = typeof(setmetatable(
24
+ {} :: {
25
+ _clientConfig: ValueObject.ValueObject<InfluxDBClientConfigUtils.InfluxDBClientConfig>,
26
+ _writeApis: { [string]: { [string]: InfluxDBWriteAPI.InfluxDBWriteAPI } },
27
+ _flushAllPromises: Promise.Promise<()>,
28
+ },
29
+ {} :: typeof({ __index = InfluxDBClient })
30
+ )) & BaseObject.BaseObject
31
+
32
+ --[=[
33
+ Creates a new InfluxDB client
34
+
35
+ @param clientConfig InfluxDBClientConfig?
36
+ @return InfluxDBClient
37
+ ]=]
38
+ function InfluxDBClient.new(clientConfig: InfluxDBClientConfigUtils.InfluxDBClientConfig?): InfluxDBClient
39
+ local self: InfluxDBClient = setmetatable(BaseObject.new() :: any, InfluxDBClient)
20
40
 
21
41
  self._clientConfig = self._maid:Add(ValueObject.new(nil))
22
42
 
@@ -29,13 +49,26 @@ function InfluxDBClient.new(clientConfig)
29
49
  return self
30
50
  end
31
51
 
32
- function InfluxDBClient:SetClientConfig(clientConfig)
52
+ --[=[
53
+ Sets the client config for this client
54
+
55
+ @param clientConfig InfluxDBClientConfig
56
+ ]=]
57
+ function InfluxDBClient.SetClientConfig(
58
+ self: InfluxDBClient,
59
+ clientConfig: InfluxDBClientConfigUtils.InfluxDBClientConfig
60
+ )
33
61
  assert(InfluxDBClientConfigUtils.isClientConfig(clientConfig), "Bad clientConfig")
34
62
 
35
63
  self._clientConfig.Value = InfluxDBClientConfigUtils.createClientConfig(clientConfig)
36
64
  end
37
65
 
38
- function InfluxDBClient:GetWriteAPI(org, bucket, precision)
66
+ function InfluxDBClient.GetWriteAPI(
67
+ self: InfluxDBClient,
68
+ org: string,
69
+ bucket: string,
70
+ precision: string?
71
+ ): InfluxDBWriteAPI.InfluxDBWriteAPI
39
72
  assert(self._clientConfig, "No self._clientConfig")
40
73
  assert(type(org) == "string", "Bad org")
41
74
  assert(type(bucket) == "string", "Bad bucket")
@@ -75,20 +108,25 @@ function InfluxDBClient:GetWriteAPI(org, bucket, precision)
75
108
  return writeAPI
76
109
  end
77
110
 
78
- function InfluxDBClient:PromiseFlushAll()
111
+ --[=[
112
+ Flushes all write APIs. Returns a promise that resolves when all write APIs are flushed for all buckets.
113
+
114
+ @return Promise<()>
115
+ ]=]
116
+ function InfluxDBClient.PromiseFlushAll(self: InfluxDBClient): Promise.Promise<()>
79
117
  if self._flushAllPromises and self._flushAllPromises:IsPending() then
80
118
  return self._flushAllPromises
81
119
  end
82
120
 
83
121
  local promises = {}
84
122
  for _, bucketList in self._writeApis do
85
- for _, writeAPI in bucketList do
123
+ for _, writeAPI: any in bucketList do
86
124
  table.insert(promises, writeAPI:PromiseFlush())
87
125
  end
88
126
  end
89
127
 
90
128
  self._flushAllPromises = PromiseUtils.all(promises)
91
- return self._flushAllPromises
129
+ return self._flushAllPromises :: any
92
130
  end
93
131
 
94
- return InfluxDBClient
132
+ return InfluxDBClient
@@ -2,7 +2,8 @@
2
2
  @class InfluxDBClient.story
3
3
  ]]
4
4
 
5
- local require = require(game:GetService("ServerScriptService"):FindFirstChild("LoaderUtils", true).Parent).bootstrapStory(script)
5
+ local require =
6
+ require(game:GetService("ServerScriptService"):FindFirstChild("LoaderUtils", true).Parent).bootstrapStory(script)
6
7
 
7
8
  local InfluxDBClient = require("InfluxDBClient")
8
9
  local InfluxDBClientConfigUtils = require("InfluxDBClientConfigUtils")
@@ -13,8 +14,8 @@ return function(_target)
13
14
  local maid = Maid.new()
14
15
 
15
16
  local config = InfluxDBClientConfigUtils.createClientConfig({
16
- url = "https://ingest.robloxanalytics.com/";
17
- token = "test-api-key";
17
+ url = "https://ingest.robloxanalytics.com/",
18
+ token = "test-api-key",
18
19
  })
19
20
 
20
21
  local influxDBClient = InfluxDBClient.new(config)
@@ -33,7 +34,7 @@ return function(_target)
33
34
  point:AddTag("place_id", tostring(game.PlaceId))
34
35
  point:AddStringField("username", "Quenty")
35
36
  point:AddIntField("userid", 4397833)
36
- point:AddFloatField("fps", 30 + math.random()*30)
37
+ point:AddFloatField("fps", 30 + math.random() * 30)
37
38
  point:AddBooleanField("is_alive", true)
38
39
  point:AddBooleanField("is_silent", false)
39
40
 
@@ -48,4 +49,4 @@ return function(_target)
48
49
  return function()
49
50
  maid:DoCleaning()
50
51
  end
51
- end
52
+ end
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  @class InfluxDBErrorUtils
3
4
  ]=]
@@ -6,6 +7,13 @@ local require = require(script.Parent.loader).load(script)
6
7
 
7
8
  local JSONUtils = require("JSONUtils")
8
9
 
10
+ --[=[
11
+ InfluxDB error type.
12
+ @interface InfluxDBError
13
+ .code string
14
+ .message string
15
+ @within InfluxDBErrorUtils
16
+ ]=]
9
17
  export type InfluxDBError = {
10
18
  code: string,
11
19
  message: string,
@@ -13,6 +21,13 @@ export type InfluxDBError = {
13
21
 
14
22
  local InfluxDBErrorUtils = {}
15
23
 
24
+ --[=[
25
+ Tries to parse the error body from InfluxDB.
26
+ Returns nil if it fails to parse.
27
+
28
+ @param body string
29
+ @return InfluxDBError?
30
+ ]=]
16
31
  function InfluxDBErrorUtils.tryParseErrorBody(body: string): InfluxDBError?
17
32
  local ok, decoded, _err = JSONUtils.jsonDecode(body)
18
33
  if not ok then
@@ -26,10 +41,14 @@ function InfluxDBErrorUtils.tryParseErrorBody(body: string): InfluxDBError?
26
41
  end
27
42
  end
28
43
 
44
+ --[=[
45
+ Checks if the given data is an InfluxDB error.
46
+
47
+ @param data any
48
+ @return boolean
49
+ ]=]
29
50
  function InfluxDBErrorUtils.isInfluxDBError(data: any): boolean
30
- return type(data) == "table"
31
- and type(data.code) == "string"
32
- and type(data.message) == "string"
51
+ return type(data) == "table" and type(data.code) == "string" and type(data.message) == "string"
33
52
  end
34
53
 
35
- return InfluxDBErrorUtils
54
+ return InfluxDBErrorUtils
@@ -1,4 +1,8 @@
1
+ --!strict
1
2
  --[=[
3
+ InfluxDB API to write to the server.
4
+
5
+ @server
2
6
  @class InfluxDBWriteAPI
3
7
  ]=]
4
8
 
@@ -7,6 +11,7 @@ local require = require(script.Parent.loader).load(script)
7
11
  local BaseObject = require("BaseObject")
8
12
  local HttpPromise = require("HttpPromise")
9
13
  local InfluxDBClientConfigUtils = require("InfluxDBClientConfigUtils")
14
+ local InfluxDBErrorUtils = require("InfluxDBErrorUtils")
10
15
  local InfluxDBPoint = require("InfluxDBPoint")
11
16
  local InfluxDBPointSettings = require("InfluxDBPointSettings")
12
17
  local InfluxDBWriteBuffer = require("InfluxDBWriteBuffer")
@@ -14,14 +19,38 @@ local InfluxDBWriteOptionUtils = require("InfluxDBWriteOptionUtils")
14
19
  local Promise = require("Promise")
15
20
  local Signal = require("Signal")
16
21
  local ValueObject = require("ValueObject")
17
- local InfluxDBErrorUtils = require("InfluxDBErrorUtils")
18
22
 
19
23
  local InfluxDBWriteAPI = setmetatable({}, BaseObject)
20
24
  InfluxDBWriteAPI.ClassName = "InfluxDBWriteAPI"
21
25
  InfluxDBWriteAPI.__index = InfluxDBWriteAPI
22
26
 
23
- function InfluxDBWriteAPI.new(org: string, bucket: string, precision: string?)
24
- local self = setmetatable(BaseObject.new(), InfluxDBWriteAPI)
27
+ export type InfluxDBWriteAPI = typeof(setmetatable(
28
+ {} :: {
29
+ RequestFinished: Signal.Signal<(any)>,
30
+ Destroying: Signal.Signal<()>,
31
+
32
+ _clientConfig: ValueObject.ValueObject<InfluxDBClientConfigUtils.InfluxDBClientConfig>,
33
+ _printDebugWriteEnabled: boolean,
34
+ _org: string,
35
+ _bucket: string,
36
+ _precision: string,
37
+ _pointSettings: InfluxDBPointSettings.InfluxDBPointSettings,
38
+ _writeOptions: InfluxDBWriteOptionUtils.InfluxDBWriteOptions,
39
+ _writeBuffer: InfluxDBWriteBuffer.InfluxDBWriteBuffer,
40
+ },
41
+ {} :: typeof({ __index = InfluxDBWriteAPI })
42
+ )) & BaseObject.BaseObject
43
+
44
+ --[=[
45
+ Creates a new InfluxDB write API. Retrieve this from the [InfluxDBClient].
46
+
47
+ @param org string
48
+ @param bucket string
49
+ @param precision string?
50
+ @return InfluxDBWriteAPI
51
+ ]=]
52
+ function InfluxDBWriteAPI.new(org: string, bucket: string, precision: string?): InfluxDBWriteAPI
53
+ local self: InfluxDBWriteAPI = setmetatable(BaseObject.new() :: any, InfluxDBWriteAPI)
25
54
 
26
55
  assert(type(org) == "string", "Bad org")
27
56
  assert(type(bucket) == "string", "Bad bucket")
@@ -53,27 +82,45 @@ function InfluxDBWriteAPI.new(org: string, bucket: string, precision: string?)
53
82
  return self
54
83
  end
55
84
 
56
- function InfluxDBWriteAPI:SetPrintDebugWriteEnabled(printDebugEnabled: boolean)
85
+ function InfluxDBWriteAPI.SetPrintDebugWriteEnabled(self: InfluxDBWriteAPI, printDebugEnabled: boolean): ()
57
86
  assert(type(printDebugEnabled) == "boolean", "Bad printDebugEnabled")
58
87
 
59
88
  self._printDebugWriteEnabled = printDebugEnabled
60
89
  end
61
90
 
62
- function InfluxDBWriteAPI:SetClientConfig(clientConfig: InfluxDBClientConfigUtils.InfluxDBClientConfig)
91
+ function InfluxDBWriteAPI.SetClientConfig(
92
+ self: InfluxDBWriteAPI,
93
+ clientConfig: InfluxDBClientConfigUtils.InfluxDBClientConfig
94
+ ): ()
63
95
  assert(InfluxDBClientConfigUtils.isClientConfig(clientConfig), "Bad clientConfig")
64
96
 
65
97
  self._clientConfig.Value = InfluxDBClientConfigUtils.createClientConfig(clientConfig)
66
98
  end
67
99
 
68
- function InfluxDBWriteAPI:SetDefaultTags(tags)
100
+ --[=[
101
+ Sets the default tags to write with each point.
102
+
103
+ @param tags InfluxDBTags
104
+ ]=]
105
+ function InfluxDBWriteAPI.SetDefaultTags(self: InfluxDBWriteAPI, tags: InfluxDBPointSettings.InfluxDBTags): ()
69
106
  self._pointSettings:SetDefaultTags(tags)
70
107
  end
71
108
 
72
- function InfluxDBWriteAPI:SetConvertTime(convertTime)
109
+ --[=[
110
+ Sets the conversion time
111
+
112
+ @param convertTime (number) -> number
113
+ ]=]
114
+ function InfluxDBWriteAPI.SetConvertTime(self: InfluxDBWriteAPI, convertTime: InfluxDBPointSettings.ConvertTime?): ()
73
115
  self._pointSettings:SetConvertTime(convertTime)
74
116
  end
75
117
 
76
- function InfluxDBWriteAPI:QueuePoint(point: InfluxDBPoint.InfluxDBPoint)
118
+ --[=[
119
+ Queues a new influx DB point to send to the server.
120
+
121
+ @param point InfluxDBPoint
122
+ ]=]
123
+ function InfluxDBWriteAPI.QueuePoint(self: InfluxDBWriteAPI, point: InfluxDBPoint.InfluxDBPoint): ()
77
124
  assert(InfluxDBPoint.isInfluxDBPoint(point), "Bad point")
78
125
 
79
126
  local line = point:ToLineProtocol(self._pointSettings)
@@ -82,11 +129,16 @@ function InfluxDBWriteAPI:QueuePoint(point: InfluxDBPoint.InfluxDBPoint)
82
129
  end
83
130
 
84
131
  if self._printDebugWriteEnabled then
85
- print(string.format("[InfluxDBWriteAPI.QueuePoint] - Queueing '%s'", line))
132
+ print(string.format("[InfluxDBWriteAPI.QueuePoint] - Queueing '%s'", line or "nil"))
86
133
  end
87
134
  end
88
135
 
89
- function InfluxDBWriteAPI:QueuePoints(points: { InfluxDBPoint.InfluxDBPoint })
136
+ --[=[
137
+ Queues a new list of influx DB points to send to the server.
138
+
139
+ @param points { InfluxDBPoint }
140
+ ]=]
141
+ function InfluxDBWriteAPI.QueuePoints(self: InfluxDBWriteAPI, points: { InfluxDBPoint.InfluxDBPoint }): ()
90
142
  assert(type(points) == "table", "Bad points")
91
143
 
92
144
  for _, point in points do
@@ -98,12 +150,12 @@ function InfluxDBWriteAPI:QueuePoints(points: { InfluxDBPoint.InfluxDBPoint })
98
150
  end
99
151
 
100
152
  if self._printDebugWriteEnabled then
101
- print(string.format("[InfluxDBWriteAPI.QueuePoints] - Queueing '%s'", line))
153
+ print(string.format("[InfluxDBWriteAPI.QueuePoints] - Queueing '%s'", line or "nil"))
102
154
  end
103
155
  end
104
156
  end
105
157
 
106
- function InfluxDBWriteAPI:_promiseSendBatch(toSend: { InfluxDBPoint.InfluxDBPoint }): Promise.Promise<()>
158
+ function InfluxDBWriteAPI._promiseSendBatch(self: InfluxDBWriteAPI, toSend: { string }): Promise.Promise<()>
107
159
  assert(type(toSend) == "table", "Bad toSend")
108
160
 
109
161
  local clientConfig = self._clientConfig.Value
@@ -122,13 +174,13 @@ function InfluxDBWriteAPI:_promiseSendBatch(toSend: { InfluxDBPoint.InfluxDBPoin
122
174
  end
123
175
 
124
176
  local body = table.concat(toSend, "\n")
125
- local request = {
177
+ local request: HttpPromise.HTTPRequest = {
126
178
  Method = "POST",
127
179
  Headers = {
128
180
  ["Content-Type"] = "application/json",
129
181
  ["Accept"] = "application/json",
130
182
  ["Authorization"] = authHeader,
131
- },
183
+ } :: any,
132
184
  Compress = Enum.HttpCompression.Gzip,
133
185
  Url = self:_getWriteUrl(),
134
186
  Body = body,
@@ -189,24 +241,20 @@ function InfluxDBWriteAPI:_promiseSendBatch(toSend: { InfluxDBPoint.InfluxDBPoin
189
241
  end)
190
242
  end
191
243
 
192
- function InfluxDBWriteAPI:PromiseFlush(): Promise.Promise<()>
244
+ function InfluxDBWriteAPI.PromiseFlush(self: InfluxDBWriteAPI): Promise.Promise<()>
193
245
  return self._writeBuffer:PromiseFlush()
194
246
  end
195
247
 
196
- function InfluxDBWriteAPI:_getWriteUrl(): string
248
+ function InfluxDBWriteAPI._getWriteUrl(self: InfluxDBWriteAPI): string
197
249
  local config = self._clientConfig.Value
198
- local url = config.url
250
+ local url: string = config.url
199
251
 
200
252
  assert(type(url) == "string", "Bad url")
201
253
 
202
254
  -- escape trailing slashes
203
- url = string.match(url, "(.-)[\\/]*$")
255
+ url = string.match(url, "(.-)[\\/]*$") or ""
204
256
 
205
- return string.format("%s/api/v2/write?org=%s&bucket=%s&precision=%s",
206
- url,
207
- self._org,
208
- self._bucket,
209
- self._precision)
257
+ return string.format("%s/api/v2/write?org=%s&bucket=%s&precision=%s", url, self._org, self._bucket, self._precision)
210
258
  end
211
259
 
212
- return InfluxDBWriteAPI
260
+ return InfluxDBWriteAPI
@@ -1,34 +1,46 @@
1
1
  --!strict
2
2
  --[=[
3
+ Buffer for influx DB points.
4
+
5
+ @server
3
6
  @class InfluxDBWriteBuffer
4
7
  ]=]
5
8
 
6
9
  local require = require(script.Parent.loader).load(script)
7
10
 
8
11
  local BaseObject = require("BaseObject")
12
+ local InfluxDBWriteOptionUtils = require("InfluxDBWriteOptionUtils")
9
13
  local Promise = require("Promise")
10
14
  local Signal = require("Signal")
11
- local _InfluxDBWriteOptionUtils = require("InfluxDBWriteOptionUtils")
12
15
 
13
16
  local InfluxDBWriteBuffer = setmetatable({}, BaseObject)
14
17
  InfluxDBWriteBuffer.ClassName = "InfluxDBWriteBuffer"
15
18
  InfluxDBWriteBuffer.__index = InfluxDBWriteBuffer
16
19
 
20
+ export type PromiseHandleFlush = (entries: { string }) -> Promise.Promise<()>
21
+
17
22
  export type InfluxDBWriteBuffer = typeof(setmetatable(
18
23
  {} :: {
19
24
  _bytes: number,
20
25
  _length: number,
21
26
  _entries: { string },
22
- _writeOptions: _InfluxDBWriteOptionUtils.InfluxDBWriteOptions,
23
- _promiseHandleFlush: (entries: { string }) -> Promise.Promise<()>,
27
+ _writeOptions: InfluxDBWriteOptionUtils.InfluxDBWriteOptions,
28
+ _promiseHandleFlush: PromiseHandleFlush,
24
29
  _requestQueueNext: Signal.Signal<()>,
25
30
  },
26
31
  {} :: typeof({ __index = InfluxDBWriteBuffer })
27
32
  )) & BaseObject.BaseObject
28
33
 
34
+ --[=[
35
+ Creates a new InfluxDB write buffer.
36
+
37
+ @param writeOptions InfluxDBWriteOptions
38
+ @param promiseHandleFlush (entries: { string }) -> Promise.Promise<()>
39
+ @return InfluxDBWriteBuffer
40
+ ]=]
29
41
  function InfluxDBWriteBuffer.new(
30
- writeOptions: _InfluxDBWriteOptionUtils.InfluxDBWriteOptions,
31
- promiseHandleFlush
42
+ writeOptions: InfluxDBWriteOptionUtils.InfluxDBWriteOptions,
43
+ promiseHandleFlush: PromiseHandleFlush
32
44
  ): InfluxDBWriteBuffer
33
45
  local self: InfluxDBWriteBuffer = setmetatable(BaseObject.new() :: any, InfluxDBWriteBuffer)
34
46
 
@@ -44,7 +56,12 @@ function InfluxDBWriteBuffer.new(
44
56
  return self
45
57
  end
46
58
 
47
- function InfluxDBWriteBuffer.Add(self: InfluxDBWriteBuffer, entry: string)
59
+ --[=[
60
+ Adds an entry to the buffer. If the buffer is full, it will flush
61
+
62
+ @param entry string
63
+ ]=]
64
+ function InfluxDBWriteBuffer.Add(self: InfluxDBWriteBuffer, entry: string): ()
48
65
  assert(type(entry) == "string", "Bad entry")
49
66
 
50
67
  -- Already overflowing
@@ -64,7 +81,7 @@ function InfluxDBWriteBuffer.Add(self: InfluxDBWriteBuffer, entry: string)
64
81
  end
65
82
  end
66
83
 
67
- function InfluxDBWriteBuffer._queueNextSend(self: InfluxDBWriteBuffer)
84
+ function InfluxDBWriteBuffer._queueNextSend(self: InfluxDBWriteBuffer): ()
68
85
  if self._maid._queuedSendTask then
69
86
  return
70
87
  end
@@ -78,7 +95,7 @@ function InfluxDBWriteBuffer._queueNextSend(self: InfluxDBWriteBuffer)
78
95
  end)
79
96
  end
80
97
 
81
- function InfluxDBWriteBuffer._reset(self: InfluxDBWriteBuffer)
98
+ function InfluxDBWriteBuffer._reset(self: InfluxDBWriteBuffer): { string }
82
99
  local entries = self._entries
83
100
 
84
101
  self._bytes = 0
@@ -88,7 +105,7 @@ function InfluxDBWriteBuffer._reset(self: InfluxDBWriteBuffer)
88
105
  return entries
89
106
  end
90
107
 
91
- function InfluxDBWriteBuffer._promiseFlushAll(self: InfluxDBWriteBuffer)
108
+ function InfluxDBWriteBuffer._promiseFlushAll(self: InfluxDBWriteBuffer): Promise.Promise<()>
92
109
  self._maid._queuedSendTask = nil
93
110
 
94
111
  local entries = self:_reset()
@@ -99,8 +116,13 @@ function InfluxDBWriteBuffer._promiseFlushAll(self: InfluxDBWriteBuffer)
99
116
  end
100
117
  end
101
118
 
102
- function InfluxDBWriteBuffer.PromiseFlush(self: InfluxDBWriteBuffer)
119
+ --[=[
120
+ Flushes all entries in the buffer. Returns a promise that resolves when the flush is complete.
121
+
122
+ @return Promise<()>
123
+ ]=]
124
+ function InfluxDBWriteBuffer.PromiseFlush(self: InfluxDBWriteBuffer): Promise.Promise<()>
103
125
  return self:_promiseFlushAll()
104
126
  end
105
127
 
106
- return InfluxDBWriteBuffer
128
+ return InfluxDBWriteBuffer
@@ -1,3 +1,4 @@
1
+ --!strict
1
2
  --[=[
2
3
  @class InfluxDBEscapeUtils
3
4
  ]=]
@@ -23,6 +24,12 @@ end
23
24
 
24
25
  export type EscapeTable = { [string]: string }
25
26
 
27
+ --[=[
28
+ Creates a new escaper function for the given table.
29
+
30
+ @param subTable EscapeTable
31
+ @return (string) -> string
32
+ ]=]
26
33
  function InfluxDBEscapeUtils.createEscaper(subTable: EscapeTable): (string) -> string
27
34
  assert(type(subTable) == "table", "Bad subTable")
28
35
 
@@ -43,39 +50,44 @@ function InfluxDBEscapeUtils.createEscaper(subTable: EscapeTable): (string) -> s
43
50
  end
44
51
  end
45
52
 
53
+ --[=[
54
+ Creates a new escaper function for the given table, with quotes.
55
+
56
+ @param subTable EscapeTable
57
+ @return (string) -> string
58
+ ]=]
46
59
  function InfluxDBEscapeUtils.createQuotedEscaper(subTable: EscapeTable): (string) -> string
47
60
  assert(type(subTable) == "table", "Bad subTable")
48
61
 
49
62
  local escaper = InfluxDBEscapeUtils.createEscaper(subTable)
50
63
 
51
64
  return function(str: string)
52
- return string.format("\"%s\"", escaper(str))
65
+ return string.format('"%s"', escaper(str))
53
66
  end
54
67
  end
55
68
 
56
-
57
69
  InfluxDBEscapeUtils.measurement = InfluxDBEscapeUtils.createEscaper({
58
- [","] = "\\,";
59
- [" "] = "\\ ";
60
- ["\n"] = "\\n";
61
- ["\r"] = "\\r";
62
- ["\t"] = "\\t";
63
- ["\\"] = "\\\\"; -- not sure about this, is this part of spec?
70
+ [","] = "\\,",
71
+ [" "] = "\\ ",
72
+ ["\n"] = "\\n",
73
+ ["\r"] = "\\r",
74
+ ["\t"] = "\\t",
75
+ ["\\"] = "\\\\", -- not sure about this, is this part of spec?
64
76
  })
65
77
 
66
78
  InfluxDBEscapeUtils.quoted = InfluxDBEscapeUtils.createQuotedEscaper({
67
- ["\""] = "\\\"";
68
- ["\\"] = "\\\\";
79
+ ['"'] = '\\"',
80
+ ["\\"] = "\\\\",
69
81
  })
70
82
 
71
83
  InfluxDBEscapeUtils.tag = InfluxDBEscapeUtils.createEscaper({
72
- [","] = "\\,";
73
- [" "] = "\\ ";
74
- ["="] = "\\=";
75
- ["\n"] = "\\n";
76
- ["\r"] = "\\r";
77
- ["\t"] = "\\t";
78
- ["\\"] = "\\\\"; -- not sure about this, is this part of spec?
84
+ [","] = "\\,",
85
+ [" "] = "\\ ",
86
+ ["="] = "\\=",
87
+ ["\n"] = "\\n",
88
+ ["\r"] = "\\r",
89
+ ["\t"] = "\\t",
90
+ ["\\"] = "\\\\", -- not sure about this, is this part of spec?
79
91
  })
80
92
 
81
- return InfluxDBEscapeUtils
93
+ return InfluxDBEscapeUtils
@@ -2,7 +2,8 @@
2
2
  @class InfluxDBEscapeUtils.spec.lua
3
3
  ]]
4
4
 
5
- local require = require(game:GetService("ServerScriptService"):FindFirstChild("LoaderUtils", true).Parent).bootstrapStory(script)
5
+ local require =
6
+ require(game:GetService("ServerScriptService"):FindFirstChild("LoaderUtils", true).Parent).bootstrapStory(script)
6
7
 
7
8
  local InfluxDBEscapeUtils = require("InfluxDBEscapeUtils")
8
9
  local Jest = require("Jest")
@@ -25,11 +26,11 @@ end)
25
26
 
26
27
  describe("InfluxDBEscapeUtils.quoted", function()
27
28
  it("should pass through fine", function()
28
- expect(InfluxDBEscapeUtils.quoted("hi")).toBe("\"hi\"")
29
+ expect(InfluxDBEscapeUtils.quoted("hi")).toBe('"hi"')
29
30
  end)
30
31
 
31
32
  it("should escape quotes", function()
32
- expect(InfluxDBEscapeUtils.quoted("\"hi")).toBe("\"\\\"hi\"")
33
+ expect(InfluxDBEscapeUtils.quoted('"hi')).toBe('"\\"hi"')
33
34
  end)
34
35
  end)
35
36
 
@@ -58,4 +59,4 @@ describe("InfluxDBEscapeUtils.tag", function()
58
59
  local tag = InfluxDBEscapeUtils.tag("\nhi")
59
60
  expect(tag).toBe("\\nhi")
60
61
  end)
61
- end)
62
+ end)
@@ -5,10 +5,11 @@
5
5
 
6
6
  local require = require(script.Parent.loader).load(script)
7
7
 
8
- local Math = require("Math")
9
8
  local InfluxDBEscapeUtils = require("InfluxDBEscapeUtils")
10
- local Table = require("Table")
9
+ local InfluxDBPointSettings = require("InfluxDBPointSettings")
10
+ local Math = require("Math")
11
11
  local Set = require("Set")
12
+ local Table = require("Table")
12
13
 
13
14
  local InfluxDBPoint = {}
14
15
  InfluxDBPoint.ClassName = "InfluxDBPoint"
@@ -31,6 +32,12 @@ export type InfluxDBPointTableData = {
31
32
  fields: { [string]: string },
32
33
  }
33
34
 
35
+ --[=[
36
+ Creates a new InfluxDB point
37
+
38
+ @param measurementName string?
39
+ @return InfluxDBPoint
40
+ ]=]
34
41
  function InfluxDBPoint.new(measurementName: string?): InfluxDBPoint
35
42
  local self: InfluxDBPoint = setmetatable({} :: any, InfluxDBPoint)
36
43
 
@@ -44,7 +51,13 @@ function InfluxDBPoint.new(measurementName: string?): InfluxDBPoint
44
51
  return self
45
52
  end
46
53
 
47
- function InfluxDBPoint.fromTableData(data: InfluxDBPointTableData)
54
+ --[=[
55
+ Creates a new InfluxDB point from table data
56
+
57
+ @param data InfluxDBPointTableData
58
+ @return InfluxDBPoint
59
+ ]=]
60
+ function InfluxDBPoint.fromTableData(data: InfluxDBPointTableData): InfluxDBPoint
48
61
  assert(type(data) == "table", "Bad data")
49
62
  assert(type(data.measurementName) == "string" or data.measurementName == nil, "Bad data.measurementName")
50
63
 
@@ -77,20 +90,42 @@ function InfluxDBPoint.fromTableData(data: InfluxDBPointTableData)
77
90
  return copy
78
91
  end
79
92
 
93
+ --[=[
94
+ Checks if the point is an InfluxDBPoint
95
+
96
+ @param point any
97
+ @return boolean
98
+ ]=]
80
99
  function InfluxDBPoint.isInfluxDBPoint(point: any): boolean
81
100
  return type(point) == "table" and getmetatable(point) == InfluxDBPoint
82
101
  end
83
102
 
103
+ --[=[
104
+ Sets the measurement name
105
+
106
+ @param name string?
107
+ @return boolean
108
+ ]=]
84
109
  function InfluxDBPoint.SetMeasurementName(self: InfluxDBPoint, name: string)
85
110
  assert(type(name) == "string" or name == nil, "Bad name")
86
111
 
87
112
  self._measurementName = name
88
113
  end
89
114
 
115
+ --[=[
116
+ Gets the measurement name
117
+
118
+ @return string?
119
+ ]=]
90
120
  function InfluxDBPoint.GetMeasurementName(self: InfluxDBPoint): string?
91
121
  return self._measurementName
92
122
  end
93
123
 
124
+ --[=[
125
+ Converts the point into a table data format safe for serialization
126
+
127
+ @return InfluxDBPointTableData
128
+ ]=]
94
129
  function InfluxDBPoint.ToTableData(self: InfluxDBPoint): InfluxDBPointTableData
95
130
  return {
96
131
  measurementName = self._measurementName,
@@ -210,7 +245,16 @@ function InfluxDBPoint.AddStringField(self: InfluxDBPoint, fieldName: string, va
210
245
  self._fields[fieldName] = InfluxDBEscapeUtils.quoted(value)
211
246
  end
212
247
 
213
- function InfluxDBPoint.ToLineProtocol(self: InfluxDBPoint, pointSettings)
248
+ --[=[
249
+ Converts the point to line protocol format to send to InfluxDB for consumption
250
+
251
+ @param pointSettings InfluxDBPointSettings
252
+ @return string?
253
+ ]=]
254
+ function InfluxDBPoint.ToLineProtocol(
255
+ self: InfluxDBPoint,
256
+ pointSettings: InfluxDBPointSettings.InfluxDBPointSettings
257
+ ): string?
214
258
  if not self._measurementName then
215
259
  return nil
216
260
  end
@@ -248,9 +292,9 @@ function InfluxDBPoint.ToLineProtocol(self: InfluxDBPoint, pointSettings)
248
292
  end
249
293
  end
250
294
 
251
- local timestamp: any? = self._timestamp
295
+ local timestamp = self._timestamp
252
296
  local convertTime = pointSettings:GetConvertTime()
253
- if convertTime then
297
+ if convertTime ~= nil then
254
298
  timestamp = convertTime(timestamp)
255
299
  else
256
300
  timestamp = self:_convertTimeToMillis(timestamp)
@@ -273,7 +317,7 @@ end
273
317
 
274
318
  function InfluxDBPoint._convertTimeToMillis(_self: InfluxDBPoint, value: (string | DateTime | number)?): string?
275
319
  if value == nil then
276
- return tostring(DateTime.now().UnixTimestampMillis)
320
+ return tostring(DateTime.now().UnixTimestampMillis)
277
321
  elseif type(value) == "string" then
278
322
  if #value > 0 then
279
323
  return value
@@ -289,4 +333,4 @@ function InfluxDBPoint._convertTimeToMillis(_self: InfluxDBPoint, value: (string
289
333
  end
290
334
  end
291
335
 
292
- return InfluxDBPoint
336
+ return InfluxDBPoint