### Build and Run PowerSync Loadable Extension Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/README.md These shell commands demonstrate building the PowerSync loadable extension using Rust and testing it with SQLite. The first command builds the extension, and the second loads it into an in-memory SQLite database to check the version. ```sh cargo build -p powersync_loadable sqlite3 ":memory:" ".load ./target/debug/libpowersync" "select powersync_rs_version()" #This requires sqlite3 installed ``` ```sh cargo build -p powersync_loadable --release ``` -------------------------------- ### PowerSync Sync Instructions Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/docs/sync.md Defines the possible instructions that can be returned by the `powersync_control` function, including logging, status updates, and stream management. ```typescript type Instruction = { LogLine: LogLine } | { UpdateSyncStatus: UpdateSyncStatus } | { EstablishSyncStream: EstablishSyncStream } | { FetchCredentials: FetchCredentials } // Close a connection previously started after EstablishSyncStream | { CloseSyncStream: { hide_disconnect: boolean } } // For the Dart web client, flush the (otherwise non-durable) file system. | { FlushFileSystem: {} } // Notify clients that a checkpoint was completed. Clients can clear the // download error state in response to this. | { DidCompleteSync: {} } interface LogLine { severity: 'DEBUG' | 'INFO' | 'WARNING', line: String, } // Instructs client SDKs to open a connection to the sync service. interface EstablishSyncStream { request: any // The JSON-encoded StreamingSyncRequest to send to the sync service } // Instructs SDKS to update the downloading state of their SyncStatus. interface UpdateSyncStatus { connected: boolean, connecting: boolean, priority_status: [], downloading: null | DownloadProgress, } // Instructs SDKs to refresh credentials from the backend connector. // They don't necessary have to close the connection, a CloseSyncStream instruction // will be sent when the token has already expired. interface FetchCredentials { // Set as an option in case fetching and prefetching should be handled differently. did_expire: boolean } interface SyncPriorityStatus { priority: int, last_synced_at: null | int, has_synced: null | boolean, } interface DownloadProgress { buckets: Record } interface BucketProgress { priority: int, at_last: int, since_last: int, target_count: int } ``` -------------------------------- ### Tagging Git Release Version (Shell) Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/RELEASING.md Creates an annotated Git tag for the specified version and pushes the tags to the remote repository. This is part of the release preparation steps. ```sh git tag -am v1.2.3 v1.2.3 git push --tags ``` -------------------------------- ### Running GitHub Release Workflow (Shell) Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/RELEASING.md Triggers the 'release' GitHub Actions workflow for a specific Git reference (tag) and passes a flag to indicate that artifacts should be published. This initiates the build and publishing process. ```sh gh workflow run release --ref v1.2.3 -f publish=true ``` -------------------------------- ### Build and Run PowerSync SQLite Shell Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/README.md These shell commands are used to build the PowerSync SQLite core using Rust and then run it against a test database. The first command updates git submodules, and the second builds the shell and executes a version check. ```sh git submodule update --init --recursive ``` ```sh cargo build -p powersync_sqlite ./target/debug/powersync_sqlite test.db "select powersync_rs_version()" ``` -------------------------------- ### Create and Push Git Tag for Release Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/docs/RELEASING.md This snippet demonstrates how to create an annotated Git tag with a specific version number and then push it to the remote repository. Pushing the tag triggers the release workflow. ```sh git tag -am v1.2.3 v1.2.3 git push --tags ``` -------------------------------- ### Run Dart Tests (Shell) Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/dart/README.md This command executes the Dart tests located in the current directory. It should be run after the necessary Rust library has been built. ```Shell dart test ``` -------------------------------- ### Build Rust Library for Dart Tests (Shell) Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/dart/README.md This command builds the 'powersync_loadable' package of the Rust library in debug mode, making it available for the Dart tests to load and use. ```Shell cargo build -p powersync_loadable ``` -------------------------------- ### Publishing Cocoapod (Shell) Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/RELEASING.md Publishes the powersync-sqlite-core Cocoapod specification to the trunk repository, making the new version available for iOS/macOS projects via CocoaPods. ```sh pod trunk push powersync-sqlite-core.podspec ``` -------------------------------- ### Publish Cocoapod to Trunk Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/docs/RELEASING.md This command is used to manually publish the Powersync SQLite Core Cocoapod to the Cocoapod trunk. Ensure you have the necessary permissions and have updated the podspec file. ```sh pod trunk push powersync-sqlite-core.podspec ``` -------------------------------- ### Load PowerSync Extension Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/README.md This SQL command loads the PowerSync extension into the SQLite environment. It sets up necessary functions and views without modifying the database content. ```sql .load powersync ``` -------------------------------- ### Initialize PowerSync Extension Data Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/README.md This SQL command initializes the internal data structures for the PowerSync extension. It creates necessary internal tables. This function is optional as it's also called during `powersync_replace_schema`, but can be used independently to ensure internal tables are configured. ```sql SELECT powersync_init(); ``` -------------------------------- ### Build PowerSync for iOS Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/README.md This shell command builds the PowerSync extension specifically for iOS. It utilizes a provided script to generate the necessary xcframework for iOS integration. ```sh ./tool/build_xcframework.sh ``` -------------------------------- ### Configure PowerSync Schema Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/README.md This SQL command configures the PowerSync schema by replacing it with the provided JSON definition. It creates data tables, indexes, and views based on the schema. The JSON specifies table names and their columns with types. ```sql SELECT powersync_replace_schema('{"tables": [{"name": "test", "columns": [{"name": "name", "type": "text"}]}]}'); ``` -------------------------------- ### Building PowerSync SQLite XCFramework for iOS Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/README.md Executes a shell script to build the PowerSync SQLite extension as an XCFramework, which is a format suitable for integrating into iOS and other Apple platform projects. ```sh ./tool/build_xcframework.sh ``` -------------------------------- ### SQLite Randomness Seeding (C/SQLite) Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/UUID.md SQLite's sqlite3_randomness function relies on the VFS xRandomness function for seeding. The implementation details vary by platform, with Unix systems typically using /dev/urandom, Windows using system state, and WASI/Emscripten leveraging crypto.getRandomValues(). ```c /* SQLite's sqlite3_randomness function: * 1. Seeds using the VFS xRandomness function. * 2. Generates a sequence using ChaCha20 (CSPRNG). */ // Example of how xRandomness might be implemented for Unix-like systems: // int xRandomness(sqlite3 *NotUsed, int nByte, void *pBuf) { // int fd = open("/dev/urandom", O_RDONLY); // if (fd < 0) return SQLITE_ERROR; // ssize_t bytesRead = read(fd, pBuf, nByte); // close(fd); // return (bytesRead == nByte) ? SQLITE_OK : SQLITE_ERROR; // } ``` -------------------------------- ### Emscripten/WASI Randomness (JavaScript) Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/UUID.md In Emscripten environments, which are often used for WASI, random number generation is handled by intercepting /dev/urandom calls and using the browser's crypto.getRandomValues() API for secure seeding. ```javascript // Emscripten intercepts /dev/urandom calls and provides values using crypto.getRandomValues() // Example snippet from Emscripten library.js: // // if (typeof crypto !== 'undefined' && crypto.getRandomValues) { // crypto.getRandomValues(array); // } else { // // Fallback or error handling // } ``` -------------------------------- ### UUID Generation with getrandom Crate (Rust) Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/UUID.md The Rust uuid crate utilizes the 'getrandom' crate by default for its 'v4' feature, ensuring cryptographically secure UUID generation. This crate provides a unified interface to various platform-specific random number sources. ```rust use uuid::Uuid; fn main() { // Generate a UUIDv4 using the getrandom crate let uuid = Uuid::new_v4(); println!("Generated UUID: {}", uuid); } ``` -------------------------------- ### Dart SQLite WASM Randomness (Dart) Source: https://github.com/powersync-ja/powersync-sqlite-core/blob/main/UUID.md For Dart's SQLite WASM builds, secure random values are provided using Dart's Random.secure() method. While this might be slower for seeding, it ensures cryptographic security. ```dart import 'dart:math'; // Dart sqlite3 WASM uses Random.secure() for seeding. // This translates to crypto.getRandomValues() in JS. void generateSecureRandomBytes(List buffer) { final random = Random.secure(); for (int i = 0; i < buffer.length; i++) { buffer[i] = random.nextInt(256); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.