@tishlang/tish 1.7.0 → 1.9.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 (99) hide show
  1. package/Cargo.toml +2 -0
  2. package/README.md +2 -0
  3. package/bin/tish +0 -0
  4. package/crates/js_to_tish/src/transform/expr.rs +28 -8
  5. package/crates/js_to_tish/src/transform/stmt.rs +49 -22
  6. package/crates/tish/Cargo.toml +14 -5
  7. package/crates/tish/src/cargo_native_registry.rs +29 -0
  8. package/crates/tish/src/cli_help.rs +16 -10
  9. package/crates/tish/src/main.rs +87 -32
  10. package/crates/tish/src/repl_completion.rs +3 -3
  11. package/crates/tish/tests/cargo_example_compile.rs +1 -1
  12. package/crates/tish/tests/integration_test.rs +19 -7
  13. package/crates/tish/tests/shortcircuit.rs +1 -1
  14. package/crates/tish_ast/src/ast.rs +80 -9
  15. package/crates/tish_build_utils/Cargo.toml +4 -0
  16. package/crates/tish_build_utils/src/lib.rs +105 -2
  17. package/crates/tish_builtins/Cargo.toml +5 -1
  18. package/crates/tish_builtins/src/array.rs +13 -12
  19. package/crates/tish_builtins/src/construct.rs +34 -33
  20. package/crates/tish_builtins/src/globals.rs +12 -11
  21. package/crates/tish_builtins/src/helpers.rs +2 -1
  22. package/crates/tish_builtins/src/object.rs +3 -2
  23. package/crates/tish_builtins/src/string.rs +73 -3
  24. package/crates/tish_bytecode/src/compiler.rs +12 -14
  25. package/crates/tish_bytecode/src/opcode.rs +12 -3
  26. package/crates/tish_compile/Cargo.toml +1 -0
  27. package/crates/tish_compile/src/codegen.rs +745 -199
  28. package/crates/tish_compile/src/infer.rs +6 -0
  29. package/crates/tish_compile/src/lib.rs +4 -3
  30. package/crates/tish_compile/src/resolve.rs +180 -82
  31. package/crates/tish_compile/src/types.rs +175 -11
  32. package/crates/tish_compile_js/Cargo.toml +1 -0
  33. package/crates/tish_compile_js/src/codegen.rs +152 -29
  34. package/crates/tish_compile_js/src/lib.rs +3 -1
  35. package/crates/tish_compiler_wasm/src/resolve_virtual.rs +31 -12
  36. package/crates/tish_core/Cargo.toml +8 -0
  37. package/crates/tish_core/src/json.rs +102 -53
  38. package/crates/tish_core/src/lib.rs +3 -1
  39. package/crates/tish_core/src/macros.rs +5 -5
  40. package/crates/tish_core/src/value.rs +53 -15
  41. package/crates/tish_core/src/vmref.rs +178 -0
  42. package/crates/tish_eval/Cargo.toml +17 -2
  43. package/crates/tish_eval/src/eval.rs +90 -28
  44. package/crates/tish_eval/src/http.rs +61 -0
  45. package/crates/tish_eval/src/lib.rs +3 -3
  46. package/crates/tish_eval/src/natives.rs +41 -0
  47. package/crates/tish_eval/src/value.rs +7 -3
  48. package/crates/tish_eval/src/value_convert.rs +13 -5
  49. package/crates/tish_fmt/src/lib.rs +120 -30
  50. package/crates/tish_lexer/src/lib.rs +20 -5
  51. package/crates/tish_lexer/src/token.rs +4 -0
  52. package/crates/tish_llvm/src/lib.rs +3 -1
  53. package/crates/tish_lsp/Cargo.toml +4 -1
  54. package/crates/tish_lsp/README.md +1 -1
  55. package/crates/tish_lsp/src/builtin_goto.rs +261 -0
  56. package/crates/tish_lsp/src/import_goto.rs +549 -0
  57. package/crates/tish_lsp/src/main.rs +502 -102
  58. package/crates/tish_native/src/build.rs +3 -2
  59. package/crates/tish_native/src/lib.rs +6 -2
  60. package/crates/tish_opt/src/lib.rs +17 -2
  61. package/crates/tish_parser/src/lib.rs +10 -3
  62. package/crates/tish_parser/src/parser.rs +346 -56
  63. package/crates/tish_pg/Cargo.toml +34 -0
  64. package/crates/tish_pg/README.md +38 -0
  65. package/crates/tish_pg/src/error.rs +52 -0
  66. package/crates/tish_pg/src/lib.rs +967 -0
  67. package/crates/tish_resolve/Cargo.toml +13 -0
  68. package/crates/tish_resolve/src/lib.rs +3436 -0
  69. package/crates/tish_resolve/src/pos.rs +133 -0
  70. package/crates/tish_runtime/Cargo.toml +68 -3
  71. package/crates/tish_runtime/src/http.rs +1123 -141
  72. package/crates/tish_runtime/src/http_fetch.rs +15 -14
  73. package/crates/tish_runtime/src/http_hyper.rs +418 -0
  74. package/crates/tish_runtime/src/http_prefork.rs +189 -0
  75. package/crates/tish_runtime/src/lib.rs +159 -29
  76. package/crates/tish_runtime/src/promise.rs +199 -36
  77. package/crates/tish_runtime/src/promise_io.rs +2 -1
  78. package/crates/tish_runtime/src/timers.rs +37 -1
  79. package/crates/tish_runtime/src/ws.rs +26 -28
  80. package/crates/tish_ui/src/jsx.rs +279 -8
  81. package/crates/tish_ui/src/lib.rs +5 -2
  82. package/crates/tish_ui/src/runtime/hooks.rs +406 -45
  83. package/crates/tish_ui/src/runtime/mod.rs +36 -9
  84. package/crates/tish_vm/Cargo.toml +15 -5
  85. package/crates/tish_vm/src/vm.rs +506 -259
  86. package/crates/tish_vm/tests/peephole_jump_chain_logical_or.rs +3 -1
  87. package/crates/tish_wasm/src/lib.rs +17 -14
  88. package/crates/tish_wasm_runtime/Cargo.toml +2 -1
  89. package/crates/tish_wasm_runtime/src/lib.rs +1 -1
  90. package/crates/tishlang_cargo_bindgen/Cargo.toml +1 -0
  91. package/crates/tishlang_cargo_bindgen/src/discover.rs +68 -0
  92. package/crates/tishlang_cargo_bindgen/src/lib.rs +5 -4
  93. package/justfile +8 -0
  94. package/package.json +1 -1
  95. package/platform/darwin-arm64/tish +0 -0
  96. package/platform/darwin-x64/tish +0 -0
  97. package/platform/linux-arm64/tish +0 -0
  98. package/platform/linux-x64/tish +0 -0
  99. package/platform/win32-x64/tish.exe +0 -0
