@lango-project/lango-client 0.0.0-stage → 0.2.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 +200 -0
- package/NOTICE +2 -0
- package/README.md +877 -2
- package/dist/.lango/bignumber.mjs +3119 -0
- package/dist/.lango/runtime.mjs +607 -0
- package/dist/.lango/xmldom/conventions.js +429 -0
- package/dist/.lango/xmldom/dom-parser.js +591 -0
- package/dist/.lango/xmldom/dom.js +3759 -0
- package/dist/.lango/xmldom/entities.js +2171 -0
- package/dist/.lango/xmldom/errors.js +205 -0
- package/dist/.lango/xmldom/grammar.js +559 -0
- package/dist/.lango/xmldom/index.js +41 -0
- package/dist/.lango/xmldom/package.json +1 -0
- package/dist/.lango/xmldom/sax.js +983 -0
- package/dist/.lango/xmldom.LICENSE.md +8 -0
- package/dist/application.mjs +429 -0
- package/dist/application.mjs.map +1 -0
- package/dist/coordinator.mjs +91 -0
- package/dist/coordinator.mjs.map +1 -0
- package/dist/demo.mjs +110 -0
- package/dist/demo.mjs.map +1 -0
- package/dist/demo_controls.mjs +59 -0
- package/dist/demo_controls.mjs.map +1 -0
- package/dist/errors.mjs +201 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/form_state.mjs +266 -0
- package/dist/form_state.mjs.map +1 -0
- package/dist/heartbeat.mjs +330 -0
- package/dist/heartbeat.mjs.map +1 -0
- package/dist/inheritance.mjs +240 -0
- package/dist/inheritance.mjs.map +1 -0
- package/dist/input_values.mjs +65 -0
- package/dist/input_values.mjs.map +1 -0
- package/dist/library.mjs +792 -0
- package/dist/library.mjs.map +1 -0
- package/dist/navigation.mjs +466 -0
- package/dist/navigation.mjs.map +1 -0
- package/dist/node/.lango/bignumber.mjs +3119 -0
- package/dist/node/.lango/runtime.mjs +609 -0
- package/dist/node/.lango/xmldom/conventions.js +429 -0
- package/dist/node/.lango/xmldom/dom-parser.js +591 -0
- package/dist/node/.lango/xmldom/dom.js +3759 -0
- package/dist/node/.lango/xmldom/entities.js +2171 -0
- package/dist/node/.lango/xmldom/errors.js +205 -0
- package/dist/node/.lango/xmldom/grammar.js +559 -0
- package/dist/node/.lango/xmldom/index.js +41 -0
- package/dist/node/.lango/xmldom/package.json +1 -0
- package/dist/node/.lango/xmldom/sax.js +983 -0
- package/dist/node/.lango/xmldom.LICENSE.md +8 -0
- package/dist/node/browser_host.mjs +351 -0
- package/dist/node/browser_host.mjs.map +1 -0
- package/dist/node/create_app.mjs +118 -0
- package/dist/node/create_app.mjs.map +1 -0
- package/dist/presentation.mjs +89 -0
- package/dist/presentation.mjs.map +1 -0
- package/dist/protocol.mjs +706 -0
- package/dist/protocol.mjs.map +1 -0
- package/dist/session.mjs +431 -0
- package/dist/session.mjs.map +1 -0
- package/dist/tokens.mjs +298 -0
- package/dist/tokens.mjs.map +1 -0
- package/examples/contacts.lango +302 -0
- package/examples/contacts_flow.lango +174 -0
- package/examples/contacts_store.lango +109 -0
- package/examples/contacts_store_test.lango +65 -0
- package/examples/demo.css +72 -0
- package/examples/demo_test.lango +356 -0
- package/examples/index.html +28 -0
- package/examples/pages.lango +180 -0
- package/examples/server.lango +189 -0
- package/examples/worker.lango +142 -0
- package/package.json +64 -4
- package/src/application.lango +327 -0
- package/src/browser_host.lango +276 -0
- package/src/coordinator.lango +57 -0
- package/src/demo.lango +110 -0
- package/src/demo_controls.lango +53 -0
- package/src/errors.lango +149 -0
- package/src/errors_test.lango +157 -0
- package/src/form_state.lango +168 -0
- package/src/heartbeat.lango +230 -0
- package/src/heartbeat_test.lango +479 -0
- package/src/inheritance.lango +167 -0
- package/src/input_values.lango +37 -0
- package/src/library.lango +571 -0
- package/src/logout_test.lango +564 -0
- package/src/navigation.lango +309 -0
- package/src/navigation_test.lango +556 -0
- package/src/presentation.lango +55 -0
- package/src/protocol.lango +787 -0
- package/src/renderer_test.lango +1986 -0
- package/src/session.lango +313 -0
- package/src/session_test.lango +455 -0
- package/src/tabs_test.lango +216 -0
- package/src/tokens.lango +215 -0
- package/template/.vscode/extensions.json +3 -0
- package/template/.vscode/settings.json +9 -0
- package/template/README.md +40 -0
- package/template/gitignore +4 -0
- package/template/package.json +22 -0
- package/template/public/app.css +4 -0
- package/template/public/index.html +24 -0
- package/template/src/client.lango +78 -0
- package/template/src/pages.lango +55 -0
- package/template/src/server.lango +24 -0
- package/template/src/worker.lango +77 -0
- package/template/test/app.lango +9 -0
- package/tools/create_app.lango +88 -0
- package/tools/create_app_test.lango +43 -0
- package/tools/starter_test.lango +227 -0
package/src/demo.lango
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
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
|
|
@@ -0,0 +1,53 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
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
|
+
)
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import js global Promise
|
|
2
|
+
import js global globalThis as host
|
|
3
|
+
import "./errors"
|
|
4
|
+
class ErrorReporter
|
|
5
|
+
|
|
6
|
+
export main(args)
|
|
7
|
+
|
|
8
|
+
class Recorder
|
|
9
|
+
properties
|
|
10
|
+
reports
|
|
11
|
+
fail
|
|
12
|
+
methods
|
|
13
|
+
send(report)
|
|
14
|
+
|
|
15
|
+
Recorder()
|
|
16
|
+
@reports = []
|
|
17
|
+
@fail = false
|
|
18
|
+
|
|
19
|
+
Recorder:send(report)
|
|
20
|
+
@reports.add(from_json(to_json(report)))
|
|
21
|
+
if @fail
|
|
22
|
+
throw "Private transport detail"
|
|
23
|
+
return Promise/resolve(null)
|
|
24
|
+
|
|
25
|
+
class Window
|
|
26
|
+
properties
|
|
27
|
+
handlers
|
|
28
|
+
methods
|
|
29
|
+
addEventListener(name, callback)
|
|
30
|
+
removeEventListener(name, callback)
|
|
31
|
+
emit(name, event)
|
|
32
|
+
|
|
33
|
+
Window()
|
|
34
|
+
@handlers = {
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Window:addEventListener(name, callback)
|
|
38
|
+
@handlers[name] = callback
|
|
39
|
+
|
|
40
|
+
Window:removeEventListener(name, callback)
|
|
41
|
+
assert @handlers[name] == callback
|
|
42
|
+
@handlers[name] = null
|
|
43
|
+
|
|
44
|
+
Window:emit(name, event)
|
|
45
|
+
callback = @handlers[name]
|
|
46
|
+
callback(event)
|
|
47
|
+
|
|
48
|
+
privacy()
|
|
49
|
+
window = new Window()
|
|
50
|
+
recorder = new Recorder()
|
|
51
|
+
reporter = new ErrorReporter({
|
|
52
|
+
window: window
|
|
53
|
+
transport: recorder
|
|
54
|
+
})
|
|
55
|
+
raw = {
|
|
56
|
+
message: "secret-token private@example.com"
|
|
57
|
+
stack: "/private?password=secret"
|
|
58
|
+
token: "secret-token"
|
|
59
|
+
}
|
|
60
|
+
for range(120) as index
|
|
61
|
+
reporter.error(raw)
|
|
62
|
+
reporter.error("UiValidationFailed")
|
|
63
|
+
reporter.error("UiHttpError: 500: secret-token")
|
|
64
|
+
window.emit("error", raw)
|
|
65
|
+
window.emit("unhandledrejection", raw)
|
|
66
|
+
reporter.report("private@example.com", "secret-token")
|
|
67
|
+
return reporter.flush().then(()
|
|
68
|
+
capture recorder
|
|
69
|
+
capture reporter
|
|
70
|
+
capture window
|
|
71
|
+
assert recorder.reports.length == 4
|
|
72
|
+
assert recorder.reports[0].count == 100
|
|
73
|
+
assert recorder.reports[0].code == "UnexpectedError"
|
|
74
|
+
assert recorder.reports[1].code == "UiHttpError"
|
|
75
|
+
encoded = to_json(recorder.reports)
|
|
76
|
+
assert !encoded.includes("secret")
|
|
77
|
+
assert !encoded.includes("private")
|
|
78
|
+
assert !encoded.includes("stack")
|
|
79
|
+
reporter.dispose()
|
|
80
|
+
assert window.handlers.error == null
|
|
81
|
+
assert window.handlers.unhandledrejection == null
|
|
82
|
+
reporter.error("UiProtocolUnsupported")
|
|
83
|
+
return reporter.flush()
|
|
84
|
+
).then(()
|
|
85
|
+
capture recorder
|
|
86
|
+
assert recorder.reports.length == 4
|
|
87
|
+
println("PASS reporter batches counts, never retains raw error fields and detaches on disposal")
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
budget()
|
|
91
|
+
recorder = new Recorder()
|
|
92
|
+
recorder.fail = true
|
|
93
|
+
reporter = new ErrorReporter({
|
|
94
|
+
transport: recorder
|
|
95
|
+
})
|
|
96
|
+
reporter.error("UiProtocolUnsupported")
|
|
97
|
+
return reporter.flush().then(()
|
|
98
|
+
capture reporter
|
|
99
|
+
capture recorder
|
|
100
|
+
assert recorder.reports.length == 1
|
|
101
|
+
for ["ui", "window", "promise"] as source
|
|
102
|
+
for ["UnexpectedError", "UiProtocolUnsupported", "UiHttpError"] as code
|
|
103
|
+
reporter.report(source, code)
|
|
104
|
+
return reporter.flush()
|
|
105
|
+
).then(()
|
|
106
|
+
capture reporter
|
|
107
|
+
reporter.error("UiProtocolUnsupported")
|
|
108
|
+
return reporter.flush()
|
|
109
|
+
).then(()
|
|
110
|
+
capture recorder
|
|
111
|
+
capture reporter
|
|
112
|
+
assert recorder.reports.length == 10
|
|
113
|
+
reporter.dispose()
|
|
114
|
+
println("PASS failed reports do not recurse or retry and the client budget caps network attempts")
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
nativeTransport()
|
|
118
|
+
original = host.fetch
|
|
119
|
+
calls = []
|
|
120
|
+
stub = (path, options)
|
|
121
|
+
capture calls
|
|
122
|
+
calls.add({
|
|
123
|
+
path: path
|
|
124
|
+
options: options
|
|
125
|
+
})
|
|
126
|
+
return Promise/resolve(null)
|
|
127
|
+
host.fetch = stub
|
|
128
|
+
reporter = new ErrorReporter({
|
|
129
|
+
})
|
|
130
|
+
reporter.error("UiHttpError: 500: private payload")
|
|
131
|
+
return reporter.flush().then(()
|
|
132
|
+
capture calls
|
|
133
|
+
assert calls.length == 1
|
|
134
|
+
call = calls[0]
|
|
135
|
+
assert call.path == "/_lango/client-error"
|
|
136
|
+
options = call.options
|
|
137
|
+
assert options.credentials == "omit"
|
|
138
|
+
assert options.referrerPolicy == "no-referrer"
|
|
139
|
+
assert options.redirect == "error"
|
|
140
|
+
assert options.cache == "no-store"
|
|
141
|
+
assert options.signal != null
|
|
142
|
+
assert !("Authorization" in options.headers)
|
|
143
|
+
assert !options.body.includes("private")
|
|
144
|
+
println("PASS native report transport omits credentials/referrer, rejects redirects and has a network deadline")
|
|
145
|
+
).finally(()
|
|
146
|
+
capture original
|
|
147
|
+
capture reporter
|
|
148
|
+
host.fetch = original
|
|
149
|
+
reporter.dispose()
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
main(args)
|
|
153
|
+
return privacy().then(()
|
|
154
|
+
return budget()
|
|
155
|
+
).then(()
|
|
156
|
+
return nativeTransport()
|
|
157
|
+
)
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import js global RegExp
|
|
2
|
+
|
|
3
|
+
export rulesFor(value)
|
|
4
|
+
export validationMessage(rules, value)
|
|
5
|
+
export sameValue(left, right)
|
|
6
|
+
export ownedFields(controls)
|
|
7
|
+
export dirtyFields(controls)
|
|
8
|
+
export validateFields(controls)
|
|
9
|
+
export validatesRequest(controls, name)
|
|
10
|
+
export confirmsRequest(controls, name)
|
|
11
|
+
|
|
12
|
+
rulesFor(value)
|
|
13
|
+
if value == null
|
|
14
|
+
return {
|
|
15
|
+
}
|
|
16
|
+
if !is_object(value) or is_array(value)
|
|
17
|
+
throw "UiValidationRequiresMap"
|
|
18
|
+
rules = {
|
|
19
|
+
}
|
|
20
|
+
for value as name: item
|
|
21
|
+
switch name
|
|
22
|
+
case "required"
|
|
23
|
+
if !is_bool(item)
|
|
24
|
+
throw "UiValidationRequiredMustBeBoolean"
|
|
25
|
+
case "minLength"
|
|
26
|
+
if !is_number(item) or item < 0 or item % 1 != 0
|
|
27
|
+
throw "UiValidationLengthMustBeNonnegativeInteger"
|
|
28
|
+
case "maxLength"
|
|
29
|
+
if !is_number(item) or item < 0 or item % 1 != 0
|
|
30
|
+
throw "UiValidationLengthMustBeNonnegativeInteger"
|
|
31
|
+
case "pattern"
|
|
32
|
+
if !is_string(item)
|
|
33
|
+
throw "UiValidationPatternMustBeString"
|
|
34
|
+
expression = new RegExp("^(?:${item})$")
|
|
35
|
+
case "message"
|
|
36
|
+
if !is_string(item) or item == ""
|
|
37
|
+
throw "UiValidationMessageMustBeString"
|
|
38
|
+
else
|
|
39
|
+
throw "UiUnknownValidationRule: ${name}"
|
|
40
|
+
rules[name] = item
|
|
41
|
+
if rules.minLength != null and rules.maxLength != null and rules.minLength > rules.maxLength
|
|
42
|
+
throw "UiValidationLengthRangeInvalid"
|
|
43
|
+
return rules
|
|
44
|
+
|
|
45
|
+
validationMessage(rules, value)
|
|
46
|
+
empty = value == null or value == false
|
|
47
|
+
if is_string(value)
|
|
48
|
+
empty = value.trim() == ""
|
|
49
|
+
message = null
|
|
50
|
+
if rules.required == true and empty
|
|
51
|
+
message = "This field is required."
|
|
52
|
+
if !empty
|
|
53
|
+
if rules.minLength != null or rules.maxLength != null or rules.pattern != null
|
|
54
|
+
if !is_string(value)
|
|
55
|
+
message = "This value must be text."
|
|
56
|
+
else
|
|
57
|
+
if rules.minLength != null and value.length < rules.minLength
|
|
58
|
+
message = "Enter at least ${rules.minLength} characters."
|
|
59
|
+
if rules.maxLength != null and value.length > rules.maxLength
|
|
60
|
+
message = "Enter at most ${rules.maxLength} characters."
|
|
61
|
+
if rules.pattern != null
|
|
62
|
+
pattern = new RegExp("^(?:${rules.pattern})$")
|
|
63
|
+
if !pattern.test(value)
|
|
64
|
+
message = "Enter a value in the required format."
|
|
65
|
+
if message != null and rules.message != null
|
|
66
|
+
return rules.message
|
|
67
|
+
return message
|
|
68
|
+
|
|
69
|
+
sameValue(left, right)
|
|
70
|
+
if is_array(left)
|
|
71
|
+
if !is_array(right) or left.length != right.length
|
|
72
|
+
return false
|
|
73
|
+
for left as index: value
|
|
74
|
+
if !sameValue(value, right[index])
|
|
75
|
+
return false
|
|
76
|
+
return true
|
|
77
|
+
if is_object(left)
|
|
78
|
+
if !is_object(right) or is_array(right)
|
|
79
|
+
return false
|
|
80
|
+
count = 0
|
|
81
|
+
other = 0
|
|
82
|
+
for left as name: value
|
|
83
|
+
count++
|
|
84
|
+
if !(name in right) or !sameValue(value, right[name])
|
|
85
|
+
return false
|
|
86
|
+
for right as name: value
|
|
87
|
+
other++
|
|
88
|
+
return count == other
|
|
89
|
+
return left == right
|
|
90
|
+
|
|
91
|
+
ownedFields(controls)
|
|
92
|
+
result = []
|
|
93
|
+
collectFields(controls, [], result, false)
|
|
94
|
+
return result
|
|
95
|
+
|
|
96
|
+
collectFields(controls, parent, result, blocked)
|
|
97
|
+
for controls as control
|
|
98
|
+
if control.element != null and control.element.langoFormRoot == true
|
|
99
|
+
continue
|
|
100
|
+
path = parent.slice()
|
|
101
|
+
unavailable = blocked
|
|
102
|
+
if control.element != null
|
|
103
|
+
unavailable = unavailable or control.element.disabled == true or control.element.hidden == true or control.element.inert == true
|
|
104
|
+
if control.name != null and control.name != ""
|
|
105
|
+
path.add(control.name)
|
|
106
|
+
if is_array(control.controls)
|
|
107
|
+
collectFields(control.controls, path, result, unavailable)
|
|
108
|
+
else
|
|
109
|
+
result.add({
|
|
110
|
+
control: control
|
|
111
|
+
path: path
|
|
112
|
+
blocked: unavailable
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
dirtyFields(controls)
|
|
116
|
+
fields = ownedFields(controls)
|
|
117
|
+
for fields as field
|
|
118
|
+
control = field.control
|
|
119
|
+
if is_kindof(control.isDirty, Function)
|
|
120
|
+
if control.isDirty()
|
|
121
|
+
return true
|
|
122
|
+
return false
|
|
123
|
+
|
|
124
|
+
validateFields(controls)
|
|
125
|
+
issues = []
|
|
126
|
+
fields = ownedFields(controls)
|
|
127
|
+
for fields as field
|
|
128
|
+
if field.blocked
|
|
129
|
+
continue
|
|
130
|
+
control = field.control
|
|
131
|
+
if is_kindof(control.validate, Function)
|
|
132
|
+
message = control.validate()
|
|
133
|
+
if message != null
|
|
134
|
+
issues.add({
|
|
135
|
+
path: field.path
|
|
136
|
+
message: message
|
|
137
|
+
control: field.control
|
|
138
|
+
})
|
|
139
|
+
return issues
|
|
140
|
+
|
|
141
|
+
validatesRequest(controls, name)
|
|
142
|
+
target = requestSource(controls, name)
|
|
143
|
+
return target != null and target.validates == true
|
|
144
|
+
|
|
145
|
+
confirmsRequest(controls, name)
|
|
146
|
+
target = requestSource(controls, name)
|
|
147
|
+
return target != null and target.confirms == true
|
|
148
|
+
|
|
149
|
+
requestSource(controls, name)
|
|
150
|
+
path = name
|
|
151
|
+
if is_string(path)
|
|
152
|
+
path = [path]
|
|
153
|
+
if !is_array(path) or path.length == 0
|
|
154
|
+
return null
|
|
155
|
+
current = controls
|
|
156
|
+
target = null
|
|
157
|
+
for path as part
|
|
158
|
+
if !is_array(current)
|
|
159
|
+
return null
|
|
160
|
+
target = null
|
|
161
|
+
for current as control
|
|
162
|
+
if control.name == part
|
|
163
|
+
target = control
|
|
164
|
+
break
|
|
165
|
+
if target == null
|
|
166
|
+
return null
|
|
167
|
+
current = target.controls
|
|
168
|
+
return target
|