@lango-project/lango-client 0.2.1 → 0.4.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/LICENSE +1 -0
- package/NOTICE +5 -1
- package/README.md +570 -906
- package/cli/.lango/localization.mjs +108 -0
- package/{dist/node → cli}/.lango/runtime.mjs +112 -19
- package/cli/.lango/vendor/i18next.LICENSE +21 -0
- package/cli/.lango/vendor/i18next.mjs +2434 -0
- package/cli/create.mjs +62 -0
- package/cli/create.mjs.map +1 -0
- package/dist/.lango/localization.mjs +108 -0
- package/dist/.lango/runtime.mjs +112 -19
- package/dist/.lango/vendor/i18next.LICENSE +21 -0
- package/dist/.lango/vendor/i18next.mjs +2434 -0
- package/dist/accordion.mjs +277 -0
- package/dist/accordion.mjs.map +1 -0
- package/dist/activities.mjs +185 -0
- package/dist/activities.mjs.map +1 -0
- package/dist/app.mjs +636 -0
- package/dist/app.mjs.map +1 -0
- package/dist/boot.mjs +24 -0
- package/dist/boot.mjs.map +1 -0
- package/dist/bootstrap-LICENSE +21 -0
- package/dist/bootstrap.min.css +6 -0
- package/dist/bootstrap.min.css.map +1 -0
- package/dist/button.mjs +77 -0
- package/dist/button.mjs.map +1 -0
- package/dist/chip.mjs +134 -0
- package/dist/chip.mjs.map +1 -0
- package/dist/client.css +95 -0
- package/dist/collections.mjs +77 -0
- package/dist/collections.mjs.map +1 -0
- package/dist/combo_box.mjs +408 -0
- package/dist/combo_box.mjs.map +1 -0
- package/dist/content.mjs +123 -0
- package/dist/content.mjs.map +1 -0
- package/dist/control.mjs +139 -0
- package/dist/control.mjs.map +1 -0
- package/dist/date_input.mjs +242 -0
- package/dist/date_input.mjs.map +1 -0
- package/dist/error_reporter.mjs +136 -0
- package/dist/error_reporter.mjs.map +1 -0
- package/dist/fields.mjs +454 -0
- package/dist/fields.mjs.map +1 -0
- package/dist/file_input.mjs +227 -0
- package/dist/file_input.mjs.map +1 -0
- package/dist/form.mjs +272 -0
- package/dist/form.mjs.map +1 -0
- package/dist/heartbeat.mjs +167 -254
- package/dist/heartbeat.mjs.map +1 -1
- package/dist/index.html +18 -0
- package/dist/indicators.mjs +127 -0
- package/dist/indicators.mjs.map +1 -0
- package/dist/input_changes.mjs +58 -0
- package/dist/input_changes.mjs.map +1 -0
- package/dist/input_group.mjs +38 -0
- package/dist/input_group.mjs.map +1 -0
- package/dist/layouts.mjs +195 -0
- package/dist/layouts.mjs.map +1 -0
- package/dist/library.mjs +130 -807
- package/dist/library.mjs.map +1 -1
- package/dist/longpoll.mjs +254 -0
- package/dist/longpoll.mjs.map +1 -0
- package/dist/main.mjs +138 -0
- package/dist/main.mjs.map +1 -0
- package/dist/markdown.mjs +61 -0
- package/dist/markdown.mjs.map +1 -0
- package/dist/menus.mjs +468 -0
- package/dist/menus.mjs.map +1 -0
- package/dist/navigation.mjs +260 -410
- package/dist/navigation.mjs.map +1 -1
- package/dist/numeric_input.mjs +181 -0
- package/dist/numeric_input.mjs.map +1 -0
- package/dist/otp_input.mjs +113 -0
- package/dist/otp_input.mjs.map +1 -0
- package/dist/presentations.mjs +852 -0
- package/dist/presentations.mjs.map +1 -0
- package/dist/renderer.mjs +293 -0
- package/dist/renderer.mjs.map +1 -0
- package/dist/rich_content.mjs +99 -0
- package/dist/rich_content.mjs.map +1 -0
- package/dist/tables.mjs +369 -0
- package/dist/tables.mjs.map +1 -0
- package/dist/tabs.mjs +205 -0
- package/dist/tabs.mjs.map +1 -0
- package/dist/templates.mjs +46 -0
- package/dist/templates.mjs.map +1 -0
- package/dist/vendor/DOMPurify-LICENSE +202 -0
- package/dist/vendor/dompurify.mjs +2540 -0
- package/dist/vendor/flatpickr-LICENSE.md +21 -0
- package/dist/vendor/flatpickr.min.css +13 -0
- package/dist/vendor/flatpickr.mjs +2340 -0
- package/dist/vendor/flatpickr.mjs.map +7 -0
- package/dist/vendor/marked-LICENSE.md +44 -0
- package/dist/vendor/marked.esm.js.map +7 -0
- package/dist/vendor/marked.mjs +85 -0
- package/dist/vendor/purify.es.mjs.map +1 -0
- package/dist/widgets.mjs +197 -0
- package/dist/widgets.mjs.map +1 -0
- package/docs/implementation.md +42 -0
- package/package.json +25 -43
- package/src/accordion.lango +198 -0
- package/src/activities.lango +132 -0
- package/src/app.lango +508 -0
- package/src/boot.lango +12 -0
- package/src/button.lango +49 -0
- package/src/chip.lango +94 -0
- package/src/collections.lango +46 -0
- package/src/combo_box.lango +298 -0
- package/src/content.lango +75 -0
- package/src/control.lango +100 -0
- package/src/create.lango +42 -0
- package/src/date_input.lango +215 -0
- package/src/error_reporter.lango +95 -0
- package/src/fields.lango +327 -0
- package/src/file_input.lango +175 -0
- package/src/form.lango +195 -0
- package/src/heartbeat.lango +136 -199
- package/src/indicators.lango +94 -0
- package/src/input_changes.lango +33 -0
- package/src/input_group.lango +22 -0
- package/src/layouts.lango +137 -0
- package/src/library.lango +194 -599
- package/src/longpoll.lango +187 -0
- package/src/main.lango +109 -0
- package/src/markdown.lango +48 -0
- package/src/menus.lango +336 -0
- package/src/navigation.lango +209 -299
- package/src/numeric_input.lango +131 -0
- package/src/otp_input.lango +83 -0
- package/src/presentations.lango +617 -0
- package/src/renderer.lango +288 -0
- package/src/rich_content.lango +66 -0
- package/src/tables.lango +271 -0
- package/src/tabs.lango +144 -0
- package/src/templates.lango +29 -0
- package/src/widgets.lango +141 -0
- package/web/client.css +95 -0
- package/web/index.html +18 -0
- package/dist/application.mjs +0 -429
- package/dist/application.mjs.map +0 -1
- package/dist/coordinator.mjs +0 -91
- package/dist/coordinator.mjs.map +0 -1
- package/dist/demo.mjs +0 -110
- package/dist/demo.mjs.map +0 -1
- package/dist/demo_controls.mjs +0 -59
- package/dist/demo_controls.mjs.map +0 -1
- package/dist/errors.mjs +0 -201
- package/dist/errors.mjs.map +0 -1
- package/dist/form_state.mjs +0 -266
- package/dist/form_state.mjs.map +0 -1
- package/dist/inheritance.mjs +0 -240
- package/dist/inheritance.mjs.map +0 -1
- package/dist/input_values.mjs +0 -65
- package/dist/input_values.mjs.map +0 -1
- package/dist/node/.lango/xmldom/conventions.js +0 -429
- package/dist/node/.lango/xmldom/dom-parser.js +0 -591
- package/dist/node/.lango/xmldom/dom.js +0 -3759
- package/dist/node/.lango/xmldom/entities.js +0 -2171
- package/dist/node/.lango/xmldom/errors.js +0 -205
- package/dist/node/.lango/xmldom/grammar.js +0 -559
- package/dist/node/.lango/xmldom/index.js +0 -41
- package/dist/node/.lango/xmldom/package.json +0 -1
- package/dist/node/.lango/xmldom/sax.js +0 -983
- package/dist/node/.lango/xmldom.LICENSE.md +0 -8
- package/dist/node/browser_host.mjs +0 -351
- package/dist/node/browser_host.mjs.map +0 -1
- package/dist/node/create_app.mjs +0 -118
- package/dist/node/create_app.mjs.map +0 -1
- package/dist/presentation.mjs +0 -89
- package/dist/presentation.mjs.map +0 -1
- package/dist/protocol.mjs +0 -706
- package/dist/protocol.mjs.map +0 -1
- package/dist/session.mjs +0 -471
- package/dist/session.mjs.map +0 -1
- package/dist/tokens.mjs +0 -298
- package/dist/tokens.mjs.map +0 -1
- package/examples/contacts.lango +0 -293
- package/examples/contacts_flow.lango +0 -174
- package/examples/contacts_store.lango +0 -109
- package/examples/contacts_store_test.lango +0 -65
- package/examples/demo.css +0 -87
- package/examples/demo_test.lango +0 -356
- package/examples/index.html +0 -32
- package/examples/pages.lango +0 -174
- package/examples/server.lango +0 -189
- package/examples/worker.lango +0 -142
- package/src/application.lango +0 -327
- package/src/browser_host.lango +0 -276
- package/src/coordinator.lango +0 -57
- package/src/demo.lango +0 -110
- package/src/demo_controls.lango +0 -53
- package/src/errors.lango +0 -149
- package/src/errors_test.lango +0 -157
- package/src/form_state.lango +0 -168
- package/src/heartbeat_test.lango +0 -479
- package/src/inheritance.lango +0 -167
- package/src/input_values.lango +0 -37
- package/src/logout_test.lango +0 -564
- package/src/navigation_test.lango +0 -556
- package/src/presentation.lango +0 -55
- package/src/protocol.lango +0 -787
- package/src/renderer_test.lango +0 -2047
- package/src/session.lango +0 -343
- package/src/session_test.lango +0 -455
- package/src/tabs_test.lango +0 -216
- package/src/tokens.lango +0 -215
- package/template/.vscode/extensions.json +0 -3
- package/template/.vscode/settings.json +0 -9
- package/template/README.md +0 -44
- package/template/gitignore +0 -4
- package/template/package.json +0 -22
- package/template/public/app.css +0 -10
- package/template/public/index.html +0 -24
- package/template/src/client.lango +0 -78
- package/template/src/pages.lango +0 -55
- package/template/src/server.lango +0 -24
- package/template/src/worker.lango +0 -77
- package/template/test/app.lango +0 -9
- package/tools/browser_runner.lango +0 -32
- package/tools/browser_test.lango +0 -343
- package/tools/create_app.lango +0 -88
- package/tools/create_app_test.lango +0 -43
- package/tools/starter_test.lango +0 -227
- /package/{dist/node → cli}/.lango/bignumber.mjs +0 -0
- /package/{dist → cli}/.lango/xmldom/conventions.js +0 -0
- /package/{dist → cli}/.lango/xmldom/dom-parser.js +0 -0
- /package/{dist → cli}/.lango/xmldom/dom.js +0 -0
- /package/{dist → cli}/.lango/xmldom/entities.js +0 -0
- /package/{dist → cli}/.lango/xmldom/errors.js +0 -0
- /package/{dist → cli}/.lango/xmldom/grammar.js +0 -0
- /package/{dist → cli}/.lango/xmldom/index.js +0 -0
- /package/{dist → cli}/.lango/xmldom/package.json +0 -0
- /package/{dist → cli}/.lango/xmldom/sax.js +0 -0
- /package/{dist → cli}/.lango/xmldom.LICENSE.md +0 -0
package/src/browser_host.lango
DELETED
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
import js "node:fs" as fs
|
|
2
|
-
import js "node:path" as path
|
|
3
|
-
import js "node:http" as http
|
|
4
|
-
import js "node:crypto" as crypto
|
|
5
|
-
import js "node:module" as modules
|
|
6
|
-
import js global fetch
|
|
7
|
-
import js global process
|
|
8
|
-
import js global Promise
|
|
9
|
-
import js global URL
|
|
10
|
-
import js "@lango-project/lango-api" as api
|
|
11
|
-
import js "@lango-project/lango-api/http-input" as input
|
|
12
|
-
import js "@lango-project/lango-api/rate-limit" as rates
|
|
13
|
-
|
|
14
|
-
export class BrowserHost
|
|
15
|
-
methods
|
|
16
|
-
start()
|
|
17
|
-
close()
|
|
18
|
-
|
|
19
|
-
BrowserHost(options)
|
|
20
|
-
@options = options
|
|
21
|
-
@bodyOptions = input/requestBodyOptions(options)
|
|
22
|
-
@rateLimiter = new rates/RateLimiter(options)
|
|
23
|
-
@root = path.resolve(options.appRoot)
|
|
24
|
-
@pages = options.pages
|
|
25
|
-
@port = options.port
|
|
26
|
-
@apiPort = options.apiPort
|
|
27
|
-
if @port == null
|
|
28
|
-
@port = 8080
|
|
29
|
-
if @apiPort == null
|
|
30
|
-
@apiPort = 8081
|
|
31
|
-
if !is_number(@port) or !is_number(@apiPort) or @port < 1 or @port > 65535 or @apiPort < 1 or @apiPort > 65535 or @port % 1 != 0 or @apiPort % 1 != 0 or @port == @apiPort
|
|
32
|
-
throw "UiHostRequiresDistinctPorts"
|
|
33
|
-
@assets = {
|
|
34
|
-
}
|
|
35
|
-
@server = null
|
|
36
|
-
@api = null
|
|
37
|
-
@closing = null
|
|
38
|
-
@starting = null
|
|
39
|
-
@signal = null
|
|
40
|
-
@closed = false
|
|
41
|
-
|
|
42
|
-
BrowserHost:start()
|
|
43
|
-
if @closed
|
|
44
|
-
throw "UiHostClosed"
|
|
45
|
-
if @starting != null
|
|
46
|
-
return @starting
|
|
47
|
-
@starting = launch()
|
|
48
|
-
return @starting
|
|
49
|
-
|
|
50
|
-
BrowserHost:launch()
|
|
51
|
-
options = @options
|
|
52
|
-
resolve = modules/createRequire(path.join(@root, "package.json"))
|
|
53
|
-
sdk = path.dirname(resolve.resolve("@lango-project/lango-client"))
|
|
54
|
-
files = ["library.mjs", "application.mjs", "session.mjs", "tokens.mjs", "heartbeat.mjs", "protocol.mjs", "inheritance.mjs", "coordinator.mjs", "navigation.mjs", "presentation.mjs", "input_values.mjs", "form_state.mjs", "errors.mjs", ".lango/runtime.mjs", ".lango/bignumber.mjs"]
|
|
55
|
-
for files as file
|
|
56
|
-
addAsset("/vendor/lango-client/${file}", path.join(sdk, file))
|
|
57
|
-
if options.assets != null
|
|
58
|
-
for options.assets as url: file
|
|
59
|
-
if url.startsWith("/vendor/")
|
|
60
|
-
throw "UiHostReservedAssetPath"
|
|
61
|
-
addAsset(url, path.resolve(@root, file))
|
|
62
|
-
@shell = fs.readFileSync(path.resolve(@root, options.shell))
|
|
63
|
-
state = path.join(@root, ".lango", "state")
|
|
64
|
-
fs.mkdirSync(state, {
|
|
65
|
-
recursive: true
|
|
66
|
-
})
|
|
67
|
-
keyFile = path.join(state, "jwt.key")
|
|
68
|
-
if !fs.existsSync(keyFile)
|
|
69
|
-
fs.writeFileSync(keyFile, crypto/randomBytes(32), {
|
|
70
|
-
mode: 384
|
|
71
|
-
flag: "wx"
|
|
72
|
-
})
|
|
73
|
-
keys = path.join(state, "keys.json")
|
|
74
|
-
key = fs.readFileSync(keyFile)
|
|
75
|
-
fs.writeFileSync(keys, to_json({
|
|
76
|
-
app: key.toString("base64")
|
|
77
|
-
}), {
|
|
78
|
-
mode: 384
|
|
79
|
-
})
|
|
80
|
-
@api = new api/Host({
|
|
81
|
-
applicationName: "lango-application"
|
|
82
|
-
appRoot: @root
|
|
83
|
-
stateDir: state
|
|
84
|
-
mode: "server"
|
|
85
|
-
host: "127.0.0.1"
|
|
86
|
-
port: @apiPort
|
|
87
|
-
workers: {
|
|
88
|
-
bodyLimit: @bodyOptions.bodyLimit
|
|
89
|
-
bodyTimeoutMs: @bodyOptions.bodyTimeoutMs
|
|
90
|
-
application: path.resolve(@root, options.worker)
|
|
91
|
-
workerFile: resolve.resolve("@lango-project/lango-api/worker-entry")
|
|
92
|
-
}
|
|
93
|
-
jwt: {
|
|
94
|
-
issuer: "lango-application"
|
|
95
|
-
audience: "lango-browser"
|
|
96
|
-
activeKeyId: "app"
|
|
97
|
-
keysFile: keys
|
|
98
|
-
}
|
|
99
|
-
})
|
|
100
|
-
return @api.start().then(()
|
|
101
|
-
if @closed
|
|
102
|
-
throw "UiHostClosed"
|
|
103
|
-
return listen()
|
|
104
|
-
).catch((error)
|
|
105
|
-
return close().then(()
|
|
106
|
-
capture error
|
|
107
|
-
throw error
|
|
108
|
-
)
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
BrowserHost:addAsset(url, file)
|
|
112
|
-
if !is_string(url) or !url.startsWith("/") or url.includes("?") or url.includes("#") or url.includes("\\")
|
|
113
|
-
throw "UiHostInvalidAssetPath"
|
|
114
|
-
if url in @assets
|
|
115
|
-
throw "UiHostDuplicateAsset"
|
|
116
|
-
type = "text/javascript; charset=utf-8"
|
|
117
|
-
if file.endsWith(".css")
|
|
118
|
-
type = "text/css; charset=utf-8"
|
|
119
|
-
content = fs.readFileSync(file)
|
|
120
|
-
hash = crypto/createHash("sha256")
|
|
121
|
-
hash.update(content)
|
|
122
|
-
@assets[url] = {
|
|
123
|
-
content: content
|
|
124
|
-
type: type
|
|
125
|
-
etag: "\"${hash.digest('hex')}\""
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
BrowserHost:listen()
|
|
129
|
-
server = new http/Server((req, res)
|
|
130
|
-
serve(req, res)
|
|
131
|
-
)
|
|
132
|
-
@server = server
|
|
133
|
-
pending = new Promise((resolve, reject)
|
|
134
|
-
server = @server
|
|
135
|
-
server.once("error", reject)
|
|
136
|
-
server.listen(@port, "127.0.0.1", ()
|
|
137
|
-
capture resolve
|
|
138
|
-
signal = ()
|
|
139
|
-
signalClose()
|
|
140
|
-
@signal = signal
|
|
141
|
-
process.once("SIGINT", @signal)
|
|
142
|
-
process.once("SIGTERM", @signal)
|
|
143
|
-
context log
|
|
144
|
-
log.info("Open http://localhost:${@port}/")
|
|
145
|
-
resolve(null)
|
|
146
|
-
)
|
|
147
|
-
)
|
|
148
|
-
return pending
|
|
149
|
-
|
|
150
|
-
BrowserHost:serve(req, res)
|
|
151
|
-
try
|
|
152
|
-
url = new URL(req.url, "http://localhost")
|
|
153
|
-
pathname = url.pathname
|
|
154
|
-
if req.method == "POST" and (pathname.startsWith("/app/") or pathname.startsWith("/_lango/"))
|
|
155
|
-
return receive(req, res)
|
|
156
|
-
if req.method != "GET"
|
|
157
|
-
res.writeHead(404)
|
|
158
|
-
res.end("Not found")
|
|
159
|
-
return null
|
|
160
|
-
if pathname in @assets
|
|
161
|
-
asset = @assets[pathname]
|
|
162
|
-
res.setHeader("Content-Type", asset.type)
|
|
163
|
-
res.setHeader("Cache-Control", "public, max-age=0, must-revalidate")
|
|
164
|
-
res.setHeader("ETag", asset.etag)
|
|
165
|
-
if req.headers["if-none-match"] == asset.etag
|
|
166
|
-
res.writeHead(304)
|
|
167
|
-
res.end()
|
|
168
|
-
else
|
|
169
|
-
res.writeHead(200)
|
|
170
|
-
res.end(asset.content)
|
|
171
|
-
return null
|
|
172
|
-
if pathname == "/" or @pages.match(pathname) != null
|
|
173
|
-
res.writeHead(200, {
|
|
174
|
-
"Content-Type": "text/html; charset=utf-8"
|
|
175
|
-
"Cache-Control": "no-store"
|
|
176
|
-
})
|
|
177
|
-
res.end(@shell)
|
|
178
|
-
return null
|
|
179
|
-
res.writeHead(404)
|
|
180
|
-
res.end("Not found")
|
|
181
|
-
catch error
|
|
182
|
-
res.writeHead(400)
|
|
183
|
-
res.end("Invalid request")
|
|
184
|
-
return null
|
|
185
|
-
|
|
186
|
-
BrowserHost:receive(req, res)
|
|
187
|
-
retry = @rateLimiter.admit(req.socket.remoteAddress)
|
|
188
|
-
if retry > 0
|
|
189
|
-
return input/rejectHttpRequest(req, res, 429, "TooManyRequests", retry, null)
|
|
190
|
-
completed = (body)
|
|
191
|
-
capture req
|
|
192
|
-
capture res
|
|
193
|
-
forward(req, res, body)
|
|
194
|
-
rejected = (status, error)
|
|
195
|
-
capture res
|
|
196
|
-
res.writeHead(status, {
|
|
197
|
-
"Content-Type": "application/json; charset=utf-8"
|
|
198
|
-
"Cache-Control": "no-store"
|
|
199
|
-
})
|
|
200
|
-
res.end(to_json({
|
|
201
|
-
error: error
|
|
202
|
-
}))
|
|
203
|
-
input/readRequestBody(req, res, @bodyOptions, completed, rejected)
|
|
204
|
-
return null
|
|
205
|
-
|
|
206
|
-
BrowserHost:forward(req, res, body)
|
|
207
|
-
headers = {
|
|
208
|
-
"Content-Type": "application/json"
|
|
209
|
-
}
|
|
210
|
-
if is_string(req.headers.authorization)
|
|
211
|
-
headers.Authorization = req.headers.authorization
|
|
212
|
-
return fetch("http://127.0.0.1:${@apiPort}${req.url}", {
|
|
213
|
-
method: "POST"
|
|
214
|
-
headers: headers
|
|
215
|
-
body: body
|
|
216
|
-
}).then((upstream)
|
|
217
|
-
capture res
|
|
218
|
-
return readUpstream(upstream, res)
|
|
219
|
-
).catch((error)
|
|
220
|
-
capture res
|
|
221
|
-
res.writeHead(502, {
|
|
222
|
-
"Content-Type": "application/json"
|
|
223
|
-
})
|
|
224
|
-
res.end(to_json({
|
|
225
|
-
error: "UpstreamUnavailable"
|
|
226
|
-
}))
|
|
227
|
-
)
|
|
228
|
-
|
|
229
|
-
BrowserHost:readUpstream(upstream, res)
|
|
230
|
-
return upstream.text().then((text)
|
|
231
|
-
capture upstream
|
|
232
|
-
capture res
|
|
233
|
-
relay(res, upstream, text)
|
|
234
|
-
)
|
|
235
|
-
|
|
236
|
-
BrowserHost:relay(res, upstream, text)
|
|
237
|
-
for ["Content-Type", "Cache-Control", "X-Lango-Token", "WWW-Authenticate", "Retry-After"] as name
|
|
238
|
-
value = upstream.headers.get(name)
|
|
239
|
-
if value != null
|
|
240
|
-
res.setHeader(name, value)
|
|
241
|
-
res.writeHead(upstream.status)
|
|
242
|
-
res.end(text)
|
|
243
|
-
return null
|
|
244
|
-
|
|
245
|
-
BrowserHost:close()
|
|
246
|
-
if @closing != null
|
|
247
|
-
return @closing
|
|
248
|
-
@closed = true
|
|
249
|
-
if @signal != null
|
|
250
|
-
process.removeListener("SIGINT", @signal)
|
|
251
|
-
process.removeListener("SIGTERM", @signal)
|
|
252
|
-
@closing = stop()
|
|
253
|
-
return @closing
|
|
254
|
-
|
|
255
|
-
BrowserHost:signalClose()
|
|
256
|
-
return close().catch((error)
|
|
257
|
-
context log
|
|
258
|
-
log.err("Browser host shutdown failed: ${error}")
|
|
259
|
-
process.exitCode = 1
|
|
260
|
-
)
|
|
261
|
-
|
|
262
|
-
BrowserHost:stop()
|
|
263
|
-
pending = new Promise((resolve)
|
|
264
|
-
server = @server
|
|
265
|
-
if server == null or !server.listening
|
|
266
|
-
resolve(null)
|
|
267
|
-
else
|
|
268
|
-
server.close(()
|
|
269
|
-
capture resolve
|
|
270
|
-
resolve(null)
|
|
271
|
-
)
|
|
272
|
-
)
|
|
273
|
-
return pending.finally(()
|
|
274
|
-
if @api != null
|
|
275
|
-
return @api.close()
|
|
276
|
-
)
|
package/src/coordinator.lango
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import js global Promise
|
|
2
|
-
|
|
3
|
-
export class Coordinator
|
|
4
|
-
methods
|
|
5
|
-
reserve(resources)
|
|
6
|
-
release(reservation)
|
|
7
|
-
|
|
8
|
-
Coordinator()
|
|
9
|
-
@reservations = []
|
|
10
|
-
|
|
11
|
-
Coordinator:reserve(resources)
|
|
12
|
-
waiting = []
|
|
13
|
-
for @reservations as previous
|
|
14
|
-
if overlaps(resources, previous.resources)
|
|
15
|
-
waiting.add(previous.done.promise)
|
|
16
|
-
reservation = {
|
|
17
|
-
resources: resources
|
|
18
|
-
ready: Promise/all(waiting)
|
|
19
|
-
done: Promise/withResolvers()
|
|
20
|
-
released: false
|
|
21
|
-
}
|
|
22
|
-
@reservations.add(reservation)
|
|
23
|
-
return reservation
|
|
24
|
-
|
|
25
|
-
Coordinator:release(reservation)
|
|
26
|
-
if reservation.released
|
|
27
|
-
return null
|
|
28
|
-
reservation.released = true
|
|
29
|
-
index = @reservations.indexOf(reservation)
|
|
30
|
-
if index >= 0
|
|
31
|
-
@reservations.splice(index, 1)
|
|
32
|
-
reservation.done.resolve(null)
|
|
33
|
-
return null
|
|
34
|
-
|
|
35
|
-
overlaps(first, second)
|
|
36
|
-
for first.writes as write
|
|
37
|
-
for second.reads as read
|
|
38
|
-
if related(write, read)
|
|
39
|
-
return true
|
|
40
|
-
for second.writes as other
|
|
41
|
-
if related(write, other)
|
|
42
|
-
return true
|
|
43
|
-
for first.reads as read
|
|
44
|
-
for second.writes as write
|
|
45
|
-
if related(read, write)
|
|
46
|
-
return true
|
|
47
|
-
return false
|
|
48
|
-
|
|
49
|
-
related(first, second)
|
|
50
|
-
count = first.length
|
|
51
|
-
if second.length < count
|
|
52
|
-
count = second.length
|
|
53
|
-
for first as index: name
|
|
54
|
-
if index < count
|
|
55
|
-
if name != second[index]
|
|
56
|
-
return false
|
|
57
|
-
return true
|
package/src/demo.lango
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import js global document
|
|
2
|
-
import js global window
|
|
3
|
-
import "./navigation"
|
|
4
|
-
class Navigation
|
|
5
|
-
import "./application"
|
|
6
|
-
class Application
|
|
7
|
-
import "./demo_controls"
|
|
8
|
-
demoTypes()
|
|
9
|
-
class DemoErrors
|
|
10
|
-
|
|
11
|
-
global demo = startDemo()
|
|
12
|
-
|
|
13
|
-
startDemo()
|
|
14
|
-
root = document.getElementById("app")
|
|
15
|
-
application = new Application(document, root, {
|
|
16
|
-
type: "Form"
|
|
17
|
-
name: "page"
|
|
18
|
-
classes: ["demo-theme"]
|
|
19
|
-
style: {
|
|
20
|
-
"--accent-color": "#0f766e"
|
|
21
|
-
}
|
|
22
|
-
controls: [{
|
|
23
|
-
type: "Value"
|
|
24
|
-
name: "url"
|
|
25
|
-
value: ""
|
|
26
|
-
}, {
|
|
27
|
-
type: "Value"
|
|
28
|
-
name: "template"
|
|
29
|
-
value: null
|
|
30
|
-
}, {
|
|
31
|
-
type: "Container"
|
|
32
|
-
name: "content"
|
|
33
|
-
controls: []
|
|
34
|
-
}]
|
|
35
|
-
}, {
|
|
36
|
-
bootstrapPath: "/_lango/start"
|
|
37
|
-
types: demoTypes()
|
|
38
|
-
window: window
|
|
39
|
-
errors: new DemoErrors(document.getElementById("form-status"))
|
|
40
|
-
})
|
|
41
|
-
page = application.control
|
|
42
|
-
urlField = page.controls[0]
|
|
43
|
-
templateField = page.controls[1]
|
|
44
|
-
changed = (event)
|
|
45
|
-
capture application
|
|
46
|
-
capture urlField
|
|
47
|
-
urlField.setValue(event.url)
|
|
48
|
-
session = application.session("page")
|
|
49
|
-
return session.send("/app/url", "url", null)
|
|
50
|
-
canLeave = (event)
|
|
51
|
-
capture application
|
|
52
|
-
if event.source == "refresh"
|
|
53
|
-
return true
|
|
54
|
-
return application.confirmDiscard(window)
|
|
55
|
-
navigation = new Navigation(window, {
|
|
56
|
-
rootRedirect: "/profile"
|
|
57
|
-
onUrl: changed
|
|
58
|
-
beforeNavigate: canLeave
|
|
59
|
-
})
|
|
60
|
-
opening = navigation.start()
|
|
61
|
-
opening.catch((error)
|
|
62
|
-
context log
|
|
63
|
-
log.err(error)
|
|
64
|
-
)
|
|
65
|
-
button = document.getElementById("logout")
|
|
66
|
-
status = document.getElementById("session-status")
|
|
67
|
-
button.addEventListener("click", ()
|
|
68
|
-
capture application
|
|
69
|
-
capture navigation
|
|
70
|
-
capture templateField
|
|
71
|
-
capture button
|
|
72
|
-
capture status
|
|
73
|
-
logoutDemo(application, navigation, templateField, button, status)
|
|
74
|
-
)
|
|
75
|
-
return {
|
|
76
|
-
application: application
|
|
77
|
-
navigation: navigation
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
logoutDemo(application, navigation, templateField, button, status)
|
|
81
|
-
if !application.confirmDiscard(window)
|
|
82
|
-
return null
|
|
83
|
-
showLogoutStatus(button, status, "Logging out...", true)
|
|
84
|
-
return application.logout().then((token)
|
|
85
|
-
capture navigation
|
|
86
|
-
capture templateField
|
|
87
|
-
capture button
|
|
88
|
-
capture status
|
|
89
|
-
templateField.setValue(null)
|
|
90
|
-
return reloadAfterLogout(navigation, button, status)
|
|
91
|
-
).catch((error)
|
|
92
|
-
capture button
|
|
93
|
-
capture status
|
|
94
|
-
showLogoutStatus(button, status, "Logout failed. Retry, or reload if the server already ended the session.", false)
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
reloadAfterLogout(navigation, button, status)
|
|
98
|
-
return navigation.refresh().then(()
|
|
99
|
-
capture button
|
|
100
|
-
capture status
|
|
101
|
-
showLogoutStatus(button, status, "A new anonymous session is ready.", false)
|
|
102
|
-
).catch((error)
|
|
103
|
-
capture button
|
|
104
|
-
capture status
|
|
105
|
-
showLogoutStatus(button, status, "Session restarted, but page loading failed. Reload to retry.", false)
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
showLogoutStatus(button, status, text, busy)
|
|
109
|
-
button.disabled = busy
|
|
110
|
-
status.textContent = text
|
package/src/demo_controls.lango
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import "./library"
|
|
2
|
-
class Control
|
|
3
|
-
class Types
|
|
4
|
-
|
|
5
|
-
export demoTypes()
|
|
6
|
-
|
|
7
|
-
export class DemoErrors
|
|
8
|
-
methods
|
|
9
|
-
clear()
|
|
10
|
-
error(error)
|
|
11
|
-
|
|
12
|
-
DemoErrors(element)
|
|
13
|
-
@element = element
|
|
14
|
-
|
|
15
|
-
DemoErrors:clear()
|
|
16
|
-
@element.textContent = ""
|
|
17
|
-
|
|
18
|
-
DemoErrors:error(error)
|
|
19
|
-
text = "The request failed. Please try again."
|
|
20
|
-
if error == "UiValidationFailed"
|
|
21
|
-
text = "Please correct the highlighted fields before saving."
|
|
22
|
-
@element.textContent = text
|
|
23
|
-
|
|
24
|
-
demoTypes()
|
|
25
|
-
types = new Types({
|
|
26
|
-
classes: {
|
|
27
|
-
Form: ["demo-form"]
|
|
28
|
-
Text: ["demo-input"]
|
|
29
|
-
Select: ["demo-input"]
|
|
30
|
-
Checkbox: ["demo-checkbox"]
|
|
31
|
-
Button: ["demo-button"]
|
|
32
|
-
Label: ["demo-label"]
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
types.registerType("Label", Label)
|
|
36
|
-
return types
|
|
37
|
-
|
|
38
|
-
class Label : Control
|
|
39
|
-
methods
|
|
40
|
-
setValue(value)
|
|
41
|
-
|
|
42
|
-
Label(document, definition, types)
|
|
43
|
-
super(document, definition, types, {
|
|
44
|
-
tag: "p"
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
Label:setValue(value)
|
|
48
|
-
super.setValue(value)
|
|
49
|
-
text = value
|
|
50
|
-
if text == null
|
|
51
|
-
text = ""
|
|
52
|
-
@element.textContent = text
|
|
53
|
-
return null
|
package/src/errors.lango
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import js global Promise
|
|
2
|
-
import js global performance
|
|
3
|
-
import js global setTimeout
|
|
4
|
-
import js global clearTimeout
|
|
5
|
-
import js global fetch
|
|
6
|
-
import js global AbortSignal
|
|
7
|
-
|
|
8
|
-
export class ErrorReporter
|
|
9
|
-
methods
|
|
10
|
-
error(error)
|
|
11
|
-
clear()
|
|
12
|
-
report(source, code = "UnexpectedError")
|
|
13
|
-
flush()
|
|
14
|
-
dispose()
|
|
15
|
-
|
|
16
|
-
ErrorReporter(options)
|
|
17
|
-
@window = options.window
|
|
18
|
-
@transport = options.transport
|
|
19
|
-
if @transport == null
|
|
20
|
-
@transport = new ReportTransport()
|
|
21
|
-
@pending = []
|
|
22
|
-
@timer = null
|
|
23
|
-
@running = null
|
|
24
|
-
@disposed = false
|
|
25
|
-
@until = 0
|
|
26
|
-
@sent = 0
|
|
27
|
-
onError = (event)
|
|
28
|
-
report("window")
|
|
29
|
-
onRejection = (event)
|
|
30
|
-
report("promise")
|
|
31
|
-
@onError = onError
|
|
32
|
-
@onRejection = onRejection
|
|
33
|
-
if @window != null
|
|
34
|
-
@window.addEventListener("error", @onError)
|
|
35
|
-
@window.addEventListener("unhandledrejection", @onRejection)
|
|
36
|
-
|
|
37
|
-
ErrorReporter:error(error)
|
|
38
|
-
code = "UnexpectedError"
|
|
39
|
-
if is_string(error)
|
|
40
|
-
if error == "UiValidationFailed" or error == "UiSessionDisposed"
|
|
41
|
-
return null
|
|
42
|
-
if error == "UiProtocolUnsupported"
|
|
43
|
-
code = "UiProtocolUnsupported"
|
|
44
|
-
if error.startsWith("UiHttpError:")
|
|
45
|
-
code = "UiHttpError"
|
|
46
|
-
return report("ui", code)
|
|
47
|
-
|
|
48
|
-
ErrorReporter:clear()
|
|
49
|
-
return null
|
|
50
|
-
|
|
51
|
-
ErrorReporter:report(source, code = "UnexpectedError")
|
|
52
|
-
if @disposed
|
|
53
|
-
return null
|
|
54
|
-
sources = ["window", "promise", "ui"]
|
|
55
|
-
codes = ["UnexpectedError", "UiProtocolUnsupported", "UiHttpError"]
|
|
56
|
-
origin = source
|
|
57
|
-
category = code
|
|
58
|
-
if !sources.includes(origin)
|
|
59
|
-
origin = "ui"
|
|
60
|
-
if !codes.includes(category)
|
|
61
|
-
category = "UnexpectedError"
|
|
62
|
-
for @pending as entry
|
|
63
|
-
if entry.source == origin and entry.code == category
|
|
64
|
-
if entry.count < 100
|
|
65
|
-
entry.count = entry.count + 1
|
|
66
|
-
schedule()
|
|
67
|
-
return null
|
|
68
|
-
@pending.add({
|
|
69
|
-
version: 1
|
|
70
|
-
source: origin
|
|
71
|
-
code: category
|
|
72
|
-
count: 1
|
|
73
|
-
})
|
|
74
|
-
schedule()
|
|
75
|
-
return null
|
|
76
|
-
|
|
77
|
-
ErrorReporter:schedule()
|
|
78
|
-
if @disposed or @timer != null or @running != null or @pending.length == 0
|
|
79
|
-
return null
|
|
80
|
-
send = ()
|
|
81
|
-
flush()
|
|
82
|
-
@timer = setTimeout(send, 1000)
|
|
83
|
-
return null
|
|
84
|
-
|
|
85
|
-
ErrorReporter:flush()
|
|
86
|
-
clearTimeout(@timer)
|
|
87
|
-
@timer = null
|
|
88
|
-
if @disposed
|
|
89
|
-
return Promise/resolve(null)
|
|
90
|
-
if @running != null
|
|
91
|
-
return @running
|
|
92
|
-
now = performance.now()
|
|
93
|
-
if now >= @until
|
|
94
|
-
@until = now + 60000
|
|
95
|
-
@sent = 0
|
|
96
|
-
reports = @pending
|
|
97
|
-
@pending = []
|
|
98
|
-
pending = []
|
|
99
|
-
for reports as entry
|
|
100
|
-
if @sent < 10
|
|
101
|
-
@sent = @sent + 1
|
|
102
|
-
pending.add(sendReport(@transport, entry))
|
|
103
|
-
joined = Promise/all(pending)
|
|
104
|
-
running = joined.finally(()
|
|
105
|
-
@running = null
|
|
106
|
-
schedule()
|
|
107
|
-
)
|
|
108
|
-
@running = running
|
|
109
|
-
return @running
|
|
110
|
-
|
|
111
|
-
sendReport(transport, entry)
|
|
112
|
-
return Promise/resolve().then(()
|
|
113
|
-
capture transport
|
|
114
|
-
capture entry
|
|
115
|
-
return transport.send(entry)
|
|
116
|
-
).catch((error)
|
|
117
|
-
return null
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
ErrorReporter:dispose()
|
|
121
|
-
@disposed = true
|
|
122
|
-
clearTimeout(@timer)
|
|
123
|
-
@timer = null
|
|
124
|
-
@pending = []
|
|
125
|
-
if @window != null
|
|
126
|
-
@window.removeEventListener("error", @onError)
|
|
127
|
-
@window.removeEventListener("unhandledrejection", @onRejection)
|
|
128
|
-
return null
|
|
129
|
-
|
|
130
|
-
class ReportTransport
|
|
131
|
-
methods
|
|
132
|
-
send(report)
|
|
133
|
-
|
|
134
|
-
ReportTransport:send(report)
|
|
135
|
-
signal = AbortSignal/timeout(5000)
|
|
136
|
-
return fetch("/_lango/client-error", {
|
|
137
|
-
method: "POST"
|
|
138
|
-
headers: {
|
|
139
|
-
"Content-Type": "application/json"
|
|
140
|
-
}
|
|
141
|
-
credentials: "omit"
|
|
142
|
-
cache: "no-store"
|
|
143
|
-
referrerPolicy: "no-referrer"
|
|
144
|
-
redirect: "error"
|
|
145
|
-
signal: signal
|
|
146
|
-
body: to_json(report)
|
|
147
|
-
}).then((response)
|
|
148
|
-
return null
|
|
149
|
-
)
|