[mod] before esm

This commit is contained in:
Andy Bunce 2025-07-17 15:31:04 +01:00
parent 3c60660f16
commit 8df5f011bc
8 changed files with 147 additions and 22 deletions

View file

@ -8,13 +8,14 @@ services:
- "3000:8080" - "3000:8080"
- "3001:1984" - "3001:1984"
volumes: volumes:
- basex-lsp:/srv/basex/data - ./data:/srv/basex/data
- ./webapp/static/ace:/srv/basex/webapp/static/ace
- ./webapp/lsp:/srv/basex/webapp/lsp - ./webapp/lsp:/srv/basex/webapp/lsp
- ./setup.bxs:/srv/basex/setup.bxs
# - ./jars:/srv/basex/lib/custom # - ./jars:/srv/basex/lib/custom
# - ./repo:/srv/basex/repo # - ./repo:/srv/basex/repo
environment: environment:
- "SERVER_OPTS= -c basex/setup.bxs" - "SERVER_OPTS= -d"
volumes: volumes:
basex-lsp: basex-lsp:

30
data/.logs/2025-07-17.log Normal file
View file

@ -0,0 +1,30 @@
13:46:33.043 SERVER admin OK Server was started (port: 1984).
13:46:33.076 SERVER admin INFO Initial admin password (change after first login): c980aed4-8234-48e0-84b9-195d0ef6b049
13:46:33.110 SERVER admin OK HTTP Server was started (port: 8080).
13:49:38.435 172.19.0.1:33068 admin REQUEST [GET] /dba/logs
13:49:40.374 172.19.0.1:33068 admin 302 Location: login?_page=logs 1942.58 ms
13:49:40.401 172.19.0.1:33068 admin REQUEST [GET] /dba/login?_page=logs
13:49:40.527 172.19.0.1:33068 public 200 126.37 ms
13:50:11.142 172.19.0.1:33068 admin REQUEST [POST] /dba/login
13:50:11.255 172.19.0.1:33068 public DBA Login: admin
13:50:11.256 172.19.0.1:33068 public 302 Location: logs 114.16 ms
13:50:11.281 172.19.0.1:33068 admin REQUEST [GET] /dba/logs
13:50:11.485 172.19.0.1:33068 admin 200 205.03 ms
13:50:11.677 172.19.0.1:33068 admin REQUEST [POST] /dba/logs?date=2025-07-17&page=1
13:50:11.828 172.19.0.1:33068 admin 200 150.97 ms
13:51:01.795 172.19.0.1 admin REQUEST [WS-OPEN] http://127.0.0.1:3000/ws/lsp
13:51:01.806 SERVER admin TRACE CONNECT: "websocket0"
13:51:20.443 172.19.0.1:33068 admin REQUEST [GET] /dba/logs?input=
13:51:20.535 172.19.0.1:33068 admin 200 105.53 ms
13:51:20.619 172.19.0.1:33068 admin REQUEST [POST] /dba/logs?date=2025-07-17&page=1
13:51:20.712 172.19.0.1:33068 admin 200 92.72 ms
13:54:21.878 172.19.0.1 admin REQUEST [WS-OPEN] http://127.0.0.1:3000/ws/lsp
13:54:21.886 SERVER admin TRACE CONNECT: "websocket1"
13:54:38.250 172.19.0.1:54556 admin REQUEST [GET] /dba/logs?input=
13:54:38.304 172.19.0.1:54556 admin 200 54.29 ms
13:54:38.386 172.19.0.1:54556 admin REQUEST [POST] /dba/logs?date=2025-07-17&page=1
13:54:38.467 172.19.0.1:54556 admin 200 81.02 ms
13:59:11.360 172.19.0.1 admin REQUEST [WS-OPEN] http://127.0.0.1:3000/ws/lsp
13:59:11.369 SERVER admin TRACE CONNECT: "websocket2"
14:03:40.821 172.19.0.1 admin REQUEST [WS-OPEN] http://127.0.0.1:3000/ws/lsp
14:03:40.829 SERVER admin TRACE CONNECT: "websocket3"

11
data/users.xml Normal file
View file

