From 767d75221f2fe51aa58db515e37bcc7c4a547541 Mon Sep 17 00:00:00 2001 From: rajsite Date: Tue, 30 Jul 2024 00:30:59 -0500 Subject: [PATCH] Deno KV string key and val --- Deno/Deno.gwebproject | 4 +- .../DenoKV/simple.test.gviweb | 568 ++++++++++++++++++ .../SmokeTests.gcomp/SmokeTests.gcomp | 6 +- .../Components/DenoKV.gcomp/DenoKV.gcomp | 55 ++ .../Components/DenoKV.gcomp/KV Close.gvi | 228 +++++++ .../Components/DenoKV.gcomp/KV Get String.gvi | 297 +++++++++ .../Components/DenoKV.gcomp/KV Open.gvi | 248 ++++++++ .../Components/DenoKV.gcomp/KV Set String.gvi | 297 +++++++++ .../Components/DenoKV.gcomp/Support/DenoKV.js | 1 + .../DenoKV.gcomp/Support/DenoKV.jsli | 216 +++++++ .../kv reference.gtype/kv reference.gtype | 43 ++ Deno/Library/Support/DenoKV/deno-kv.ts | 42 ++ Deno/deno.json | 6 +- 13 files changed, 2006 insertions(+), 5 deletions(-) create mode 100644 Deno/Examples/SmokeTests.gcomp/DenoKV/simple.test.gviweb create mode 100644 Deno/Library/Components/DenoKV.gcomp/DenoKV.gcomp create mode 100644 Deno/Library/Components/DenoKV.gcomp/KV Close.gvi create mode 100644 Deno/Library/Components/DenoKV.gcomp/KV Get String.gvi create mode 100644 Deno/Library/Components/DenoKV.gcomp/KV Open.gvi create mode 100644 Deno/Library/Components/DenoKV.gcomp/KV Set String.gvi create mode 100644 Deno/Library/Components/DenoKV.gcomp/Support/DenoKV.js create mode 100644 Deno/Library/Components/DenoKV.gcomp/Support/DenoKV.jsli create mode 100644 Deno/Library/Components/DenoKV.gcomp/Support/kv reference.gtype/kv reference.gtype create mode 100644 Deno/Library/Support/DenoKV/deno-kv.ts diff --git a/Deno/Deno.gwebproject b/Deno/Deno.gwebproject index ee203c57..17caebb3 100644 --- a/Deno/Deno.gwebproject +++ b/Deno/Deno.gwebproject @@ -1,5 +1,5 @@  - + @@ -83,6 +83,7 @@ + @@ -128,6 +129,7 @@ + diff --git a/Deno/Examples/SmokeTests.gcomp/DenoKV/simple.test.gviweb b/Deno/Examples/SmokeTests.gcomp/DenoKV/simple.test.gviweb new file mode 100644 index 00000000..a2f2560b --- /dev/null +++ b/Deno/Examples/SmokeTests.gcomp/DenoKV/simple.test.gviweb @@ -0,0 +1,568 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + :memory: + + + + path url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + writing kv + + + + message + + + + + + + + + + + + + + + + + + + + + + + + + + H4sIAAAAAAAEAGNgZGBg+A8EIBoEBEAMJiBmAxEsJanFJWzMIG5xZm5BTio3AK35Di0xAAAA + + + + "" + + + + + + + key + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + read kv + + + + message + + + + my value + + + + value + + + + + + + + + + + + + + + + + + + + + key result: + + + + string {0} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Deno/Examples/SmokeTests.gcomp/SmokeTests.gcomp b/Deno/Examples/SmokeTests.gcomp/SmokeTests.gcomp index a02b4cc9..8eaf2e4e 100644 --- a/Deno/Examples/SmokeTests.gcomp/SmokeTests.gcomp +++ b/Deno/Examples/SmokeTests.gcomp/SmokeTests.gcomp @@ -1,5 +1,5 @@  - + @@ -21,6 +21,7 @@ + @@ -42,6 +43,9 @@ + + + diff --git a/Deno/Library/Components/DenoKV.gcomp/DenoKV.gcomp b/Deno/Library/Components/DenoKV.gcomp/DenoKV.gcomp new file mode 100644 index 00000000..50768130 --- /dev/null +++ b/Deno/Library/Components/DenoKV.gcomp/DenoKV.gcomp @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Deno/Library/Components/DenoKV.gcomp/KV Close.gvi b/Deno/Library/Components/DenoKV.gcomp/KV Close.gvi new file mode 100644 index 00000000..c6c6b7c4 --- /dev/null +++ b/Deno/Library/Components/DenoKV.gcomp/KV Close.gvi @@ -0,0 +1,228 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + error in + + + + + + + + kv reference + + + + + + + error out + + + + + + + + + + + + + + + + + + + + + False + 0 + "" + + + + + + + + 0 + + + + + + + + False + 0 + "" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Deno/Library/Components/DenoKV.gcomp/KV Get String.gvi b/Deno/Library/Components/DenoKV.gcomp/KV Get String.gvi new file mode 100644 index 00000000..881056ac --- /dev/null +++ b/Deno/Library/Components/DenoKV.gcomp/KV Get String.gvi @@ -0,0 +1,297 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + kv reference in + + + + + + kv reference out + + + + + + key + + + + + + + + + value + + + + + + error out + + + + + + + error in + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + 0 + + + + + + + + + + + "" + + + + + False + 0 + "" + + + + + + + + + + False + 0 + "" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Deno/Library/Components/DenoKV.gcomp/KV Open.gvi b/Deno/Library/Components/DenoKV.gcomp/KV Open.gvi new file mode 100644 index 00000000..f1e94ce5 --- /dev/null +++ b/Deno/Library/Components/DenoKV.gcomp/KV Open.gvi @@ -0,0 +1,248 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + error out + + + + + + + error in + + + + + + + kv reference + + + + + + + path url + + + + + + + + + + + + + + + + + + + + + False + 0 + "" + + + + + + + + + + False + 0 + "" + + + + + + + + 0 + + + + + + "" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Deno/Library/Components/DenoKV.gcomp/KV Set String.gvi b/Deno/Library/Components/DenoKV.gcomp/KV Set String.gvi new file mode 100644 index 00000000..3ad4b893 --- /dev/null +++ b/Deno/Library/Components/DenoKV.gcomp/KV Set String.gvi @@ -0,0 +1,297 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + kv reference in + + + + + + kv reference out + + + + + + + key + + + + + + + + + + value + + + + + + + error out + + + + + + + error in + + + + + + + + + + + + + + + + + + + 0 + + + + + + 0 + + + + + + + + + + + "" + + + + + False + 0 + "" + + + + + + + + + + False + 0 + "" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Deno/Library/Components/DenoKV.gcomp/Support/DenoKV.js b/Deno/Library/Components/DenoKV.gcomp/Support/DenoKV.js new file mode 100644 index 00000000..18b1d059 --- /dev/null +++ b/Deno/Library/Components/DenoKV.gcomp/Support/DenoKV.js @@ -0,0 +1 @@ +import '../../../../Library/Support/DenoKV/deno-kv.ts'; diff --git a/Deno/Library/Components/DenoKV.gcomp/Support/DenoKV.jsli b/Deno/Library/Components/DenoKV.gcomp/Support/DenoKV.jsli new file mode 100644 index 00000000..24af38d3 --- /dev/null +++ b/Deno/Library/Components/DenoKV.gcomp/Support/DenoKV.jsli @@ -0,0 +1,216 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Deno/Library/Components/DenoKV.gcomp/Support/kv reference.gtype/kv reference.gtype b/Deno/Library/Components/DenoKV.gcomp/Support/kv reference.gtype/kv reference.gtype new file mode 100644 index 00000000..0b65c441 --- /dev/null +++ b/Deno/Library/Components/DenoKV.gcomp/Support/kv reference.gtype/kv reference.gtype @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Deno/Library/Support/DenoKV/deno-kv.ts b/Deno/Library/Support/DenoKV/deno-kv.ts new file mode 100644 index 00000000..30b2f7b3 --- /dev/null +++ b/Deno/Library/Support/DenoKV/deno-kv.ts @@ -0,0 +1,42 @@ +import { fromFileUrl } from '@std/path'; + +const kvOpen = async (pathURL: string) => { + let path; + if (pathURL === '') { + path = undefined; + } else if (pathURL === ':memory:') { + path = pathURL; + } else { + path = fromFileUrl(pathURL); + } + const kvReference = await Deno.openKv(path); + return kvReference; +}; + +const kvSetString = async (kvReference: Deno.Kv, keyJSON: string, value: string) => { + const key = JSON.parse(keyJSON) as string[]; + await kvReference.set(key, value); +}; + +const kvGetString = async (kvReference: Deno.Kv, keyJSON: string) => { + const key = JSON.parse(keyJSON) as string[]; + const result = await kvReference.get(key); + return result.value; +}; + +const kvClose = (kvReference: Deno.Kv) => { + kvReference.close(); +}; + +const api = { + kvOpen, + kvClose, + kvSetString, + kvGetString +} as const; + +declare namespace globalThis { + let WebVIDenoKV: typeof api; +} + +globalThis.WebVIDenoKV = api; diff --git a/Deno/deno.json b/Deno/deno.json index aa32382b..18f58862 100644 --- a/Deno/deno.json +++ b/Deno/deno.json @@ -3,11 +3,11 @@ "simple:start": "export COMPONENT=SimpleServer && deno task tool:start:main", "simple:publish": "export COMPONENT=SimpleServer && deno task tool:publish:main", "simple:compile": "export COMPONENT=SimpleServer && deno task tool:compile:main", - "test": "deno task build && deno test -A", + "test": "deno task build && deno test --unstable-kv -A", "build": "deno task tool:build:gweb && deno task tool:build:deno", - "tool:start:main": "deno task build && deno run -A \"./Builds/$(echo $COMPONENT)_Default Web Server/main.ts\"", + "tool:start:main": "deno task build && deno run --unstable-kv -A \"./Builds/$(echo $COMPONENT)_Default Web Server/main.ts\"", "tool:publish:main": "deno task build && deployctl deploy --entrypoint=\"./Builds/$(echo $COMPONENT)_Default Web Server/main.ts\" --import-map=./deno.json", - "tool:compile:main": "deno task build && deno compile -A -o \"./$(echo $COMPONENT).exe\" \"./Builds/$(echo $COMPONENT)_Default Web Server/main.ts\"", + "tool:compile:main": "deno task build && deno compile --unstable-kv -A -o \"./$(echo $COMPONENT).exe\" \"./Builds/$(echo $COMPONENT)_Default Web Server/main.ts\"", "tool:build:gweb": "\"C:/Program Files/National Instruments/G Web Development Software/gwebcli.exe\" distribution -p Deno.gwebproject --dn Deno.lvdist", "tool:build:deno": "deno run -A ./Support/convert-html.ts ./Builds/**/*.via.txt", "tool:rebuild-vireo-data-url": "deno run -A ./Support/make-vireo-dataurl.ts",