@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
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import js global crypto
|
|
2
|
-
|
|
3
|
-
export testContacts(send, token)
|
|
4
|
-
|
|
5
|
-
testContacts(send, token)
|
|
6
|
-
flow = new ContactsFlow(send, token)
|
|
7
|
-
return flow.run()
|
|
8
|
-
|
|
9
|
-
class ContactsFlow
|
|
10
|
-
methods
|
|
11
|
-
run()
|
|
12
|
-
|
|
13
|
-
ContactsFlow(send, token)
|
|
14
|
-
@send = send
|
|
15
|
-
@token = token
|
|
16
|
-
@instance = crypto/randomUUID()
|
|
17
|
-
@id = null
|
|
18
|
-
@duplicate = null
|
|
19
|
-
|
|
20
|
-
ContactsFlow:request(action, seqno, values)
|
|
21
|
-
send = @send
|
|
22
|
-
return send("/app/contacts/${action}", {
|
|
23
|
-
formId: "contacts"
|
|
24
|
-
formInstanceId: @instance
|
|
25
|
-
seqno: seqno
|
|
26
|
-
values: values
|
|
27
|
-
}, @token).then((result)
|
|
28
|
-
if result.token != null
|
|
29
|
-
@token = result.token
|
|
30
|
-
return result
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
ContactsFlow:record(version, fullName = "Ada", email = "ada@example.com")
|
|
34
|
-
return {
|
|
35
|
-
id: @id
|
|
36
|
-
version: version
|
|
37
|
-
fullName: fullName
|
|
38
|
-
email: email
|
|
39
|
-
country: "gb"
|
|
40
|
-
subscribed: false
|
|
41
|
-
confirmDelete: false
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
ContactsFlow:save(seqno, record)
|
|
45
|
-
return request("save", seqno, {
|
|
46
|
-
editor: record
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
ContactsFlow:run()
|
|
50
|
-
send = @send
|
|
51
|
-
return send("/app/url", {
|
|
52
|
-
formId: "contacts-page"
|
|
53
|
-
formInstanceId: @instance
|
|
54
|
-
seqno: 1
|
|
55
|
-
values: {
|
|
56
|
-
url: "/contacts"
|
|
57
|
-
template: null
|
|
58
|
-
content: {
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}, @token).then((result)
|
|
62
|
-
assert result.status == 200
|
|
63
|
-
@token = result.token
|
|
64
|
-
page = result.body.ui.replace.content.controls[1]
|
|
65
|
-
assert page.type == "Form"
|
|
66
|
-
assert page.controls[1].options.length == 0
|
|
67
|
-
@id = page.controls[4].controls[0].value
|
|
68
|
-
assert is_string(@id)
|
|
69
|
-
return save(1, record(0, " Ada Lovelace ", "ADA@EXAMPLE.COM"))
|
|
70
|
-
).then((result)
|
|
71
|
-
assert result.status == 200
|
|
72
|
-
assert result.body.vals.editor.version == 1
|
|
73
|
-
assert result.body.vals.editor.fullName == "Ada Lovelace"
|
|
74
|
-
assert result.body.vals.editor.email == "ada@example.com"
|
|
75
|
-
assert result.body.vals.editor.subscribed == false
|
|
76
|
-
assert result.body.ui.replace.selection.options.length == 1
|
|
77
|
-
assert result.body.cmds[0].name == "savedValue"
|
|
78
|
-
return request("open", 2, {
|
|
79
|
-
selection: @id
|
|
80
|
-
})
|
|
81
|
-
).then((result)
|
|
82
|
-
assert result.status == 200
|
|
83
|
-
assert result.body.ui.replace.editor.controls[1].value == 1
|
|
84
|
-
assert result.body.ui.replace.editor.controls[3].value == "Ada Lovelace"
|
|
85
|
-
return save(3, record(1, "Grace Hopper"))
|
|
86
|
-
).then((result)
|
|
87
|
-
assert result.body.vals.editor.version == 2
|
|
88
|
-
assert result.body.vals.editor.fullName == "Grace Hopper"
|
|
89
|
-
return save(4, record(1, "Lost update"))
|
|
90
|
-
).then((result)
|
|
91
|
-
assert result.body.vals.editor.status.includes("changed")
|
|
92
|
-
assert result.body.cmds.length == 0
|
|
93
|
-
stale = record(1)
|
|
94
|
-
stale.confirmDelete = true
|
|
95
|
-
return request("delete", 5, {
|
|
96
|
-
editor: stale
|
|
97
|
-
})
|
|
98
|
-
).then((result)
|
|
99
|
-
assert result.body.vals.editor.status.includes("changed")
|
|
100
|
-
return request("delete", 6, {
|
|
101
|
-
editor: record(2)
|
|
102
|
-
})
|
|
103
|
-
).then((result)
|
|
104
|
-
assert result.body.cmds[0].name == "error"
|
|
105
|
-
assert to_json(result.body.cmds[0].target) == to_json(["editor", "confirmDelete"])
|
|
106
|
-
return save(7, record(2, "Grace", "invalid"))
|
|
107
|
-
).then((result)
|
|
108
|
-
assert result.body.cmds.length == 1
|
|
109
|
-
assert result.body.cmds[0].name == "error"
|
|
110
|
-
return request("new", 8, {
|
|
111
|
-
})
|
|
112
|
-
).then((result)
|
|
113
|
-
@duplicate = result.body.ui.replace.editor.controls[0].value
|
|
114
|
-
duplicate = record(0)
|
|
115
|
-
duplicate.id = @duplicate
|
|
116
|
-
return save(9, duplicate)
|
|
117
|
-
).then((result)
|
|
118
|
-
assert result.body.cmds[0].value == "Another contact uses this email."
|
|
119
|
-
send = @send
|
|
120
|
-
return send("/_lango/start", {
|
|
121
|
-
}, null)
|
|
122
|
-
).then((result)
|
|
123
|
-
assert result.status == 200
|
|
124
|
-
send = @send
|
|
125
|
-
return send("/app/contacts/open", {
|
|
126
|
-
formId: "foreign-contacts"
|
|
127
|
-
formInstanceId: @instance
|
|
128
|
-
seqno: 1
|
|
129
|
-
values: {
|
|
130
|
-
selection: @id
|
|
131
|
-
}
|
|
132
|
-
}, result.token)
|
|
133
|
-
).then((result)
|
|
134
|
-
assert result.status == 200
|
|
135
|
-
assert result.body.ui.replace.selection.options.length == 0
|
|
136
|
-
assert result.body.vals.editor.status.includes("no longer exists")
|
|
137
|
-
return request("open", 10, {
|
|
138
|
-
selection: @id
|
|
139
|
-
})
|
|
140
|
-
).then((result)
|
|
141
|
-
assert result.body.ui.replace.editor.controls[3].value == "Grace Hopper"
|
|
142
|
-
assert result.body.ui.replace.editor.controls[1].value == 2
|
|
143
|
-
current = record(2)
|
|
144
|
-
current.confirmDelete = true
|
|
145
|
-
return request("delete", 11, {
|
|
146
|
-
editor: current
|
|
147
|
-
})
|
|
148
|
-
).then((result)
|
|
149
|
-
assert result.body.ui.replace.selection.options.length == 0
|
|
150
|
-
assert result.body.vals.editor.status == "Contact deleted."
|
|
151
|
-
assert result.body.ui.replace.editor.controls[1].value == 0
|
|
152
|
-
return request("open", 12, {
|
|
153
|
-
selection: @id
|
|
154
|
-
})
|
|
155
|
-
).then((result)
|
|
156
|
-
assert result.body.vals.editor.status.includes("no longer exists")
|
|
157
|
-
return save(13, record("invalid"))
|
|
158
|
-
).then((result)
|
|
159
|
-
assert result.status == 400
|
|
160
|
-
assert result.body.error == "InvalidContact"
|
|
161
|
-
send = @send
|
|
162
|
-
return send("/app/contacts/new", {
|
|
163
|
-
formId: "unsigned"
|
|
164
|
-
formInstanceId: @instance
|
|
165
|
-
seqno: 1
|
|
166
|
-
values: {
|
|
167
|
-
}
|
|
168
|
-
}, null)
|
|
169
|
-
).then((result)
|
|
170
|
-
assert result.status == 401
|
|
171
|
-
assert result.body.error == "BootstrapRequired"
|
|
172
|
-
println("PASS real contacts CRUD, canonical save acknowledgements, validation, unique email, stale update/delete and token-owner isolation")
|
|
173
|
-
return @token
|
|
174
|
-
)
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import js "node:sqlite" as sqlite
|
|
2
|
-
import js "node:fs" as fs
|
|
3
|
-
import js "node:path" as path
|
|
4
|
-
|
|
5
|
-
export class ContactsStore
|
|
6
|
-
methods
|
|
7
|
-
list(owner)
|
|
8
|
-
get(owner, id)
|
|
9
|
-
save(owner, id, version, values)
|
|
10
|
-
deleteRecord(owner, id, version)
|
|
11
|
-
close()
|
|
12
|
-
|
|
13
|
-
ContactsStore(file)
|
|
14
|
-
fs.mkdirSync(path.dirname(file), {
|
|
15
|
-
recursive: true
|
|
16
|
-
})
|
|
17
|
-
db = new sqlite/DatabaseSync(file)
|
|
18
|
-
@db = db
|
|
19
|
-
@closed = false
|
|
20
|
-
try
|
|
21
|
-
db.exec("PRAGMA busy_timeout = 5000")
|
|
22
|
-
db.exec("PRAGMA journal_mode = WAL")
|
|
23
|
-
db.exec("CREATE TABLE IF NOT EXISTS contacts (client_id TEXT NOT NULL, id TEXT NOT NULL, version INTEGER NOT NULL, full_name TEXT NOT NULL, email TEXT NOT NULL COLLATE NOCASE, country TEXT, subscribed INTEGER NOT NULL, PRIMARY KEY(client_id, id), UNIQUE(client_id, email))")
|
|
24
|
-
catch error
|
|
25
|
-
close()
|
|
26
|
-
throw error
|
|
27
|
-
|
|
28
|
-
ContactsStore:list(owner)
|
|
29
|
-
requireOwner(owner)
|
|
30
|
-
query = @db.prepare("SELECT id, version, full_name, email, country, subscribed FROM contacts WHERE client_id = ? ORDER BY full_name COLLATE NOCASE, id")
|
|
31
|
-
result = []
|
|
32
|
-
for query.all(owner) as row
|
|
33
|
-
result.add(contact(row))
|
|
34
|
-
return result
|
|
35
|
-
|
|
36
|
-
ContactsStore:get(owner, id)
|
|
37
|
-
requireOwner(owner)
|
|
38
|
-
query = @db.prepare("SELECT id, version, full_name, email, country, subscribed FROM contacts WHERE client_id = ? AND id = ?")
|
|
39
|
-
row = query.get(owner, id)
|
|
40
|
-
if row == null
|
|
41
|
-
return null
|
|
42
|
-
return contact(row)
|
|
43
|
-
|
|
44
|
-
ContactsStore:save(owner, id, version, values)
|
|
45
|
-
requireOwner(owner)
|
|
46
|
-
requireVersion(id, version)
|
|
47
|
-
subscribed = 0
|
|
48
|
-
if values.subscribed
|
|
49
|
-
subscribed = 1
|
|
50
|
-
query = null
|
|
51
|
-
result = null
|
|
52
|
-
if version == 0
|
|
53
|
-
query = @db.prepare("INSERT INTO contacts(client_id, id, version, full_name, email, country, subscribed) VALUES (?, ?, 1, ?, ?, ?, ?) ON CONFLICT DO NOTHING")
|
|
54
|
-
result = query.run(owner, id, values.fullName, values.email, values.country, subscribed)
|
|
55
|
-
else
|
|
56
|
-
query = @db.prepare("UPDATE contacts SET full_name = ?, email = ?, country = ?, subscribed = ?, version = version + 1 WHERE client_id = ? AND id = ? AND version = ? AND NOT EXISTS (SELECT 1 FROM contacts AS other WHERE other.client_id = ? AND other.email = ? COLLATE NOCASE AND other.id != ?)")
|
|
57
|
-
result = query.run(values.fullName, values.email, values.country, subscribed, owner, id, version, owner, values.email, id)
|
|
58
|
-
if result.changes == 1
|
|
59
|
-
return {
|
|
60
|
-
outcome: "Saved"
|
|
61
|
-
id: id
|
|
62
|
-
version: version + 1
|
|
63
|
-
}
|
|
64
|
-
current = get(owner, id)
|
|
65
|
-
outcome = "DuplicateEmail"
|
|
66
|
-
if version != 0 and current == null
|
|
67
|
-
outcome = "Missing"
|
|
68
|
-
if current != null and (version == 0 or current.version != version)
|
|
69
|
-
outcome = "Conflict"
|
|
70
|
-
return {
|
|
71
|
-
outcome: outcome
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
ContactsStore:deleteRecord(owner, id, version)
|
|
75
|
-
requireOwner(owner)
|
|
76
|
-
requireVersion(id, version)
|
|
77
|
-
if version == 0
|
|
78
|
-
return "Missing"
|
|
79
|
-
query = @db.prepare("DELETE FROM contacts WHERE client_id = ? AND id = ? AND version = ?")
|
|
80
|
-
result = query.run(owner, id, version)
|
|
81
|
-
if result.changes == 1
|
|
82
|
-
return "Deleted"
|
|
83
|
-
if get(owner, id) == null
|
|
84
|
-
return "Missing"
|
|
85
|
-
return "Conflict"
|
|
86
|
-
|
|
87
|
-
ContactsStore:close()
|
|
88
|
-
if !@closed
|
|
89
|
-
@closed = true
|
|
90
|
-
db = @db
|
|
91
|
-
db.close()
|
|
92
|
-
|
|
93
|
-
requireOwner(owner)
|
|
94
|
-
if !is_string(owner) or owner == ""
|
|
95
|
-
throw "ContactsOwnerRequired"
|
|
96
|
-
|
|
97
|
-
requireVersion(id, version)
|
|
98
|
-
if !is_string(id) or id == "" or id.length > 128 or !is_number(version) or version < 0 or version % 1 != 0 or version >= 9007199254740991
|
|
99
|
-
throw "ContactsIdentityAndVersionRequired"
|
|
100
|
-
|
|
101
|
-
contact(row)
|
|
102
|
-
return {
|
|
103
|
-
id: row.id
|
|
104
|
-
version: row.version
|
|
105
|
-
fullName: row.full_name
|
|
106
|
-
email: row.email
|
|
107
|
-
country: row.country
|
|
108
|
-
subscribed: row.subscribed == 1
|
|
109
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import js "node:fs" as fs
|
|
2
|
-
import js "node:os" as os
|
|
3
|
-
import js "node:path" as path
|
|
4
|
-
import "./contacts_store"
|
|
5
|
-
class ContactsStore
|
|
6
|
-
|
|
7
|
-
export main(args)
|
|
8
|
-
|
|
9
|
-
values(name, email, subscribed = false)
|
|
10
|
-
return {
|
|
11
|
-
fullName: name
|
|
12
|
-
email: email
|
|
13
|
-
country: null
|
|
14
|
-
subscribed: subscribed
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
main(args)
|
|
18
|
-
directory = fs.mkdtempSync(path.join(os.tmpdir(), "lango-contacts-"))
|
|
19
|
-
file = path.join(directory, "contacts.sqlite")
|
|
20
|
-
first = new ContactsStore(file)
|
|
21
|
-
second = new ContactsStore(file)
|
|
22
|
-
try
|
|
23
|
-
saved = first.save("owner-a", "one", 0, values("Ada", "ada@example.com", true))
|
|
24
|
-
assert saved.outcome == "Saved"
|
|
25
|
-
assert saved.version == 1
|
|
26
|
-
assert second.list("owner-a").length == 1
|
|
27
|
-
assert second.get("owner-b", "one") == null
|
|
28
|
-
other = second.save("owner-b", "one", 0, values("Other", "ada@example.com"))
|
|
29
|
-
assert other.outcome == "Saved"
|
|
30
|
-
duplicate = first.save("owner-a", "two", 0, values("Duplicate", "ADA@example.com"))
|
|
31
|
-
assert duplicate.outcome == "DuplicateEmail"
|
|
32
|
-
next = second.save("owner-a", "one", 1, values("Ada'); DROP TABLE contacts;--", "ada@example.com"))
|
|
33
|
-
assert next.outcome == "Saved"
|
|
34
|
-
assert next.version == 2
|
|
35
|
-
stale = first.save("owner-a", "one", 1, values("Lost update", "lost@example.com"))
|
|
36
|
-
assert stale.outcome == "Conflict"
|
|
37
|
-
record = first.get("owner-a", "one")
|
|
38
|
-
assert record.fullName == "Ada'); DROP TABLE contacts;--"
|
|
39
|
-
assert record.subscribed == false
|
|
40
|
-
assert record.country == null
|
|
41
|
-
assert first.deleteRecord("owner-a", "one", 1) == "Conflict"
|
|
42
|
-
assert first.deleteRecord("owner-c", "one", 2) == "Missing"
|
|
43
|
-
more = first.save("owner-a", "two", 0, values("Second", "second@example.com"))
|
|
44
|
-
assert more.outcome == "Saved"
|
|
45
|
-
duplicate = second.save("owner-a", "two", 1, values("Second", "ADA@example.com"))
|
|
46
|
-
assert duplicate.outcome == "DuplicateEmail"
|
|
47
|
-
record = first.get("owner-a", "two")
|
|
48
|
-
assert record.version == 1
|
|
49
|
-
assert record.email == "second@example.com"
|
|
50
|
-
first.close()
|
|
51
|
-
first = new ContactsStore(file)
|
|
52
|
-
record = first.get("owner-a", "one")
|
|
53
|
-
assert record.version == 2
|
|
54
|
-
assert first.list("owner-a").length == 2
|
|
55
|
-
assert first.deleteRecord("owner-a", "one", 2) == "Deleted"
|
|
56
|
-
assert second.get("owner-a", "one") == null
|
|
57
|
-
assert second.get("owner-b", "one").fullName == "Other"
|
|
58
|
-
println("PASS contacts persist across reopen, isolate owners, bind SQL values, reject duplicates and prevent stale update/delete across connections")
|
|
59
|
-
finally
|
|
60
|
-
first.close()
|
|
61
|
-
second.close()
|
|
62
|
-
fs.rmSync(directory, {
|
|
63
|
-
recursive: true
|
|
64
|
-
force: true
|
|
65
|
-
})
|
package/examples/demo.css
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
body {
|
|
2
|
-
max-width: 52rem;
|
|
3
|
-
margin: 2rem auto;
|
|
4
|
-
padding: 0 1rem;
|
|
5
|
-
font-family: system-ui, sans-serif;
|
|
6
|
-
line-height: 1.5;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
nav {
|
|
10
|
-
display: flex;
|
|
11
|
-
flex-wrap: wrap;
|
|
12
|
-
gap: 1rem;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.demo-theme .demo-form {
|
|
16
|
-
display: grid;
|
|
17
|
-
gap: 0.75rem;
|
|
18
|
-
padding: 1rem;
|
|
19
|
-
border: 1px solid #cbd5e1;
|
|
20
|
-
border-radius: 0.5rem;
|
|
21
|
-
margin-block: 0.75rem;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.demo-theme .demo-input {
|
|
25
|
-
padding: 0.5rem;
|
|
26
|
-
border: 1px solid #94a3b8;
|
|
27
|
-
border-radius: 0.25rem;
|
|
28
|
-
font: inherit;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
.demo-theme .demo-button {
|
|
32
|
-
padding: 0.5rem 1rem;
|
|
33
|
-
background-color: var(--accent-color);
|
|
34
|
-
color: white;
|
|
35
|
-
border: 0;
|
|
36
|
-
border-radius: 0.25rem;
|
|
37
|
-
font: inherit;
|
|
38
|
-
cursor: pointer;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.demo-theme .demo-button:disabled {
|
|
42
|
-
cursor: default;
|
|
43
|
-
opacity: 0.6;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.demo-theme .demo-label {
|
|
47
|
-
font-weight: 600;
|
|
48
|
-
color: var(--accent-color);
|
|
49
|
-
margin-block: 0.5rem;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.demo-theme .demo-checkbox {
|
|
53
|
-
width: 1.25rem;
|
|
54
|
-
height: 1.25rem;
|
|
55
|
-
accent-color: var(--accent-color);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
.demo-theme [aria-invalid="true"] {
|
|
59
|
-
outline: 2px solid #b91c1c;
|
|
60
|
-
outline-offset: 2px;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
#form-status {
|
|
64
|
-
color: #b91c1c;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
.demo-theme .contact-editor {
|
|
68
|
-
display: grid;
|
|
69
|
-
gap: 0.5rem;
|
|
70
|
-
padding-block-start: 1rem;
|
|
71
|
-
border-top: 1px solid #cbd5e1;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
.lango-field {
|
|
75
|
-
display: grid;
|
|
76
|
-
gap: 0.35rem;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
.lango-caption { font-weight: 600; }
|
|
80
|
-
.lango-field-error { color: #b91c1c; }
|
|
81
|
-
.lango-field-error[hidden] { display: none; }
|
|
82
|
-
.lango-field input, .lango-field select { box-sizing: border-box; max-width: 100%; }
|
|
83
|
-
.lango-field[data-lango-control="Checkbox"] { grid-template-columns: auto 1fr; align-items: center; }
|
|
84
|
-
.lango-field[data-lango-control="Checkbox"] input { grid-column: 1; grid-row: 1; }
|
|
85
|
-
.lango-field[data-lango-control="Checkbox"] .lango-caption { grid-column: 2; grid-row: 1; }
|
|
86
|
-
.lango-field[data-lango-control="Checkbox"] .lango-field-error { grid-column: 1 / -1; }
|
|
87
|
-
:focus-visible { outline: 3px solid #0f766e; outline-offset: 3px; }
|