@noita-ts/pollnet 0.3.5 → 0.3.6
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/async.d.ts +1 -0
- package/dist/async.lua +19 -31
- package/dist/lualib_bundle.lua +44 -44
- package/package.json +1 -1
package/dist/async.d.ts
CHANGED
|
@@ -48,6 +48,7 @@ export declare class HttpResponse {
|
|
|
48
48
|
headers: string;
|
|
49
49
|
body: string;
|
|
50
50
|
constructor(status: number, headers: string, body: string);
|
|
51
|
+
static read(socket: pollnet.Socket): HttpResponse;
|
|
51
52
|
/**
|
|
52
53
|
* Parse the raw header block into a map.
|
|
53
54
|
* Header names seen more than once collapse into an array of their values, in
|
package/dist/async.lua
CHANGED
|
@@ -3,14 +3,14 @@ local __TS__Promise = ____lualib.__TS__Promise
|
|
|
3
3
|
local __TS__New = ____lualib.__TS__New
|
|
4
4
|
local __TS__Class = ____lualib.__TS__Class
|
|
5
5
|
local __TS__InstanceOf = ____lualib.__TS__InstanceOf
|
|
6
|
-
local __TS__StringSplit = ____lualib.__TS__StringSplit
|
|
7
|
-
local __TS__ArrayIsArray = ____lualib.__TS__ArrayIsArray
|
|
8
6
|
local Error = ____lualib.Error
|
|
9
7
|
local RangeError = ____lualib.RangeError
|
|
10
8
|
local ReferenceError = ____lualib.ReferenceError
|
|
11
9
|
local SyntaxError = ____lualib.SyntaxError
|
|
12
10
|
local TypeError = ____lualib.TypeError
|
|
13
11
|
local URIError = ____lualib.URIError
|
|
12
|
+
local __TS__StringSplit = ____lualib.__TS__StringSplit
|
|
13
|
+
local __TS__ArrayIsArray = ____lualib.__TS__ArrayIsArray
|
|
14
14
|
local ____exports = {}
|
|
15
15
|
local _____2E = require("index")
|
|
16
16
|
local pollnet = _____2E.default
|
|
@@ -111,6 +111,18 @@ function HttpResponse.prototype.____constructor(self, status, headers, body)
|
|
|
111
111
|
self.headers = headers
|
|
112
112
|
self.body = body
|
|
113
113
|
end
|
|
114
|
+
function HttpResponse.read(self, socket)
|
|
115
|
+
local msgs, ____error = socket:await_n(3)
|
|
116
|
+
if not msgs then
|
|
117
|
+
error(
|
|
118
|
+
__TS__New(Error, "socket error: " .. ____error),
|
|
119
|
+
0
|
|
120
|
+
)
|
|
121
|
+
end
|
|
122
|
+
local statusStr, headersStr, respBody = unpack(msgs, 1, 3)
|
|
123
|
+
local status = tonumber((string.match("^%d+", statusStr))) or 500
|
|
124
|
+
return __TS__New(____exports.HttpResponse, status, headersStr, respBody)
|
|
125
|
+
end
|
|
114
126
|
function HttpResponse.prototype.parseHeaders(self)
|
|
115
127
|
local headers = {}
|
|
116
128
|
for ____, line in ipairs(__TS__StringSplit(self.headers, "\n")) do
|
|
@@ -121,12 +133,12 @@ function HttpResponse.prototype.parseHeaders(self)
|
|
|
121
133
|
2
|
|
122
134
|
)
|
|
123
135
|
if not key or not value then
|
|
124
|
-
goto
|
|
136
|
+
goto __continue26
|
|
125
137
|
end
|
|
126
138
|
local prev = headers[key]
|
|
127
139
|
if not prev then
|
|
128
140
|
headers[key] = value
|
|
129
|
-
goto
|
|
141
|
+
goto __continue26
|
|
130
142
|
end
|
|
131
143
|
if __TS__ArrayIsArray(prev) then
|
|
132
144
|
prev[#prev + 1] = value
|
|
@@ -134,7 +146,7 @@ function HttpResponse.prototype.parseHeaders(self)
|
|
|
134
146
|
headers[key] = {prev, value}
|
|
135
147
|
end
|
|
136
148
|
end
|
|
137
|
-
::
|
|
149
|
+
::__continue26::
|
|
138
150
|
end
|
|
139
151
|
return headers
|
|
140
152
|
end
|
|
@@ -147,33 +159,9 @@ function HttpClient.prototype.____constructor(self, reactor)
|
|
|
147
159
|
self.reactor = reactor
|
|
148
160
|
end
|
|
149
161
|
function HttpClient.prototype.get(self, url, headers)
|
|
150
|
-
return self.reactor:spawn(function()
|
|
151
|
-
local socket = pollnet.http_get(url, headers, false)
|
|
152
|
-
local msgs, ____error = socket:await_n(3)
|
|
153
|
-
if not msgs then
|
|
154
|
-
error(
|
|
155
|
-
__TS__New(Error, "socket error: " .. ____error),
|
|
156
|
-
0
|
|
157
|
-
)
|
|
158
|
-
end
|
|
159
|
-
local statusStr, headersStr, respBody = unpack(msgs, 1, 3)
|
|
160
|
-
local status = tonumber({string.match("^%d+", statusStr)}) or 500
|
|
161
|
-
return __TS__New(____exports.HttpResponse, status, headersStr, respBody)
|
|
162
|
-
end)
|
|
162
|
+
return self.reactor:spawn(function() return ____exports.HttpResponse:read(pollnet.http_get(url, headers, false)) end)
|
|
163
163
|
end
|
|
164
164
|
function HttpClient.prototype.post(self, url, headers, body)
|
|
165
|
-
return self.reactor:spawn(function()
|
|
166
|
-
local socket = pollnet.http_post(url, headers, body, false)
|
|
167
|
-
local msgs, ____error = socket:await_n(3)
|
|
168
|
-
if not msgs then
|
|
169
|
-
error(
|
|
170
|
-
__TS__New(Error, "socket error: " .. ____error),
|
|
171
|
-
0
|
|
172
|
-
)
|
|
173
|
-
end
|
|
174
|
-
local statusStr, headersStr, respBody = unpack(msgs, 1, 3)
|
|
175
|
-
local status = tonumber((string.match("^%d+", statusStr))) or 500
|
|
176
|
-
return __TS__New(____exports.HttpResponse, status, headersStr, respBody)
|
|
177
|
-
end)
|
|
165
|
+
return self.reactor:spawn(function() return ____exports.HttpResponse:read(pollnet.http_post(url, headers, body, false)) end)
|
|
178
166
|
end
|
|
179
167
|
return ____exports
|
package/dist/lualib_bundle.lua
CHANGED
|
@@ -213,47 +213,6 @@ do
|
|
|
213
213
|
end
|
|
214
214
|
end
|
|
215
215
|
|
|
216
|
-
local __TS__StringSplit
|
|
217
|
-
do
|
|
218
|
-
local sub = string.sub
|
|
219
|
-
local find = string.find
|
|
220
|
-
function __TS__StringSplit(source, separator, limit)
|
|
221
|
-
if limit == nil then
|
|
222
|
-
limit = 4294967295
|
|
223
|
-
end
|
|
224
|
-
if limit == 0 then
|
|
225
|
-
return {}
|
|
226
|
-
end
|
|
227
|
-
local result = {}
|
|
228
|
-
local resultIndex = 1
|
|
229
|
-
if separator == nil or separator == "" then
|
|
230
|
-
for i = 1, #source do
|
|
231
|
-
result[resultIndex] = sub(source, i, i)
|
|
232
|
-
resultIndex = resultIndex + 1
|
|
233
|
-
end
|
|
234
|
-
else
|
|
235
|
-
local currentPos = 1
|
|
236
|
-
while resultIndex <= limit do
|
|
237
|
-
local startPos, endPos = find(source, separator, currentPos, true)
|
|
238
|
-
if not startPos then
|
|
239
|
-
break
|
|
240
|
-
end
|
|
241
|
-
result[resultIndex] = sub(source, currentPos, startPos - 1)
|
|
242
|
-
resultIndex = resultIndex + 1
|
|
243
|
-
currentPos = endPos + 1
|
|
244
|
-
end
|
|
245
|
-
if resultIndex <= limit then
|
|
246
|
-
result[resultIndex] = sub(source, currentPos)
|
|
247
|
-
end
|
|
248
|
-
end
|
|
249
|
-
return result
|
|
250
|
-
end
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
local function __TS__ArrayIsArray(value)
|
|
254
|
-
return type(value) == "table" and (value[1] ~= nil or next(value) == nil)
|
|
255
|
-
end
|
|
256
|
-
|
|
257
216
|
local function __TS__StringIncludes(self, searchString, position)
|
|
258
217
|
if not position then
|
|
259
218
|
position = 1
|
|
@@ -374,17 +333,58 @@ do
|
|
|
374
333
|
URIError = createErrorClass(nil, "URIError")
|
|
375
334
|
end
|
|
376
335
|
|
|
336
|
+
local __TS__StringSplit
|
|
337
|
+
do
|
|
338
|
+
local sub = string.sub
|
|
339
|
+
local find = string.find
|
|
340
|
+
function __TS__StringSplit(source, separator, limit)
|
|
341
|
+
if limit == nil then
|
|
342
|
+
limit = 4294967295
|
|
343
|
+
end
|
|
344
|
+
if limit == 0 then
|
|
345
|
+
return {}
|
|
346
|
+
end
|
|
347
|
+
local result = {}
|
|
348
|
+
local resultIndex = 1
|
|
349
|
+
if separator == nil or separator == "" then
|
|
350
|
+
for i = 1, #source do
|
|
351
|
+
result[resultIndex] = sub(source, i, i)
|
|
352
|
+
resultIndex = resultIndex + 1
|
|
353
|
+
end
|
|
354
|
+
else
|
|
355
|
+
local currentPos = 1
|
|
356
|
+
while resultIndex <= limit do
|
|
357
|
+
local startPos, endPos = find(source, separator, currentPos, true)
|
|
358
|
+
if not startPos then
|
|
359
|
+
break
|
|
360
|
+
end
|
|
361
|
+
result[resultIndex] = sub(source, currentPos, startPos - 1)
|
|
362
|
+
resultIndex = resultIndex + 1
|
|
363
|
+
currentPos = endPos + 1
|
|
364
|
+
end
|
|
365
|
+
if resultIndex <= limit then
|
|
366
|
+
result[resultIndex] = sub(source, currentPos)
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
return result
|
|
370
|
+
end
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
local function __TS__ArrayIsArray(value)
|
|
374
|
+
return type(value) == "table" and (value[1] ~= nil or next(value) == nil)
|
|
375
|
+
end
|
|
376
|
+
|
|
377
377
|
return {
|
|
378
378
|
__TS__Promise = __TS__Promise,
|
|
379
379
|
__TS__New = __TS__New,
|
|
380
380
|
__TS__Class = __TS__Class,
|
|
381
381
|
__TS__InstanceOf = __TS__InstanceOf,
|
|
382
|
-
__TS__StringSplit = __TS__StringSplit,
|
|
383
|
-
__TS__ArrayIsArray = __TS__ArrayIsArray,
|
|
384
382
|
Error = Error,
|
|
385
383
|
RangeError = RangeError,
|
|
386
384
|
ReferenceError = ReferenceError,
|
|
387
385
|
SyntaxError = SyntaxError,
|
|
388
386
|
TypeError = TypeError,
|
|
389
|
-
URIError = URIError
|
|
387
|
+
URIError = URIError,
|
|
388
|
+
__TS__StringSplit = __TS__StringSplit,
|
|
389
|
+
__TS__ArrayIsArray = __TS__ArrayIsArray
|
|
390
390
|
}
|