@@ -0,0 +1,34 @@
1
+ [package]
2
+ name = "tishlang_pg"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ description = "PostgreSQL driver for the Tish native runtime — tokio-postgres + deadpool"
6
+ license-file = { workspace = true }
7
+ repository = { workspace = true }
8
+
9
+ [lib]
10
+ name = "tishlang_pg"
11
+ crate-type = ["rlib"]
12
+
13
+ [features]
14
+ default = ["tish-bindings"]
15
+ # Exposes sync `pub fn(args: &[Value]) -> Value` wrappers for the bytecode VM
16
+ # (`cargo:tish_pg` module URL, registered by the `tishlang` CLI when built with `pg`).
17
+ tish-bindings = ["dep:tishlang_runtime", "dep:once_cell", "dep:slab"]
18
+
19
+ [dependencies]
20
+ tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
21
+ tokio-postgres = { version = "0.7", features = ["with-serde_json-1", "with-uuid-1", "with-chrono-0_4"] }
22
+ futures = "0.3"
23
+ deadpool = "0.12"
24
+ deadpool-postgres = "0.14"
25
+ serde = { version = "1", features = ["derive"] }
26
+ serde_json = "1"
27
+ thiserror = "1"
28
+ url = "2"
29
+ tishlang_runtime = { path = "../tish_runtime", version = ">=0.1", optional = true, features = ["send-values"] }
30
+ once_cell = { version = "1", optional = true }
31
+ slab = { version = "0.4", optional = true }
32
+
33
+ [dev-dependencies]
34
+ tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
@@ -0,0 +1,38 @@
1
+ # tishlang_pg
2
+
3
+ **PostgreSQL for Tish** — a Rust library (`rlib`) that **Tish-compiled programs** use: Tish compiles to native Rust, and this crate is a normal Rust dependency of that output, so **authors still write `.tish`**.
4
+
5
+ ## What this is **not**
6
+
7
+ - **No Node.js** / no N-API in this crate
8
+ - No JavaScript runtime in the driver itself
9
+
10
+ ## What this **is**
11
+
12
+ - **`tokio-postgres`** + **`deadpool-postgres`** for the wire protocol and pooling.
13
+ - A **Rust API** (`PgPool`, `PoolConfig`, `QueryResult`) plus Tish-facing bindings (`cargo:tish_pg`) used when the CLI is built with the **`pg`** feature.
14
+
15
+ ## From `.tish` (npm package)
16
+
17
+ Install the scoped package and import the same surface as the standalone `tish-pg` repo used to ship:
18
+
19
+ ```tish
20
+ import { connect, queryPrepared, prepare, close } from '@tishlang/pg'
21
+ ```
22
+
23
+ Requires **`tish run` / `tish build` with the `pg` feature** (included in the default `full` feature set).
24
+
25
+ ## Building in this workspace
26
+
27
+ From the `tish` repo root:
28
+
29
+ ```bash
30
+ cargo build -p tishlang_pg
31
+ cargo test -p tishlang_pg
32
+ ```
33
+
34
+ See the workspace [`justfile`](../../justfile) for common tasks.
35
+
36
+ ## License
37
+
38
+ Same as the parent workspace (`LICENSE` at repo root).
@@ -0,0 +1,52 @@
1
+ use std::fmt::Write as _;
2
+ use std::error::Error as StdError;
3
+
4
+ use deadpool::managed::PoolError;
5
+ use thiserror::Error;
6
+
7
+ /// `tokio_postgres::Error`’s [`Display`] is often just `"db error"` for server
8
+ /// faults; the real text lives on [`tokio_postgres::Error::as_db_error`].
9
+ pub fn format_pg_error(e: &tokio_postgres::Error) -> String {
10
+ if let Some(db) = e.as_db_error() {
11
+ let mut s = format!("{} [{}]", db.message(), db.code().code());
12
+ if let Some(d) = db.detail() {
13
+ let _ = write!(s, " ({})", d);
14
+ }
15
+ if let Some(h) = db.hint() {
16
+ let _ = write!(s, " hint: {}", h);
17
+ }
18
+ return s;
19
+ }
20
+ let mut out = e.to_string();
21
+ if let Some(src) = e.source() {
22
+ let _ = write!(out, " ({})", src);
23
+ }
24
+ out
25
+ }
26
+
27
+ pub fn format_tish_pg_error(e: &TishPgError) -> String {
28
+ match e {
29
+ TishPgError::Postgres(pg) => format_pg_error(pg),
30
+ TishPgError::Pool(pe) => match pe {
31
+ PoolError::Backend(pg) => format_pg_error(pg),
32
+ _ => pe.to_string(),
33
+ },
34
+ _ => e.to_string(),
35
+ }
36
+ }
37
+
38
+ #[derive(Debug, Error)]
39
+ pub enum TishPgError {
40
+ #[error("invalid connection string: {0}")]
41
+ BadConnectionString(String),
42
+ #[error("invalid query parameter: {0}")]
43
+ BadParam(String),
44
+ #[error("postgres: {0}")]
45
+ Postgres(#[from] tokio_postgres::Error),
46
+ #[error("pool: {0}")]
47
+ Pool(#[from] deadpool::managed::PoolError<tokio_postgres::Error>),
48
+ #[error("build pool: {0}")]
49
+ Build(#[from] deadpool_postgres::BuildError),
50
+ }
51
+
52
+ pub type Result<T> = std::result::Result<T, TishPgError>;