@ -0,0 +1,11 @@
<users>
<user name="admin" permission="admin">
<password algorithm="digest">
<hash>60a56ebb6dcce833b7b25f1b30308230</hash>
</password>
<password algorithm="salted-sha256">
<salt>1380009415456</salt>
<hash>d05ace1a12d885eefaeeefaff9064b79dba66099e4b746ee670ee40740b59010</hash>
</password>
</user>
</users>

View file

@ -1,2 +0,0 @@
CREATE DB xmark http://files.basex.org/xml/xmark.xml
REPO INSTALL https://github.com/expkg-zone58/pdfbox/releases/download/v0.3.6/pdfbox-0.3.6.xar

View file

@ -2,24 +2,24 @@
: Simple WebSocket chat. Utility functions. : Simple WebSocket chat. Utility functions.
: @author BaseX Team, BSD License : @author BaseX Team, BSD License
:) :)
module namespace chat-util = 'chat/util'; module namespace lsp-util = 'chat/util';
import module namespace session = 'http://basex.org/modules/session';
import module namespace ws = 'http://basex.org/modules/ws'; import module namespace ws = 'http://basex.org/modules/ws';
(:~ User id (bound to sessions and WebSockets). :) (:~ User id (bound to sessions and WebSockets). :)
declare variable $chat-util:id := 'id'; declare variable $lsp-util:id := 'id';
(:~ (:~
: Sends a users list (all, active) to all registered clients. : Sends a users list (all, active) to all registered clients.
:) :)
declare function chat-util:users() as empty-sequence() { declare function lsp-util:users() as empty-sequence() {
ws:emit(map{ ws:emit(map{
'type': 'users', 'type': 'users',
'users': array { sort(user:list()) }, 'users': array { sort(user:list()) },
'active': array { distinct-values( 'active': array { distinct-values(
for $id in ws:ids() for $id in ws:ids()
return ws:get($id, $chat-util:id) return ws:get($id, $lsp-util:id)
)} )}
}) })
}; };
@ -29,15 +29,15 @@ declare function chat-util:users() as empty-sequence() {
: @param $text text to be sent : @param $text text to be sent
: @param $to receiver of a private message (optional) : @param $to receiver of a private message (optional)
:) :)
declare function chat-util:message( declare function lsp-util:message(
$text as xs:string, $text as xs:string,
$to as xs:string? $to as xs:string?
) as empty-sequence() { ) as empty-sequence() {
let $ws-ids := ws:ids()[not($to) or ws:get(., $chat-util:id) = $to] let $ws-ids := ws:ids()[not($to) or ws:get(., $lsp-util:id) = $to]
return ws:send(map{ return ws:send(map{
'type': 'message', 'type': 'message',
'text': serialize($text), 'text': serialize($text),
'from': ws:get(ws:id(), $chat-util:id), 'from': ws:get(ws:id(), $lsp-util:id),
'date': format-time(current-time(), '[H02]:[m02]:[s02]'), 'date': format-time(current-time(), '[H02]:[m02]:[s02]'),
'private': boolean($to) 'private': boolean($to)
}, $ws-ids) }, $ws-ids)
@ -47,10 +47,10 @@ declare function chat-util:message(
: Closes all WebSocket connections from the specified user. : Closes all WebSocket connections from the specified user.
: @param $name username : @param $name username
:) :)
declare function chat-util:close( declare function lsp-util:close(
$name as xs:string $name as xs:string
) as empty-sequence() { ) as empty-sequence() {
for $id in ws:ids() for $id in ws:ids()
where ws:get($id, $chat-util:id) = $name where ws:get($id, $lsp-util:id) = $name
return ws:close($id) return ws:close($id)
}; };

View file

@ -2,19 +2,24 @@
: Simple WebSocket chat. WebSocket functions. : Simple WebSocket chat. WebSocket functions.
: @author BaseX Team, BSD License : @author BaseX Team, BSD License
:) :)
module namespace chat-ws = 'chat-ws'; module namespace lsp-ws = 'lsp-ws';
import module namespace chat-util = 'chat/util' at 'lsp-util.xqm'; import module namespace chat-util = 'chat/util' at 'lsp-util.xqm';
declare
%ws:error('/lsp', '{$error}')
function lsp-ws:error($error) {
trace($error,"ERR ")
};
(:~ (:~
: Creates a WebSocket connection. Registers the user and notifies all clients. : Creates a WebSocket connection. Registers the user and notifies all clients.
:) :)
declare declare
%ws:connect('/lsp') %ws:connect('/lsp')
function chat-ws:connect() as empty-sequence() { function lsp-ws:connect() as empty-sequence() {
ws:set(ws:id()=>trace("CONNECT: "), $chat-util:id, session:get($chat-util:id)), ws:set(ws:id()=>trace("CONNECT: "), $chat-util:id, session:get($chat-util:id))
chat-util:users() (: ,chat-util:users() :)
}; };
(:~ (:~
@ -23,10 +28,10 @@ function chat-ws:connect() as empty-sequence() {
:) :)
declare declare
%ws:message('/lsp', '{$message}') %ws:message('/lsp', '{$message}')
function chat-ws:message( function lsp-ws:message(
$message as xs:string $message as xs:string
) as empty-sequence() { ) as empty-sequence() {
let $json := parse-json($message) let $json := parse-json($message=>trace("MSG "))
let $type := $json?type let $type := $json?type
return if($type = 'message') then ( return if($type = 'message') then (
chat-util:message($json?text, $json?to) chat-util:message($json?text, $json?to)
@ -40,7 +45,7 @@ function chat-ws:message(
:) :)
declare declare
%ws:close('/lsp') %ws:close('/lsp')
function chat-ws:close() as empty-sequence() { function lsp-ws:close() as empty-sequence() {
ws:delete(ws:id(), $chat-util:id), ws:delete(ws:id(), $chat-util:id),
chat-util:users() chat-util:users()
}; };

View file

@ -0,0 +1,28 @@
import * as aceBuilds from 'https://esm.run/ace-builds';
import ace from 'https://cdn.jsdelivr.net/npm/ace/+esm'
/* import 'ace-builds/src-noconflict/mode-javascript';
import 'ace-builds/src-noconflict/theme-chrome'; */
/* import {AceLanguageClient} from "ace-linters/build/ace-language-client";
const serverData = {
module: () => import("ace-linters/build/language-client"),
modes: "json|json5",
type: "socket",
socket: new WebSocket("ws://127.0.0.1:3000/ws/lsp"), // your websocket server address
}
*/
// Initialize the editor
const editor = ace.edit("editor", {
theme: "ace/theme/chrome",
mode: "ace/mode/javascript",
fontSize: "14px",
showPrintMargin: false,
useWorker: false // Disable web worker for this simple demo
});
// Create a language provider for WebSocket
//let languageProvider = AceLanguageClient.for(serverData);
//languageProvider.registerEditor(editor);

View file

@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>BaseX LSP</title>
<script src="https://www.unpkg.com/ace-builds@latest/src-noconflict/ace.js"></script>
<script src="https://www.unpkg.com/ace-builds@latest/src-noconflict/ext-language_tools.js"></script>
<script src="https://www.unpkg.com/ace-builds@latest/src-noconflict/ext-modelist.js"></script>
<!-- -->
<script src="https://www.unpkg.com/ace-linters@latest/build/ace-linters.js"></script>
<script src="https://www.unpkg.com/ace-linters@latest/build/ace-language-client.js"></script>
<script type="module" src="acego.js"></script>
</head>
<body>
<div>something<button onclick="foo()">send</button><a href="/dba/logs" target="_blank">dba</a></div>
<div id="editor" style="height: 100px">some text</div>
<script>
var modelist = ace.require('ace/ext/modelist');
if(modelist.modesByName['json'] == undefined) {
console.log("mode doesn't exist");
}
var servers = [
{
module: () => import("XXXXXace-linters/build/language-client"),
modes: "json",
type: "socket",
socket: new WebSocket("ws://127.0.0.1:3000/ws/lsp"),
}
];
let languageProvider = AceLanguageClient.for(servers);
ace.require("ace/ext/language_tools"); //To allow autocompletion
var editor = ace.edit("editor", {
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
mode: "json"
});
languageProvider.registerEditor(editor);
// editor.session.setMode("astro"); // mode now contains "ace/mode/javascript".
function foo(){
servers[0].socket.send("TTTTT")
alert("hi")
}
</script>
</body>
</html>