* Create new crate `fs-utils`; move `Lockfile` and `create_parent_dir`
The snapshot crate will need to create lockfiles.
Rather than duplicating code to do so, we choose to move our definition of `Lockfile`
into a crate that can be depended on by both `cli` and `snapshot`.
No existing crate seems like an obvious choice for this
-- a `Lockfile` is not really a data structure, so `data-structures` seems wrong --
so we add a new crate, `fs-utils`.
Currently this contains only `Lockfile` and `create_parent_dir`,
but a follow-up PR will add `DirTrie`, a Git-like on-disk object store.
* Deduplicate `map_err` closure
* Zeke's nit: simplify control flow
Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
Signed-off-by: Phoebe Goldman <phoebe@goldman-tribe.org>
---------
Signed-off-by: Phoebe Goldman <phoebe@goldman-tribe.org>
Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
* make user tables private by default and define privacy via attribute
* switch to spacetimedb(table(public)) syntax
* accept codegen snap changes
* sdk: use public in define_tables!
* bindings-macro: adjust some doc comments
* sdk-test-connect-disconnect: make Connected/Disconnected public tables
* Make Public Private again
* Fix FilterBy regression in C#
Fixes regression accidentally introduced in #1277: if FindBy returns null, FilterBy will return an iterable with a single null item instead of an empty iterable.
* Fix snapshots
- Limit types to those defined in the consistent filtering proposal (#1256).
- Make `filterBy` a lazy iterable for consistency and performance reasons.
- Add `findBy` for unique fields as per proposal.
* Update C# codegen to consistent filtering rules
- Limit types as per proposal.
- Add `Query` client-side SDK helper for API parity with server-side modules (on client-side it's a simple wrapper around Iter + Where).
- Change return type of `FilterBy` to always be iterable, with new `FindBy` function for unique fields.
- Simplify the way primary keys are handled - must go with https://github.com/clockworklabs/spacetimedb-csharp-sdk/pull/93 for the client SDK counterpart.
* Add using for System.Linq
* Update snapshot
* Extend codegen tests to Rust
* Replace cursive-chat module_bindings with symlink
* Implement consistent filtering rules for Rust
* Fixup
* Regenerate tests
* Fix non-deterministic import order
* cargo fmt
* Fix chat examples
* Change symlinks to files themselves
* Revert accidental change
This needs to wait for server-side API break to be implemented as well.
* Prevent importing an identity with a name that already exists in the
config
* Make identity naming more consistent
* Fix clippy lints
* Several bug fixes and UX improvements
* Prevent someone from adding the same identity twice
* Fix lint
* [jdetter/make-identity-naming-more-consistent]: review
* [jdetter/make-identity-naming-more-consistent]: review
* [jdetter/make-identity-naming-more-consistent]: review
* Reverted file
---------
Co-authored-by: John Detter <no-reply@boppygames.gg>
Co-authored-by: Zeke Foppa <github.com/bfops>
* Create a lockfile when opening config files
In the past, we've had issues where multiple concurrent CLI processes
would race to read and write the CLI config file,
leading to data loss.
We considered using `flock`/`LockFileEx` and blocking until the file became available,
but unfortunately it's not possible to atomically create and lock a nonexistent file,
which we need to do in the case where the configuration doesn't yet exist.
Instead, we opt for a classic lockfile-based scheme:
Before opening a config file `foo.conf`, attempt to exclusively create `foo.lock`,
and panic if the exclusive creation fails.
Once it becomes clear that we will not write the config any more,
i.e. in `Config::drop`,
delete the lockfile, allowing another process to operate.
This means that attempting to run multiple concurrent Spacetime CLI processes
with the same config file is now a hard error.
* Fix CI failures
This commit fixes two CI failures:
- `spacetime start`, and a few other CLI subcommands, do not access their `Config` at all,
but the CLI constructs it unconditionally in `main`,
which made it an error to run any CLI command while `spacetime start` was running.
This is fixed by having subcommands which don't need a `Config`
drop it before doing anything.
- Contrary to my assumption,
the test configuration created by `Config::new_with_localhost` does get `drop`ped,
because the test harness `clone`s is and passes an owned version to the CLI.
This was causing it to attempt to delete the empty path, which failed.
This is fixed by having the home configuration be `Option`al,
and setting it to `None` in tests.
* Clap before config because they suppress destructors
Perform Clap argument parsing as the very first thing in a CLI process,
before locking the config,
because Clap calls `exit` directly on error rather than panicing
(presumably to have more control over error output),
which prevents destructors from running,
leaving stale lockfiles.
* Encapsulate lockfile logic in a type
Also deduplicate logic for finding config file paths.
* Define `create_parent_dir` helper with comments
* Replace `drop` calls with more explicit `Config::release_lock`.
* Remove C# GetArgsAsObjectArray
This is a weird "duck-typed" API that has one usage in BitCraft, but it's easy to replace with either real reflection or strong-typed interfaces.
* Update csharp.rs
Signed-off-by: Ingvar Stepanyan <me@rreverser.com>
---------
Signed-off-by: Ingvar Stepanyan <me@rreverser.com>
CLI `generate` code is a particularly heavy user of format-based macros, and so it benefits most from inlining format args where possible.
This is done by adding `#![warn(clippy::uninlined_format_args)]` + running `cargo clippy --fix` followed by `cargo fmt`, so shouldn't require manual review.
This is a follow-up to #1142 and, like that PR, is mainly done to make generate's code a bit cleaner and diffs simpler.
While working on the new C# codegen, I accidentally noticed that those tests were passing even when they clearly should've been failing due to changed output.
After running with `--nocapture`, I found out it's because the tests are silently skipped and reported as successful when `rust_wasm_test.wasm` isn't built.
This further led to finding that `rust_wasm_test.wasm` is never built - the relevant module results in `rust_wasm_test_module.wasm` instead - so these tests have been incorrectly passing for ages.
This PR changes them to actually build the module as part of testing and updates the snapshots to latest master.
This adds a non-fallible `write_fmt` method to `CodeIndenter<String>` (since we know it should never fail), which allows to use `write!` and `writeln!` without `.unwrap()` everywhere, making code a lot less noisy.
When a server key rotation is suspected, suggest to make the new
identity the default.
This usually happens during development using an ephemeral instance. If
one follows the instructions, the `default_identity` is not set for the
existing server, which makes the CLI generate a fresh identity every
time.
See also: #333