@noita-ts/pollnet 0.1.0 → 0.3.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 probable-basilisk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,73 @@
1
+ import pollnet from ".";
2
+ export declare namespace compat {
3
+ /**
4
+ * Run `body` inside a reactor coroutine and get its completion as a Promise.
5
+ * `body` may freely use socket.await() / other yield-based pollnet APIs.
6
+ * Errors inside body reject the promise.
7
+ */
8
+ const asyncify: <T>(reactor: pollnet.Reactor, body: () => T) => Promise<T>;
9
+ /**
10
+ * Parks the *current coroutine* until the promise settles, then returns its
11
+ * value or rethrows its rejection.
12
+ * Only call from inside a reactor coroutine (`reactor.run(() => { .. HERE .. })`).
13
+ */
14
+ const yieldPromise: <T>(p: Promise<T>) => T;
15
+ }
16
+ /**
17
+ * Promise-friendly wrapper around a {@link pollnet.Reactor}.
18
+ *
19
+ * Lets you drive yield-based pollnet coroutines while exposing their results
20
+ * as Promises. Call {@link poll} regularly (e.g. once per frame) to advance
21
+ * all running coroutines.
22
+ */
23
+ export declare class AsyncReactor {
24
+ private reactor;
25
+ constructor();
26
+ /**
27
+ * Advance every coroutine currently running on the reactor by one step.
28
+ * Must be called periodically for spawned work to make progress.
29
+ */
30
+ poll(): number;
31
+ /**
32
+ * Run `body` as a reactor coroutine and return its result as a Promise.
33
+ * `body` may use yield-based pollnet APIs (e.g. `socket.await()`).
34
+ */
35
+ spawn<T>(body: () => T): Promise<T>;
36
+ /**
37
+ * Async version of `pollnet.Reactor.run_server`.
38
+ *
39
+ * Accept connections on `server_sock`, spawning a coroutine that runs
40
+ * `client_body` for each incoming client. `client_body` receives the client
41
+ * socket and its remote address, and may itself return a Promise which the
42
+ * coroutine parks on until it settles.
43
+ */
44
+ runServer(server_sock: pollnet.Socket, client_body: (sock: pollnet.Socket, addr: string) => Promise<void>): void;
45
+ }
46
+ export declare class HttpResponse {
47
+ status: number;
48
+ headers: string;
49
+ body: string;
50
+ constructor(status: number, headers: string, body: string);
51
+ /**
52
+ * Parse the raw header block into a map.
53
+ * Header names seen more than once collapse into an array of their values, in
54
+ * order.
55
+ */
56
+ parseHeaders(): Record<string, string | string[]>;
57
+ }
58
+ /**
59
+ * Tiny async HTTP client built on top of an {@link AsyncReactor}.
60
+ * Requests run as reactor coroutines and resolve to an {@link HttpResponse}.
61
+ */
62
+ export declare class HttpClient {
63
+ private reactor;
64
+ constructor(reactor: AsyncReactor);
65
+ /**
66
+ * Perform an HTTP GET.
67
+ */
68
+ get(url: string, headers?: Record<string, string | string[]> | string): Promise<HttpResponse>;
69
+ /**
70
+ * Perform an HTTP POST with an optional request `body`.
71
+ */
72
+ post(url: string, headers?: Record<string, string | string[]> | string, body?: string): Promise<HttpResponse>;
73
+ }
package/dist/async.lua ADDED
@@ -0,0 +1,173 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local __TS__Promise = ____lualib.__TS__Promise
3
+ local __TS__New = ____lualib.__TS__New
4
+ local __TS__Class = ____lualib.__TS__Class
5
+ local __TS__StringSplit = ____lualib.__TS__StringSplit
6
+ local __TS__ArrayIsArray = ____lualib.__TS__ArrayIsArray
7
+ local Error = ____lualib.Error
8
+ local RangeError = ____lualib.RangeError
9
+ local ReferenceError = ____lualib.ReferenceError
10
+ local SyntaxError = ____lualib.SyntaxError
11
+ local TypeError = ____lualib.TypeError
12
+ local URIError = ____lualib.URIError
13
+ local ____exports = {}
14
+ local _____2E = require("index")
15
+ local pollnet = _____2E.default
16
+ ____exports.compat = {}
17
+ local compat = ____exports.compat
18
+ do
19
+ --- Run `body` inside a reactor coroutine and get its completion as a Promise.
20
+ -- `body` may freely use socket.await() / other yield-based pollnet APIs.
21
+ -- Errors inside body reject the promise.
22
+ compat.asyncify = function(____, reactor, body)
23
+ return __TS__New(
24
+ __TS__Promise,
25
+ function(____, resolve, reject)
26
+ reactor:run(function()
27
+ do
28
+ local function ____catch(e)
29
+ reject(nil, e)
30
+ end
31
+ local ____try, ____hasReturned = pcall(function()
32
+ resolve(
33
+ nil,
34
+ body(nil)
35
+ )
36
+ end)
37
+ if not ____try then
38
+ ____catch(____hasReturned)
39
+ end
40
+ end
41
+ end)
42
+ end
43
+ )
44
+ end
45
+ --- Parks the *current coroutine* until the promise settles, then returns its
46
+ -- value or rethrows its rejection.
47
+ -- Only call from inside a reactor coroutine (`reactor.run(() => { .. HERE .. })`).
48
+ compat.yieldPromise = function(____, p)
49
+ local done = false
50
+ local ok = false
51
+ local result
52
+ p["then"](
53
+ p,
54
+ function(____, v)
55
+ done = true
56
+ ok = true
57
+ result = v
58
+ end,
59
+ function(____, e)
60
+ done = true
61
+ ok = false
62
+ result = e
63
+ end
64
+ )
65
+ while not done do
66
+ coroutine.yield()
67
+ end
68
+ if not ok then
69
+ error(result, 0)
70
+ end
71
+ return result
72
+ end
73
+ end
74
+ --- Promise-friendly wrapper around a {@link pollnet.Reactor}.
75
+ --
76
+ -- Lets you drive yield-based pollnet coroutines while exposing their results
77
+ -- as Promises. Call {@link poll} regularly (e.g. once per frame) to advance
78
+ -- all running coroutines.
79
+ ____exports.AsyncReactor = __TS__Class()
80
+ local AsyncReactor = ____exports.AsyncReactor
81
+ AsyncReactor.name = "AsyncReactor"
82
+ function AsyncReactor.prototype.____constructor(self)
83
+ self.reactor = pollnet.Reactor()
84
+ end
85
+ function AsyncReactor.prototype.poll(self)
86
+ return self.reactor:update()
87
+ end
88
+ function AsyncReactor.prototype.spawn(self, body)
89
+ return ____exports.compat:asyncify(self.reactor, body)
90
+ end
91
+ function AsyncReactor.prototype.runServer(self, server_sock, client_body)
92
+ server_sock:on_connection(function(client_sock, addr)
93
+ self.reactor:run(function() return ____exports.compat:yieldPromise(client_body(nil, client_sock, addr)) end)
94
+ end)
95
+ self.reactor:run(function()
96
+ while (server_sock:await()) do
97
+ end
98
+ end)
99
+ end
100
+ ____exports.HttpResponse = __TS__Class()
101
+ local HttpResponse = ____exports.HttpResponse
102
+ HttpResponse.name = "HttpResponse"
103
+ function HttpResponse.prototype.____constructor(self, status, headers, body)
104
+ self.status = status
105
+ self.headers = headers
106
+ self.body = body
107
+ end
108
+ function HttpResponse.prototype.parseHeaders(self)
109
+ local headers = {}
110
+ for ____, line in ipairs(__TS__StringSplit(self.headers, "\n")) do
111
+ do
112
+ local key, value = unpack(
113
+ __TS__StringSplit(line, ": ", 2),
114
+ 1,
115
+ 2
116
+ )
117
+ if not key or not value then
118
+ goto __continue23
119
+ end
120
+ local prev = headers[key]
121
+ if not prev then
122
+ headers[key] = value
123
+ goto __continue23
124
+ end
125
+ if __TS__ArrayIsArray(prev) then
126
+ prev[#prev + 1] = value
127
+ else
128
+ headers[key] = {prev, value}
129
+ end
130
+ end
131
+ ::__continue23::
132
+ end
133
+ return headers
134
+ end
135
+ --- Tiny async HTTP client built on top of an {@link AsyncReactor}.
136
+ -- Requests run as reactor coroutines and resolve to an {@link HttpResponse}.
137
+ ____exports.HttpClient = __TS__Class()
138
+ local HttpClient = ____exports.HttpClient
139
+ HttpClient.name = "HttpClient"
140
+ function HttpClient.prototype.____constructor(self, reactor)
141
+ self.reactor = reactor
142
+ end
143
+ function HttpClient.prototype.get(self, url, headers)
144
+ return self.reactor:spawn(function()
145
+ local socket = pollnet.http_get(url, headers, false)
146
+ local msgs, ____error = socket:await_n(3)
147
+ if not msgs then
148
+ error(
149
+ __TS__New(Error, "socket error: " .. ____error),
150
+ 0
151
+ )
152
+ end
153
+ local statusStr, headersStr, respBody = unpack(msgs, 1, 3)
154
+ local status = tonumber({string.match("^%d+", statusStr)}) or 500
155
+ return __TS__New(____exports.HttpResponse, status, headersStr, respBody)
156
+ end)
157
+ end
158
+ function HttpClient.prototype.post(self, url, headers, body)
159
+ return self.reactor:spawn(function()
160
+ local socket = pollnet.http_post(url, headers, body, false)
161
+ local msgs, ____error = socket:await_n(3)
162
+ if not msgs then
163
+ error(
164
+ __TS__New(Error, "socket error: " .. ____error),
165
+ 0
166
+ )
167
+ end
168
+ local statusStr, headersStr, respBody = unpack(msgs, 1, 3)
169
+ local status = tonumber({string.match("^%d+", statusStr)}) or 500
170
+ return __TS__New(____exports.HttpResponse, status, headersStr, respBody)
171
+ end)
172
+ end
173
+ return ____exports
@@ -154,8 +154,7 @@ declare namespace pollnet {
154
154
 
155
155
  /** Awaits a message (coroutine.yield) */
156
156
  await():
157
- | LuaMultiReturn<[string, undefined]>
158
- | LuaMultiReturn<[false, string]>;
157
+ LuaMultiReturn<[string, undefined]> | LuaMultiReturn<[false, string]>;
159
158
 
160
159
  /** Awaits N messages */
161
160
  await_n(
@@ -197,12 +196,12 @@ declare namespace pollnet {
197
196
  init(): void;
198
197
 
199
198
  /** Runs a coroutine thread */
200
- run(thread_body: (self: Reactor) => Promise<void> | void): void;
199
+ run(thread_body: (this: Reactor) => void): void;
201
200
 
202
201
  /** Runs a server with client handler */
203
202
  run_server(
204
203
  server_sock: Socket,
205
- client_body: (sock: Socket, addr: string) => Promise<void> | void,
204
+ client_body: (sock: Socket, addr: string) => void,
206
205
  ): void;
207
206
 
208
207
  /** Logs messages */
@@ -0,0 +1,389 @@
1
+ local function __TS__New(target, ...)
2
+ local instance = setmetatable({}, target.prototype)
3
+ instance:____constructor(...)
4
+ return instance
5
+ end
6
+
7
+ local __TS__Symbol, Symbol
8
+ do
9
+ local symbolMetatable = {__tostring = function(self)
10
+ return ("Symbol(" .. (self.description or "")) .. ")"
11
+ end}
12
+ function __TS__Symbol(description)
13
+ return setmetatable({description = description}, symbolMetatable)
14
+ end
15
+ Symbol = {
16
+ asyncDispose = __TS__Symbol("Symbol.asyncDispose"),
17
+ dispose = __TS__Symbol("Symbol.dispose"),
18
+ iterator = __TS__Symbol("Symbol.iterator"),
19
+ hasInstance = __TS__Symbol("Symbol.hasInstance"),
20
+ species = __TS__Symbol("Symbol.species"),
21
+ toStringTag = __TS__Symbol("Symbol.toStringTag")
22
+ }
23
+ end
24
+
25
+ local function __TS__InstanceOf(obj, classTbl)
26
+ if type(classTbl) ~= "table" then
27
+ error("Right-hand side of 'instanceof' is not an object", 0)
28
+ end
29
+ if classTbl[Symbol.hasInstance] ~= nil then
30
+ return not not classTbl[Symbol.hasInstance](classTbl, obj)
31
+ end
32
+ if type(obj) == "table" then
33
+ local luaClass = obj.constructor
34
+ while luaClass ~= nil do
35
+ if luaClass == classTbl then
36
+ return true
37
+ end
38
+ luaClass = luaClass.____super
39
+ end
40
+ end
41
+ return false
42
+ end
43
+
44
+ local function __TS__Class(self)
45
+ local c = {prototype = {}}
46
+ c.prototype.__index = c.prototype
47
+ c.prototype.constructor = c
48
+ return c
49
+ end
50
+
51
+ local __TS__Promise
52
+ do
53
+ local function makeDeferredPromiseFactory()
54
+ local resolve
55
+ local reject
56
+ local function executor(____, res, rej)
57
+ resolve = res
58
+ reject = rej
59
+ end
60
+ return function()
61
+ local promise = __TS__New(__TS__Promise, executor)
62
+ return promise, resolve, reject
63
+ end
64
+ end
65
+ local makeDeferredPromise = makeDeferredPromiseFactory()
66
+ local function isPromiseLike(value)
67
+ return __TS__InstanceOf(value, __TS__Promise)
68
+ end
69
+ local function doNothing(self)
70
+ end
71
+ local ____pcall = _G.pcall
72
+ __TS__Promise = __TS__Class()
73
+ __TS__Promise.name = "__TS__Promise"
74
+ function __TS__Promise.prototype.____constructor(self, executor)
75
+ self.state = 0
76
+ self.fulfilledCallbacks = {}
77
+ self.rejectedCallbacks = {}
78
+ local success, ____error = ____pcall(
79
+ executor,
80
+ nil,
81
+ function(____, v) return self:resolve(v) end,
82
+ function(____, err) return self:reject(err) end
83
+ )
84
+ if not success then
85
+ self:reject(____error)
86
+ end
87
+ end
88
+ function __TS__Promise.resolve(value)
89
+ if __TS__InstanceOf(value, __TS__Promise) then
90
+ return value
91
+ end
92
+ local promise = __TS__New(__TS__Promise, doNothing)
93
+ promise.state = 1
94
+ promise.value = value
95
+ return promise
96
+ end
97
+ function __TS__Promise.reject(reason)
98
+ local promise = __TS__New(__TS__Promise, doNothing)
99
+ promise.state = 2
100
+ promise.rejectionReason = reason
101
+ return promise
102
+ end
103
+ __TS__Promise.prototype["then"] = function(self, onFulfilled, onRejected)
104
+ local promise, resolve, reject = makeDeferredPromise()
105
+ self:addCallbacks(
106
+ onFulfilled and self:createPromiseResolvingCallback(onFulfilled, resolve, reject) or resolve,
107
+ onRejected and self:createPromiseResolvingCallback(onRejected, resolve, reject) or reject
108
+ )
109
+ return promise
110
+ end
111
+ function __TS__Promise.prototype.addCallbacks(self, fulfilledCallback, rejectedCallback)
112
+ if self.state == 1 then
113
+ return fulfilledCallback(nil, self.value)
114
+ end
115
+ if self.state == 2 then
116
+ return rejectedCallback(nil, self.rejectionReason)
117
+ end
118
+ local ____self_fulfilledCallbacks_0 = self.fulfilledCallbacks
119
+ ____self_fulfilledCallbacks_0[#____self_fulfilledCallbacks_0 + 1] = fulfilledCallback
120
+ local ____self_rejectedCallbacks_1 = self.rejectedCallbacks
121
+ ____self_rejectedCallbacks_1[#____self_rejectedCallbacks_1 + 1] = rejectedCallback
122
+ end
123
+ function __TS__Promise.prototype.catch(self, onRejected)
124
+ return self["then"](self, nil, onRejected)
125
+ end
126
+ function __TS__Promise.prototype.finally(self, onFinally)
127
+ if type(onFinally) ~= "function" then
128
+ return self["then"](self, onFinally, onFinally)
129
+ end
130
+ return self["then"](
131
+ self,
132
+ function(____, x)
133
+ local ____self_2 = __TS__New(
134
+ __TS__Promise,
135
+ function(____, resolve) return resolve(
136
+ nil,
137
+ onFinally(nil)
138
+ ) end
139
+ )
140
+ return ____self_2["then"](
141
+ ____self_2,
142
+ function() return x end
143
+ )
144
+ end,
145
+ function(____, e)
146
+ local ____self_3 = __TS__New(
147
+ __TS__Promise,
148
+ function(____, resolve) return resolve(
149
+ nil,
150
+ onFinally(nil)
151
+ ) end
152
+ )
153
+ return ____self_3["then"](
154
+ ____self_3,
155
+ function()
156
+ error(e, 0)
157
+ end
158
+ )
159
+ end
160
+ )
161
+ end
162
+ function __TS__Promise.prototype.resolve(self, value)
163
+ if isPromiseLike(value) then
164
+ return value:addCallbacks(
165
+ function(____, v) return self:resolve(v) end,
166
+ function(____, err) return self:reject(err) end
167
+ )
168
+ end
169
+ if self.state == 0 then
170
+ self.state = 1
171
+ self.value = value
172
+ return self:invokeCallbacks(self.fulfilledCallbacks, value)
173
+ end
174
+ end
175
+ function __TS__Promise.prototype.reject(self, reason)
176
+ if self.state == 0 then
177
+ self.state = 2
178
+ self.rejectionReason = reason
179
+ return self:invokeCallbacks(self.rejectedCallbacks, reason)
180
+ end
181
+ end
182
+ function __TS__Promise.prototype.invokeCallbacks(self, callbacks, value)
183
+ local callbacksLength = #callbacks
184
+ if callbacksLength ~= 0 then
185
+ for i = 1, callbacksLength - 1 do
186
+ callbacks[i](callbacks, value)
187
+ end
188
+ return callbacks[callbacksLength](callbacks, value)
189
+ end
190
+ end
191
+ function __TS__Promise.prototype.createPromiseResolvingCallback(self, f, resolve, reject)
192
+ return function(____, value)
193
+ local success, resultOrError = ____pcall(f, nil, value)
194
+ if not success then
195
+ return reject(nil, resultOrError)
196
+ end
197
+ return self:handleCallbackValue(resultOrError, resolve, reject)
198
+ end
199
+ end
200
+ function __TS__Promise.prototype.handleCallbackValue(self, value, resolve, reject)
201
+ if isPromiseLike(value) then
202
+ local nextpromise = value
203
+ if nextpromise.state == 1 then
204
+ return resolve(nil, nextpromise.value)
205
+ elseif nextpromise.state == 2 then
206
+ return reject(nil, nextpromise.rejectionReason)
207
+ else
208
+ return nextpromise:addCallbacks(resolve, reject)
209
+ end
210
+ else
211
+ return resolve(nil, value)
212
+ end
213
+ end
214
+ end
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
+ local function __TS__StringIncludes(self, searchString, position)
258
+ if not position then
259
+ position = 1
260
+ else
261
+ position = position + 1
262
+ end
263
+ local index = string.find(self, searchString, position, true)
264
+ return index ~= nil
265
+ end
266
+
267
+ local function __TS__ClassExtends(target, base)
268
+ target.____super = base
269
+ local staticMetatable = setmetatable({__index = base}, base)
270
+ setmetatable(target, staticMetatable)
271
+ local baseMetatable = getmetatable(base)
272
+ if baseMetatable then
273
+ if type(baseMetatable.__index) == "function" then
274
+ staticMetatable.__index = baseMetatable.__index
275
+ end
276
+ if type(baseMetatable.__newindex) == "function" then
277
+ staticMetatable.__newindex = baseMetatable.__newindex
278
+ end
279
+ end
280
+ setmetatable(target.prototype, base.prototype)
281
+ if type(base.prototype.__index) == "function" then
282
+ target.prototype.__index = base.prototype.__index
283
+ end
284
+ if type(base.prototype.__newindex) == "function" then
285
+ target.prototype.__newindex = base.prototype.__newindex
286
+ end
287
+ if type(base.prototype.__tostring) == "function" then
288
+ target.prototype.__tostring = base.prototype.__tostring
289
+ end
290
+ end
291
+
292
+ local Error, RangeError, ReferenceError, SyntaxError, TypeError, URIError
293
+ do
294
+ local function getErrorStack(self, constructor)
295
+ if debug == nil then
296
+ return nil
297
+ end
298
+ local level = 1
299
+ while true do
300
+ local info = debug.getinfo(level, "f")
301
+ level = level + 1
302
+ if not info then
303
+ level = 1
304
+ break
305
+ elseif info.func == constructor then
306
+ break
307
+ end
308
+ end
309
+ if __TS__StringIncludes(_VERSION, "Lua 5.0") then
310
+ return debug.traceback(("[Level " .. tostring(level)) .. "]")
311
+ elseif _VERSION == "Lua 5.1" then
312
+ return string.sub(
313
+ debug.traceback("", level),
314
+ 2
315
+ )
316
+ else
317
+ return debug.traceback(nil, level)
318
+ end
319
+ end
320
+ local function wrapErrorToString(self, getDescription)
321
+ return function(self)
322
+ local description = getDescription(self)
323
+ local caller = debug.getinfo(3, "f")
324
+ local isClassicLua = __TS__StringIncludes(_VERSION, "Lua 5.0")
325
+ if isClassicLua or caller and caller.func ~= error then
326
+ return description
327
+ else
328
+ return (description .. "\n") .. tostring(self.stack)
329
+ end
330
+ end
331
+ end
332
+ local function initErrorClass(self, Type, name)
333
+ Type.name = name
334
+ return setmetatable(
335
+ Type,
336
+ {__call = function(____, _self, message) return __TS__New(Type, message) end}
337
+ )
338
+ end
339
+ local ____initErrorClass_1 = initErrorClass
340
+ local ____class_0 = __TS__Class()
341
+ ____class_0.name = ""
342
+ function ____class_0.prototype.____constructor(self, message)
343
+ if message == nil then
344
+ message = ""
345
+ end
346
+ self.message = message
347
+ self.name = "Error"
348
+ self.stack = getErrorStack(nil, __TS__New)
349
+ local metatable = getmetatable(self)
350
+ if metatable and not metatable.__errorToStringPatched then
351
+ metatable.__errorToStringPatched = true
352
+ metatable.__tostring = wrapErrorToString(nil, metatable.__tostring)
353
+ end
354
+ end
355
+ function ____class_0.prototype.__tostring(self)
356
+ return self.message ~= "" and (self.name .. ": ") .. self.message or self.name
357
+ end
358
+ Error = ____initErrorClass_1(nil, ____class_0, "Error")
359
+ local function createErrorClass(self, name)
360
+ local ____initErrorClass_3 = initErrorClass
361
+ local ____class_2 = __TS__Class()
362
+ ____class_2.name = ____class_2.name
363
+ __TS__ClassExtends(____class_2, Error)
364
+ function ____class_2.prototype.____constructor(self, ...)
365
+ ____class_2.____super.prototype.____constructor(self, ...)
366
+ self.name = name
367
+ end
368
+ return ____initErrorClass_3(nil, ____class_2, name)
369
+ end
370
+ RangeError = createErrorClass(nil, "RangeError")
371
+ ReferenceError = createErrorClass(nil, "ReferenceError")
372
+ SyntaxError = createErrorClass(nil, "SyntaxError")
373
+ TypeError = createErrorClass(nil, "TypeError")
374
+ URIError = createErrorClass(nil, "URIError")
375
+ end
376
+
377
+ return {
378
+ __TS__Promise = __TS__Promise,
379
+ __TS__New = __TS__New,
380
+ __TS__Class = __TS__Class,
381
+ __TS__StringSplit = __TS__StringSplit,
382
+ __TS__ArrayIsArray = __TS__ArrayIsArray,
383
+ Error = Error,
384
+ RangeError = RangeError,
385
+ ReferenceError = ReferenceError,
386
+ SyntaxError = SyntaxError,
387
+ TypeError = TypeError,
388
+ URIError = URIError
389
+ }
package/package.json CHANGED
@@ -1,22 +1,34 @@
1
1
  {
2
2
  "name": "@noita-ts/pollnet",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "files": [
5
- "index.lua",
6
- "index.d.ts",
5
+ "dist/**/*.{lua,d.ts}",
7
6
  "pollnet.dll",
8
- "pollnet-license.txt"
7
+ "LICENSE-pollnet"
9
8
  ],
10
- "main": "index",
11
9
  "type": "module",
12
- "types": "index.d.ts",
10
+ "main": "dist/index",
11
+ "types": "dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index"
16
+ },
17
+ "./async": {
18
+ "types": "./dist/async.d.ts",
19
+ "default": "./dist/async"
20
+ }
21
+ },
13
22
  "scripts": {
14
- "prepublishOnly": "tsc -p ."
23
+ "build": "tstl -p . && cp *.lua *.d.ts dist/",
24
+ "prepublishOnly": "rm -rf dist && npm run build"
15
25
  },
16
26
  "dependencies": {
17
- "@typescript-to-lua/language-extensions": "^1.19.0"
27
+ "@typescript-to-lua/language-extensions": "^1.19.0",
28
+ "lua-types": "^2.13.1"
18
29
  },
19
30
  "devDependencies": {
20
- "typescript": "^5.9.3"
31
+ "typescript": "^6.0.2",
32
+ "typescript-to-lua": "^1.36.0"
21
33
  }
22
34
  }
File without changes