xq-lsp 1.5.0 → 1.6.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +23 -1
  3. package/demo/favicon.svg +6 -0
  4. package/demo/index.html +2 -0
  5. package/demo/main.ts +3 -12
  6. package/dist/analyzer.js +8 -6
  7. package/dist/diagnostics.d.ts +20 -0
  8. package/dist/diagnostics.js +28 -0
  9. package/dist/qt4-worker.js +5 -11
  10. package/dist/runtimes/existdb/cache.xq +83 -0
  11. package/dist/runtimes/existdb/compression.xq +198 -0
  12. package/dist/runtimes/existdb/console.xq +24 -0
  13. package/dist/runtimes/existdb/contentextraction.xq +31 -0
  14. package/dist/runtimes/existdb/counter.xq +30 -0
  15. package/dist/runtimes/existdb/crypto.xq +97 -0
  16. package/dist/runtimes/existdb/datetime.xq +91 -0
  17. package/dist/runtimes/existdb/exist.xq +29 -0
  18. package/dist/runtimes/existdb/file.xq +129 -0
  19. package/dist/runtimes/existdb/ft.xq +325 -0
  20. package/dist/runtimes/existdb/httpclient.xq +118 -0
  21. package/dist/runtimes/existdb/image.xq +65 -0
  22. package/dist/runtimes/existdb/inspect.xq +49 -0
  23. package/dist/runtimes/existdb/kwic.xq +24 -0
  24. package/dist/runtimes/existdb/mail.xq +124 -0
  25. package/dist/runtimes/existdb/ngram.xq +57 -0
  26. package/dist/runtimes/existdb/process.xq +8 -0
  27. package/dist/runtimes/existdb/range.xq +171 -0
  28. package/dist/runtimes/existdb/repo.xq +125 -0
  29. package/dist/runtimes/existdb/request.xq +242 -0
  30. package/dist/runtimes/existdb/response.xq +50 -0
  31. package/dist/runtimes/existdb/scheduler.xq +35 -0
  32. package/dist/runtimes/existdb/session.xq +111 -0
  33. package/dist/runtimes/existdb/sm.xq +497 -0
  34. package/dist/runtimes/existdb/sort.xq +59 -0
  35. package/dist/runtimes/existdb/system.xq +267 -0
  36. package/dist/runtimes/existdb/transform.xq +88 -0
  37. package/dist/runtimes/existdb/util.xq +892 -0
  38. package/dist/runtimes/existdb/validation.xq +83 -0
  39. package/dist/runtimes/existdb/xmldb.xq +482 -0
  40. package/dist/runtimes/existdb/xmldiff.xq +22 -0
  41. package/dist/runtimes/fonto/fonto.xq +164 -0
  42. package/dist/runtimes.js +40 -4
  43. package/dist/server.js +21 -70
  44. package/dist/types.d.ts +2 -0
  45. package/dist/unused-diagnostics.d.ts +1 -1
  46. package/dist/unused-diagnostics.js +57 -1
  47. package/logo.svg +6 -0
  48. package/package.json +2 -2
  49. package/src/analyzer.ts +8 -6
  50. package/src/diagnostics.ts +43 -0
  51. package/src/qt4-worker.ts +5 -9
  52. package/src/runtimes/existdb/exist.xq +29 -0
  53. package/src/runtimes.ts +41 -8
  54. package/src/server.ts +21 -75
  55. package/src/types.ts +2 -0
  56. package/src/unused-diagnostics.ts +59 -2
  57. package/src/runtimes/existdb/predeclared-namespaces.json +0 -34
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.6.0](https://github.com/DrRataplan/xq-lsp/compare/lsp-v1.5.0...lsp-v1.6.0) (2026-07-09)
4
+
5
+
6
+ ### Features
7
+
8
+ * add diagnostics for unused imports and namespace declarations ([0ded7ba](https://github.com/DrRataplan/xq-lsp/commit/0ded7ba26b98bc308ca59cf7061f8ade197a4d13))
9
+ * **claude-code:** add xq-lsp plugin for Claude Code ([aa96a4d](https://github.com/DrRataplan/xq-lsp/commit/aa96a4d5fdd9192e33be862608674d71e020017f))
10
+ * **vscode:** add XQuery 4.0 syntax highlighting grammar ([f2ee489](https://github.com/DrRataplan/xq-lsp/commit/f2ee489ff1ec3ab67f9142d6c039c559d28d5e67))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * add the $exist:* variables to the exist runtime ([4798582](https://github.com/DrRataplan/xq-lsp/commit/4798582c28f036c959432dbcca56edc81f7cca93))
16
+ * copy runtime files to dist and inline existdb predeclared namespaces ([e98b6d6](https://github.com/DrRataplan/xq-lsp/commit/e98b6d672ba504bba5dda30980b7a58cbdfcf847))
17
+ * **vscode:** recognize .xquery file extension ([7afc049](https://github.com/DrRataplan/xq-lsp/commit/7afc04913c1b02419c1965c489c32d09df1834b6))
18
+
3
19
  ## [1.5.0](https://github.com/DrRataplan/xq-lsp/compare/lsp-v1.4.1...lsp-v1.5.0) (2026-06-18)
4
20
 
5
21
 
package/README.md CHANGED
@@ -1,9 +1,12 @@
1
+ <img src="./logo.svg" alt="xq-lsp" width="48" height="48">
2
+
1
3
  # xq-lsp
2
4
 
3
5
  Language Server Protocol implementation for XQuery, providing autocompletion, hover documentation, signature help, go-to-definition, and diagnostics.
4
6
 
5
7
  ## Features
6
8
 
9
+ - **Syntax highlighting** — keywords, types, variables, operators, comments, and XQuery 4.0 tokens (VS Code extension)
7
10
  - **Completion** — functions declared in the current file, imported modules, and variables in scope
8
11
  - **Hover** — function signatures on hover
9
12
  - **Signature help** — active parameter hints inside function calls
@@ -234,4 +237,23 @@ npx vsce package
234
237
  code --install-extension xquery-lsp-vscode-*.vsix
235
238
  ```
236
239
 
237
- The extension registers `.xq`, `.xql`, `.xqm`, and `.xqy` files as XQuery and starts `xq-lsp` automatically when you open one.
240
+ The extension registers `.xq`, `.xql`, `.xqm`, `.xqy`, and `.xquery` files as XQuery, provides syntax highlighting via a bundled TextMate grammar, and starts `xq-lsp` automatically when you open one.
241
+
242
+ ## Claude Code
243
+
244
+ A plugin lives in [`editors/claude-code/`](./editors/claude-code/) that registers `xq-lsp` as a native LSP server for Claude Code, giving diagnostics, go-to-definition, find-references, and hover for XQuery files.
245
+
246
+ Make sure the `xq-lsp` binary is on `PATH`:
247
+
248
+ ```sh
249
+ npm install -g xq-lsp
250
+ ```
251
+
252
+ Then, from within Claude Code:
253
+
254
+ ```
255
+ /plugin marketplace add DrRataplan/xq-lsp
256
+ /plugin install xquery-lsp@xq-lsp
257
+ ```
258
+
259
+ See [`editors/claude-code/README.md`](./editors/claude-code/README.md) for local-development setup and details on what the plugin configures.
@@ -0,0 +1,6 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
2
+ <rect width="32" height="32" rx="7" fill="#1e1b4b"/>
3
+ <path d="M5 9 L11 16 L5 23" stroke="#a78bfa" stroke-width="3" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
4
+ <path d="M27 9 L21 16 L27 23" stroke="#a78bfa" stroke-width="3" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
5
+ <circle cx="16" cy="16" r="2.5" fill="#a78bfa"/>
6
+ </svg>
package/demo/index.html CHANGED
@@ -4,6 +4,7 @@
4
4
  <meta charset="utf-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
6
  <title>xq-lsp playground</title>
7
+ <link rel="icon" type="image/svg+xml" href="./favicon.svg" />
7
8
  <style>
8
9
  * {
9
10
  box-sizing: border-box;
@@ -132,6 +133,7 @@
132
133
  </head>
133
134
  <body>
134
135
  <header>
136
+ <img src="./favicon.svg" alt="" width="20" height="20" />
135
137
  <h1>xq-lsp playground</h1>
136
138
  <button id="share-btn">Copy link</button>
137
139
  </header>
package/demo/main.ts CHANGED
@@ -11,10 +11,7 @@ import builtinsMath from "../builtins/builtins-math.xq?raw";
11
11
  import builtinsMap from "../builtins/builtins-map.xq?raw";
12
12
  import builtinsArray from "../builtins/builtins-array.xq?raw";
13
13
  import { findUndeclaredPrefixUsages } from "../src/namespace-diagnostics.ts";
14
- import { checkTypes } from "../src/typechecker.ts";
15
- import { checkFunctionCalls } from "../src/functioncall-diagnostics.ts";
16
- import { checkUnused } from "../src/unused-diagnostics.ts";
17
- import { checkContextItemUsage } from "../src/context-item-diagnostics.ts";
14
+ import { runDiagnostics, runHints } from "../src/diagnostics.ts";
18
15
  import { type FileAnalysis } from "../src/types.ts";
19
16
  import { resolveFunctionAtOffset, resolveSignatureAtOffset, functionSignature } from "../src/hover-core.ts";
20
17
  import { getCompletions } from "../src/completion-core.ts";
@@ -238,18 +235,12 @@ const xqueryLinter = linter((view): Diagnostic[] => {
238
235
 
239
236
  if (ast) {
240
237
  const imported = getImported(analysis);
241
- for (const d of checkTypes(ast, code, analysis, new Map())) {
242
- diagnostics.push({ from: d.offset, to: d.offset + d.length, severity: "warning", message: d.message });
243
- }
244
- for (const d of checkFunctionCalls(ast, analysis, imported)) {
238
+ for (const d of runDiagnostics(ast, code, analysis, imported)) {
245
239
  diagnostics.push({ from: d.offset, to: d.offset + d.length, severity: "error", message: d.message });
246
240
  }
247
- for (const d of checkUnused(ast, analysis)) {
241
+ for (const d of runHints(ast, analysis)) {
248
242
  diagnostics.push({ from: d.offset, to: d.offset + d.length, severity: "hint", message: d.message });
249
243
  }
250
- for (const d of checkContextItemUsage(ast)) {
251
- diagnostics.push({ from: d.offset, to: d.offset + d.length, severity: "error", message: d.message });
252
- }
253
244
  }
254
245
 
255
246
  return diagnostics;
package/dist/analyzer.js CHANGED
@@ -291,7 +291,7 @@ function extractNamespaceDecls(ast) {
291
291
  const namespaceUri = uriNode ? stripQuotes(firstTerminalValue(uriNode) ?? "") : null;
292
292
  if (!namespaceUri)
293
293
  continue;
294
- results.push({ prefix, namespaceUri });
294
+ results.push({ prefix, namespaceUri, offset: ncname.start ?? nd.start ?? 0 });
295
295
  }
296
296
  return results;
297
297
  }
@@ -307,7 +307,7 @@ function extractImports(ast) {
307
307
  continue;
308
308
  const namespaceUri = stripQuotes(firstTerminalValue(uris[0]) ?? "");
309
309
  const atPath = uris.length >= 2 ? stripQuotes(firstTerminalValue(uris[1]) ?? "") : undefined;
310
- results.push({ prefix, namespaceUri, atPath });
310
+ results.push({ prefix, namespaceUri, atPath, offset: ncname.start ?? mi.start ?? 0 });
311
311
  }
312
312
  return results;
313
313
  }
@@ -338,8 +338,8 @@ const RE_FUNC = /declare\s+(?:%[\w:\-]+(?:\([^)]*\))?\s+)*function\s+([\w:\-]+)\
338
338
  const RE_VAR_DECL = /declare\s+(?:%[\w:\-]+(?:\([^)]*\))?\s+)*variable\s+\$([\w:\-]+)/g;
339
339
  const RE_LET = /\blet\s+\$([\w:\-]+)\s*:=/g;
340
340
  const RE_FOR = /\bfor\s+\$([\w:\-]+)\s+in\b/g;
341
- const RE_IMPORT = /import\s+module\s+namespace\s+([\w\-]+)\s*=\s*["']([^"']*)["'](?:\s+at\s+["']([^"']*)["'])?/g;
342
- const RE_NS_DECL = /declare\s+namespace\s+([\w\-]+)\s*=\s*["']([^"']*)["']/g;
341
+ const RE_IMPORT = /import\s+module\s+namespace\s+([\w\-]+)\s*=\s*["']([^"']*)["'](?:\s+at\s+["']([^"']*)["'])?/gd;
342
+ const RE_NS_DECL = /declare\s+namespace\s+([\w\-]+)\s*=\s*["']([^"']*)["']/gd;
343
343
  function analyzeRegex(text, sourceUri) {
344
344
  const moduleVariables = [];
345
345
  const localBindings = [];
@@ -350,7 +350,8 @@ function analyzeRegex(text, sourceUri) {
350
350
  const imports = [];
351
351
  RE_IMPORT.lastIndex = 0;
352
352
  while ((m = RE_IMPORT.exec(text)) !== null) {
353
- const imp = { prefix: m[1], namespaceUri: m[2] };
353
+ const indices = m.indices;
354
+ const imp = { prefix: m[1], namespaceUri: m[2], offset: indices[1][0] };
354
355
  if (m[3])
355
356
  imp.atPath = m[3];
356
357
  imports.push(imp);
@@ -358,7 +359,8 @@ function analyzeRegex(text, sourceUri) {
358
359
  const namespaceDecls = [];
359
360
  RE_NS_DECL.lastIndex = 0;
360
361
  while ((m = RE_NS_DECL.exec(text)) !== null) {
361
- namespaceDecls.push({ prefix: m[1], namespaceUri: m[2] });
362
+ const indices = m.indices;
363
+ namespaceDecls.push({ prefix: m[1], namespaceUri: m[2], offset: indices[1][0] });
362
364
  }
363
365
  const prefixMap = buildPrefixMap(moduleNs, imports, namespaceDecls);
364
366
  const functions = [];
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Central registry of all diagnostic checkers.
3
+ *
4
+ * Add every new checker here so qt4-worker, server, and the playground
5
+ * all stay in sync automatically.
6
+ */
7
+ import type { Node } from "xq-parser";
8
+ import type { TypeDiagnostic, FileAnalysis } from "./types.ts";
9
+ /**
10
+ * Run all error-level diagnostics (XQuery static/dynamic error codes).
11
+ * Safe to use in QT4 test coverage checks.
12
+ *
13
+ * @param imports Merged map of imported module analyses and built-in function libraries.
14
+ */
15
+ export declare function runDiagnostics(ast: Node, text: string, analysis: FileAnalysis, imports: Map<string, FileAnalysis>): TypeDiagnostic[];
16
+ /**
17
+ * Run hint-level diagnostics (unused functions/variables).
18
+ * Produces xq-lsp:* codes — kept separate to avoid false-positives in QT4 tests.
19
+ */
20
+ export declare function runHints(ast: Node, analysis: FileAnalysis): TypeDiagnostic[];
@@ -0,0 +1,28 @@
1
+ import { checkTypes } from "./typechecker.js";
2
+ import { checkFunctionCalls } from "./functioncall-diagnostics.js";
3
+ import { findUndeclaredPrefixUsages } from "./namespace-diagnostics.js";
4
+ import { checkContextItemUsage } from "./context-item-diagnostics.js";
5
+ import { checkUndeclaredVariables } from "./variable-diagnostics.js";
6
+ import { checkUnused } from "./unused-diagnostics.js";
7
+ /**
8
+ * Run all error-level diagnostics (XQuery static/dynamic error codes).
9
+ * Safe to use in QT4 test coverage checks.
10
+ *
11
+ * @param imports Merged map of imported module analyses and built-in function libraries.
12
+ */
13
+ export function runDiagnostics(ast, text, analysis, imports) {
14
+ return [
15
+ ...checkTypes(ast, text, analysis, imports),
16
+ ...checkFunctionCalls(ast, analysis, imports),
17
+ ...findUndeclaredPrefixUsages(ast, analysis),
18
+ ...checkContextItemUsage(ast),
19
+ ...checkUndeclaredVariables(ast, analysis, imports),
20
+ ];
21
+ }
22
+ /**
23
+ * Run hint-level diagnostics (unused functions/variables).
24
+ * Produces xq-lsp:* codes — kept separate to avoid false-positives in QT4 tests.
25
+ */
26
+ export function runHints(ast, analysis) {
27
+ return checkUnused(ast, analysis);
28
+ }
@@ -1,27 +1,21 @@
1
1
  import { workerData, parentPort } from "node:worker_threads";
2
2
  import { analyzeWithAst } from "./analyzer.js";
3
- import { checkTypes } from "./typechecker.js";
4
- import { checkFunctionCalls } from "./functioncall-diagnostics.js";
5
- import { findUndeclaredPrefixUsages } from "./namespace-diagnostics.js";
3
+ import { runDiagnostics } from "./diagnostics.js";
6
4
  import { getBuiltins } from "./builtins.js";
7
5
  const BUILTINS = new Map([["builtin:fn", getBuiltins()]]);
8
- function runDiagnostics(query, envNamespaces) {
6
+ function collectCodes(query, envNamespaces) {
9
7
  try {
10
8
  const { analysis, ast, parseError } = analyzeWithAst(query, "file:///test.xq");
11
9
  for (const ns of envNamespaces) {
12
10
  if (ns.prefix && !analysis.namespaceDecls.some((d) => d.prefix === ns.prefix)) {
13
- analysis.namespaceDecls.push({ prefix: ns.prefix, namespaceUri: ns.uri });
11
+ analysis.namespaceDecls.push({ prefix: ns.prefix, namespaceUri: ns.uri, offset: -1 });
14
12
  }
15
13
  }
16
14
  const codes = [];
17
15
  if (parseError)
18
16
  codes.push("XPST0003");
19
17
  if (ast) {
20
- for (const d of checkTypes(ast, query, analysis, BUILTINS))
21
- codes.push(d.code);
22
- for (const d of checkFunctionCalls(ast, analysis, BUILTINS))
23
- codes.push(d.code);
24
- for (const d of findUndeclaredPrefixUsages(ast, analysis))
18
+ for (const d of runDiagnostics(ast, query, analysis, BUILTINS))
25
19
  codes.push(d.code);
26
20
  }
27
21
  return [...new Set(codes)];
@@ -32,7 +26,7 @@ function runDiagnostics(query, envNamespaces) {
32
26
  }
33
27
  const batch = workerData;
34
28
  const results = batch.map((tc) => {
35
- const got = runDiagnostics(tc.query, tc.envNamespaces);
29
+ const got = collectCodes(tc.query, tc.envNamespaces);
36
30
  const hasError = got.length > 0;
37
31
  const outcome = tc.expected === "static-error"
38
32
  ? hasError
@@ -0,0 +1,83 @@
1
+ module namespace cache = "http://exist-db.org/xquery/cache";
2
+
3
+ (:~
4
+ : Eviction policy work of the cache is performed asynchronously. Performs any
5
+ : pending maintenance operations needed by the cache, on the current thread.
6
+ : Typically not needed by users, and only used for testing scenarios. Requires
7
+ : 'clear' permissions.
8
+ : @param $cache-name The name of the cache
9
+ :)
10
+ declare function cache:cleanup($cache-name as xs:string) as empty-sequence() external;
11
+
12
+ (:~
13
+ : Clears all key/values from either all caches or the named cache
14
+ :)
15
+ declare function cache:clear() as empty-sequence() external;
16
+
17
+ (:~
18
+ : Clears all key/values from either all caches or the named cache
19
+ : @param $cache-name The name of the cache
20
+ :)
21
+ declare function cache:clear($cache-name as xs:string) as empty-sequence() external;
22
+
23
+ (:~
24
+ : Explicitly create a cache with a specific configuration
25
+ : @param $cache-name The name of the cache
26
+ : @param $config A map with configuration for the cache. At present cache LRU and permission groups may be specified, for operations on the cache. `maximumSize` is optional and specifies the maximum number of entries. `expireAfterAccess` is optional and specifies the expiry period for infrequently accessed entries (in milliseconds). `expireAfterWrite` is optional and specifies the expiry period after the entry's creation, or the most recent replacement of its value (in milliseconds). If a permission group is not specified for an operation, then permissions are not checked for that operation. Should have the format: map { "maximumSize": 1000, "expireAfterAccess": 120000, "expireAfterWrite": 240000, "permissions": map { "put-group": "group1", "get-group": "group2", "remove-group": "group3", "clear-group": "group4"} }
27
+ : @return true if the cache was created, false if the cache already exists
28
+ :)
29
+ declare function cache:create($cache-name as xs:string, $config as map(*)) as xs:boolean external;
30
+
31
+ (:~
32
+ : Destroys a cache entirely
33
+ : @param $cache-name The name of the cache
34
+ :)
35
+ declare function cache:destroy($cache-name as xs:string) as empty-sequence() external;
36
+
37
+ (:~
38
+ : Get data from identified global cache by key
39
+ : @param $cache-name The name of the cache
40
+ : @param $key The key
41
+ : @return The value associated with the key
42
+ :)
43
+ declare function cache:get($cache-name as xs:string, $key as xs:anyType+) as item()* external;
44
+
45
+ (:~
46
+ : List all keys stored in a cache. Note this operation is expensive.
47
+ : @param $cache-name The name of the cache
48
+ : @return The keys in the cache. Note these will be returned in serialized string form, as that is used internally.
49
+ :)
50
+ declare function cache:keys($cache-name as xs:string) as xs:string* external;
51
+
52
+ (:~
53
+ : List all values (for the associated keys) stored in a cache.
54
+ : @param $cache-name The name of the cache
55
+ : @param $keys The keys, if none are specified, all values are returned
56
+ : @return The values associated with the keys
57
+ :)
58
+ declare function cache:list($cache-name as xs:string, $keys as xs:anyType*) as item()* external;
59
+
60
+ (:~
61
+ : Get the names of all current caches
62
+ : @return The names of all caches currently in use.
63
+ :)
64
+ declare function cache:names() as xs:string* external;
65
+
66
+ (:~
67
+ : Put data with a key into the identified cache. Returns the previous value
68
+ : associated with the key
69
+ : @param $cache-name The name of the cache
70
+ : @param $key The key
71
+ : @param $value The value
72
+ : @return The previous value associated with the key
73
+ :)
74
+ declare function cache:put($cache-name as xs:string, $key as xs:anyType+, $value as item()*) as item()* external;
75
+
76
+ (:~
77
+ : Remove data from the identified cache by the key. Returns the value that was
78
+ : previously associated with key
79
+ : @param $cache-name The name of the cache
80
+ : @param $key The key
81
+ : @return The value that was previously associated with the key
82
+ :)
83
+ declare function cache:remove($cache-name as xs:string, $key as xs:anyType+) as item()* external;
@@ -0,0 +1,198 @@
1
+ module namespace compression = "http://exist-db.org/xquery/compression";
2
+
3
+ (:~
4
+ : Stores an entry to the database. Attempts to guard against exit attacks; If
5
+ : an exit attack is detected then the error `compression:archive-exit-attack
6
+ : is raised`.
7
+ : @param $destination A path to a Collection in the database where the entry should be extracted. If the Collection does not exist it will be created.
8
+ : @return A function suitable for passing as the $entry-data#3
9
+ :)
10
+ declare function compression:db-store-entry3($destination as xs:string?) as function(*) external;
11
+
12
+ (:~
13
+ : Stores an entry to the database. Attempts to guard against exit attacks; If
14
+ : an exit attack is detected then the error `compression:archive-exit-attack
15
+ : is raised`.
16
+ : @param $destination A path to a Collection in the database where the entry should be extracted. If the Collection does not exist it will be created.
17
+ : @return A function suitable for passing as the $entry-data#4
18
+ :)
19
+ declare function compression:db-store-entry4($destination as xs:string?) as function(*) external;
20
+
21
+ (:~
22
+ : Deflate data (RFC 1950)
23
+ : @param $data The data to Deflate
24
+ :)
25
+ declare function compression:deflate($data as xs:base64Binary) as xs:base64Binary? external;
26
+
27
+ (:~
28
+ : Deflate data (RFC 1951)
29
+ : @param $data The data to Deflate
30
+ : @param $raw If true, create raw deflate data that is not wrapped inside zlib header and checksum.
31
+ :)
32
+ declare function compression:deflate($data as xs:base64Binary, $raw as xs:boolean) as xs:base64Binary? external;
33
+
34
+ (:~
35
+ : Stores an entry to the filesystem. This method is only available to the DBA
36
+ : role. Attempts to guard against exit attacks; If an exit attack is detected
37
+ : then the error `compression:archive-exit-attack is raised`.
38
+ : @param $destination A path to a directory on the filesystem where the entry should be extracted. If the path does not exist it will be created.
39
+ : @return A function suitable for passing as the $entry-data#3
40
+ :)
41
+ declare function compression:fs-store-entry3($destination as xs:string?) as function(*) external;
42
+
43
+ (:~
44
+ : Stores an entry to the filesystem. This method is only available to the DBA
45
+ : role. Attempts to guard against exit attacks; If an exit attack is detected
46
+ : then the error `compression:archive-exit-attack is raised`.
47
+ : @param $destination A path to a directory on the filesystem where the entry should be extracted. If the path does not exist it will be created.
48
+ : @return A function suitable for passing as the $entry-data#4
49
+ :)
50
+ declare function compression:fs-store-entry4($destination as xs:string?) as function(*) external;
51
+
52
+ (:~
53
+ : GZip's data
54
+ : @param $data The data to GZip
55
+ :)
56
+ declare function compression:gzip($data as xs:base64Binary) as xs:base64Binary? external;
57
+
58
+ (:~
59
+ : Inflate data (RFC 1950)
60
+ : @param $inflate-data The inflate data to uncompress.
61
+ :)
62
+ declare function compression:inflate($inflate-data as xs:base64Binary) as xs:base64Binary? external;
63
+
64
+ (:~
65
+ : Inflate data (RFC 1951)
66
+ : @param $inflate-data The inflate data to uncompress.
67
+ : @param $raw If true, expect raw deflate data that is not wrapped inside zlib header and checksum.
68
+ :)
69
+ declare function compression:inflate($inflate-data as xs:base64Binary, $raw as xs:boolean) as xs:base64Binary? external;
70
+
71
+ (:~
72
+ : Does not filter any entries.
73
+ : @param $path The path of the entry
74
+ : @param $data-type The type of the entry, either 'directory' or 'resource'.
75
+ : @return Always true, so that no entries are filtered. Parameters are ignored.
76
+ :)
77
+ declare function compression:no-filter($path as xs:string, $data-type as xs:string) as xs:boolean external;
78
+
79
+ (:~
80
+ : Does not filter any entries.
81
+ : @param $path The path of the entry
82
+ : @param $data-type The type of the entry, either 'directory' or 'resource'.
83
+ : @param $param One or more parameters.
84
+ : @return Always true, so that no entries are filtered. Parameters are ignored.
85
+ :)
86
+ declare function compression:no-filter(
87
+ $path as xs:string,
88
+ $data-type as xs:string,
89
+ $param as item()*
90
+ ) as xs:boolean external;
91
+
92
+ declare function compression:tar() as xs:base64Binary* external;
93
+
94
+ (:~
95
+ : UnGZip's data
96
+ : @param $gzip-data The gzip data to uncompress.
97
+ :)
98
+ declare function compression:ungzip($gzip-data as xs:base64Binary) as xs:base64Binary? external;
99
+
100
+ (:~
101
+ : UnTar all the resources/folders from the provided data by calling user
102
+ : defined functions to determine what and how to store the resources/folders
103
+ : @param $tar-data The tar file data
104
+ : @param $entry-filter A user defined function for filtering resources from the tar file. The function takes 2 parameters e.g. user:untar-entry-filter($path as xs:string, $data-type as xs:string) as xs:boolean. $data-type may be 'resource' or 'folder'. If the return type is true() it indicates the entry should be processed and passed to the entry-data function, else the resource is skipped. If you wish to extract all resources you can use the provided compression:no-filter#2 function.
105
+ : @param $entry-data A user defined function for storing an extracted resource from the tar file. The function takes 3 parameters e.g. user:untar-entry-data($path as xs:string, $data-type as xs:string, $data as item()?). Or a user defined function which returns a db path for storing an extracted resource from the tar file. The function takes 3 parameters e.g. user:entry-path($path as xs:string, $data-type as xs:string, $param as item()*) as xs:anyURI. $data-type may be 'resource' or 'folder'. Functions for storing the entries to a folder on the filesystem or a collection in the database provided by compression:fs-store-entry3($dest) and compression:db-store-entry3($dest).
106
+ :)
107
+ declare function compression:untar(
108
+ $tar-data as xs:base64Binary,
109
+ $entry-filter as function(*),
110
+ $entry-data as function(*)
111
+ ) as item()* external;
112
+
113
+ (:~
114
+ : UnTar all the resources/folders from the provided data by calling user
115
+ : defined functions to determine what and how to store the resources/folders
116
+ : @param $tar-data The tar file data
117
+ : @param $entry-filter A user defined function for filtering resources from the tar file. The function takes 3 parameters e.g. user:untar-entry-filter($path as xs:string, $data-type as xs:string, $param as item()*) as xs:boolean. $data-type may be 'resource' or 'folder'. $param is a sequence with any additional parameters, for example a list of extracted files. If the return type is true() it indicates the entry should be processed and passed to the entry-data function, else the resource is skipped. If you wish to extract all resources you can use the provided compression:no-filter#3 function.
118
+ : @param $entry-filter-param A sequence with an additional parameters for filtering function.
119
+ : @param $entry-data A user defined function for storing an extracted resource from the tar file. The function takes 4 parameters e.g. user:untar-entry-data($path as xs:string, $data-type as xs:string, $data as item()?, $param as item()*). Or a user defined function which returns a db path for storing an extracted resource from the tar file. The function takes 3 parameters e.g. user:entry-path($path as xs:string, $data-type as xs:string, $param as item()*) as xs:anyURI. $data-type may be 'resource' or 'folder'. $param is a sequence with any additional parameters Functions for storing the entries to a folder on the filesystem or a collection in the database provided by compression:fs-store-entry4($dest) and compression:db-store-entry4($dest).
120
+ : @param $entry-data-param A sequence with an additional parameters for storing function.
121
+ :)
122
+ declare function compression:untar(
123
+ $tar-data as xs:base64Binary,
124
+ $entry-filter as function(*),
125
+ $entry-filter-param as xs:anyType*,
126
+ $entry-data as function(*),
127
+ $entry-data-param as xs:anyType*
128
+ ) as item()* external;
129
+
130
+ (:~
131
+ : UnTar all the resources/folders from the provided data by calling user
132
+ : defined functions to determine what and how to store the resources/folders
133
+ : @param $tar-data The tar file data
134
+ : @param $entry-filter A user defined function for filtering resources from the tar file. The function takes 3 parameters e.g. user:untar-entry-filter($path as xs:string, $data-type as xs:string, $param as item()*) as xs:boolean. $data-type may be 'resource' or 'folder'. $param is a sequence with any additional parameters, for example a list of extracted files. If the return type is true() it indicates the entry should be processed and passed to the entry-data function, else the resource is skipped. If you wish to extract all resources you can use the provided compression:no-filter#3 function.
135
+ : @param $entry-filter-param A sequence with an additional parameters for filtering function.
136
+ : @param $entry-data A user defined function for storing an extracted resource from the tar file. The function takes 4 parameters e.g. user:untar-entry-data($path as xs:string, $data-type as xs:string, $data as item()?, $param as item()*). Or a user defined function which returns a db path for storing an extracted resource from the tar file. The function takes 3 parameters e.g. user:entry-path($path as xs:string, $data-type as xs:string, $param as item()*) as xs:anyURI. $data-type may be 'resource' or 'folder'. $param is a sequence with any additional parameters Functions for storing the entries to a folder on the filesystem or a collection in the database provided by compression:fs-store-entry4($dest) and compression:db-store-entry4($dest).
137
+ : @param $entry-data-param A sequence with an additional parameters for storing function.
138
+ : @param $encoding The encoding to be used during uncompressing eg: UTF8 or Cp437 from https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html
139
+ :)
140
+ declare function compression:untar(
141
+ $tar-data as xs:base64Binary,
142
+ $entry-filter as function(*),
143
+ $entry-filter-param as xs:anyType*,
144
+ $entry-data as function(*),
145
+ $entry-data-param as xs:anyType*,
146
+ $encoding as xs:string
147
+ ) as item()* external;
148
+
149
+ (:~
150
+ : UnZip all the resources/folders from the provided data by calling user
151
+ : defined functions to determine what and how to store the resources/folders
152
+ : @param $zip-data The zip file data
153
+ : @param $entry-filter A user defined function for filtering resources from the zip file. The function takes 2 parameters e.g. user:unzip-entry-filter($path as xs:string, $data-type as xs:string) as xs:boolean. $data-type may be 'resource' or 'folder'. If the return type is true() it indicates the entry should be processed and passed to the $entry-data function, else the resource is skipped. If you wish to extract all resources you can use the provided compression:no-filter#2 function.
154
+ : @param $entry-data A user defined function for storing an extracted resource from the zip file. The function takes 3 parameters e.g. user:unzip-entry-data($path as xs:string, $data-type as xs:string, $data as item()?). Or a user defined function which returns a db path for storing an extracted resource from the zip file. The function takes 3 parameters e.g. user:entry-path($path as xs:string, $data-type as xs:string, $param as item()*) as xs:anyURI. $data-type may be 'resource' or 'folder'. Functions for storing the entries to a folder on the filesystem or a collection in the database provided by compression:fs-store-entry3($dest) and compression:db-store-entry3($dest).
155
+ :)
156
+ declare function compression:unzip(
157
+ $zip-data as xs:base64Binary,
158
+ $entry-filter as function(*),
159
+ $entry-data as function(*)
160
+ ) as item()* external;
161
+
162
+ (:~
163
+ : UnZip all the resources/folders from the provided data by calling user
164
+ : defined functions to determine what and how to store the resources/folders
165
+ : @param $zip-data The zip file data
166
+ : @param $entry-filter A user defined function for filtering resources from the zip file. The function takes 3 parameters e.g. user:unzip-entry-filter($path as xs:string, $data-type as xs:string, $param as item()*) as xs:boolean. $data-type may be 'resource' or 'folder'. $param is a sequence with any additional parameters, for example a list of extracted files. If the return type is true() it indicates the entry should be processed and passed to the $entry-data function, else the resource is skipped. If you wish to extract all resources you can use the provided compression:no-filter#3 function.
167
+ : @param $entry-filter-param A sequence with an additional parameters for filtering function.
168
+ : @param $entry-data A user defined function for storing an extracted resource from the zip file. The function takes 4 parameters e.g. user:unzip-entry-data($path as xs:string, $data-type as xs:string, $data as item()?, $param as item()*). Or a user defined function which returns a db path for storing an extracted resource from the zip file. The function takes 3 parameters e.g. user:entry-path($path as xs:string, $data-type as xs:string, $param as item()*) as xs:anyURI. $data-type may be 'resource' or 'folder'. $param is a sequence with any additional parameters. Functions for storing the entries to a folder on the filesystem or a collection in the database provided by compression:fs-store-entry4($dest) and compression:db-store-entry4($dest).
169
+ : @param $entry-data-param A sequence with an additional parameters for storing function.
170
+ :)
171
+ declare function compression:unzip(
172
+ $zip-data as xs:base64Binary,
173
+ $entry-filter as function(*),
174
+ $entry-filter-param as xs:anyType*,
175
+ $entry-data as function(*),
176
+ $entry-data-param as xs:anyType*
177
+ ) as item()* external;
178
+
179
+ (:~
180
+ : UnZip all the resources/folders from the provided data by calling user
181
+ : defined functions to determine what and how to store the resources/folders
182
+ : @param $zip-data The zip file data
183
+ : @param $entry-filter A user defined function for filtering resources from the zip file. The function takes 3 parameters e.g. user:unzip-entry-filter($path as xs:string, $data-type as xs:string, $param as item()*) as xs:boolean. $data-type may be 'resource' or 'folder'. $param is a sequence with any additional parameters, for example a list of extracted files. If the return type is true() it indicates the entry should be processed and passed to the $entry-data function, else the resource is skipped. If you wish to extract all resources you can use the provided compression:no-filter#3 function.
184
+ : @param $entry-filter-param A sequence with an additional parameters for filtering function.
185
+ : @param $entry-data A user defined function for storing an extracted resource from the zip file. The function takes 4 parameters e.g. user:unzip-entry-data($path as xs:string, $data-type as xs:string, $data as item()?, $param as item()*). Or a user defined function which returns a db path for storing an extracted resource from the zip file. The function takes 3 parameters e.g. user:entry-path($path as xs:string, $data-type as xs:string, $param as item()*) as xs:anyURI. $data-type may be 'resource' or 'folder'. $param is a sequence with any additional parameters. Functions for storing the entries to a folder on the filesystem or a collection in the database provided by compression:fs-store-entry4($dest) and compression:db-store-entry4($dest).
186
+ : @param $entry-data-param A sequence with an additional parameters for storing function.
187
+ : @param $encoding The encoding to be used during uncompressing eg: UTF8 or Cp437 from https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html
188
+ :)
189
+ declare function compression:unzip(
190
+ $zip-data as xs:base64Binary,
191
+ $entry-filter as function(*),
192
+ $entry-filter-param as xs:anyType*,
193
+ $entry-data as function(*),
194
+ $entry-data-param as xs:anyType*,
195
+ $encoding as xs:string
196
+ ) as item()* external;
197
+
198
+ declare function compression:zip() as xs:base64Binary* external;
@@ -0,0 +1,24 @@
1
+ module namespace console = "http://exist-db.org/xquery/console";
2
+
3
+ (:~
4
+ : Log items to the 'default' console channel.
5
+ : @param $items Values to log.
6
+ : @return Empty
7
+ :)
8
+ declare function console:log($items as item()*) as empty-sequence() external;
9
+
10
+ (:~
11
+ : Log items to a specific console channel.
12
+ : @param $channel The channel to log to.
13
+ : @param $items Values to log.
14
+ : @return Empty
15
+ :)
16
+ declare function console:log($channel as xs:string, $items as item()*) as empty-sequence() external;
17
+
18
+ (:~
19
+ : Send a JSON message to a console channel.
20
+ : @param $channel The channel to send to.
21
+ : @param $items Value to send as JSON.
22
+ : @return Empty
23
+ :)
24
+ declare function console:send($channel as xs:string, $items as item()?) as empty-sequence() external;
@@ -0,0 +1,31 @@
1
+ module namespace contentextraction = "http://exist-db.org/xquery/contentextraction";
2
+
3
+ (:~
4
+ : extracts the metadata
5
+ : @param $binary The binary data to extract from
6
+ : @return Extracted metadata
7
+ :)
8
+ declare function contentextraction:get-metadata($binary as xs:base64Binary) as document-node() external;
9
+
10
+ (:~
11
+ : extracts the metadata and contents
12
+ : @param $binary The binary data to extract from
13
+ : @return Extracted content and metadata
14
+ :)
15
+ declare function contentextraction:get-metadata-and-content($binary as xs:base64Binary) as document-node() external;
16
+
17
+ (:~
18
+ : extracts the metadata
19
+ : @param $binary The binary data to extract from
20
+ : @param $callback The callback function. Expected signature:
21
+ : @param $namespaces Prefix/namespace mappings to be used for matching the paths. Pass an XML fragment with the following structure: <namespaces><namespace prefix="prefix" uri="uri"/></namespaces>.
22
+ : @param $userData Additional data which will be passed to the callback function.
23
+ : @return Returns empty sequence
24
+ :)
25
+ declare function contentextraction:stream-content(
26
+ $binary as xs:base64Binary,
27
+ $paths as xs:string*,
28
+ $callback as function(*),
29
+ $namespaces as element()?,
30
+ $userData as item()*
31
+ ) as empty-sequence() external;
@@ -0,0 +1,30 @@
1
+ module namespace counter = "http://exist-db.org/xquery/counter";
2
+
3
+ (:~
4
+ : Create a unique counter named $counter-name.
5
+ : @param $counter-name Name of the counter.
6
+ : @return the value of the newly created counter.
7
+ :)
8
+ declare function counter:create($counter-name as item()) as xs:long? external;
9
+
10
+ (:~
11
+ : Create a unique counter named $counter-name and initialize it with value
12
+ : $init-value.
13
+ : @param $counter-name Name of the counter.
14
+ : @param $init-value The initial value of the counter.
15
+ : @return the value of the newly created counter.
16
+ :)
17
+ declare function counter:create($counter-name as item(), $init-value as xs:long) as xs:long? external;
18
+
19
+ (:~
20
+ : Destroy the counter named $counter-name.
21
+ : @param $counter-name Name of the counter.
22
+ :)
23
+ declare function counter:destroy($counter-name as item()) as xs:boolean? external;
24
+
25
+ (:~
26
+ : Increment the counter $counter-name and return its new value.
27
+ : @param $counter-name Name of the counter.
28
+ : @return the new value of the specified counter, or -1 if the counter does not exist.
29
+ :)
30
+ declare function counter:next-value($counter-name as item()) as xs:long? external;