moquilang

Crates.iomoquilang
lib.rsmoquilang
version0.1.1
created_at2025-10-05 07:46:29.48742+00
updated_at2025-10-05 07:53:37.968529+00
descriptionA WebAssembly module for entity operations and service calls with a database (default to a SQLite integration)
homepagehttps://crates.io/crates/moquilang
repositoryhttps://github.com/moquilabs
max_upload_size
id1868742
size1,320,019
(moquilabs)

documentation

README

Moquilang WebAssembly Module

Crates.io Documentation License: MIT

This is a WebAssembly module built with Rust that provides entity operations and service calls for JavaScript applications. It includes a complete user management service and SQLite database integration.

Features

  • User Management: Complete CRUD operations for user entities
  • Entity Operations: Generic entity creation, retrieval, update, and deletion
  • Service Framework: Extensible service call infrastructure
  • SQLite Integration: Browser-based SQLite database support
  • WebAssembly Performance: Native-like performance in the browser

Directory structure

  • pkg/ - Contains WebAssembly build artifacts and generated JavaScript bindings

  • static/ - Contains SQLite library and other JavaScript dependencies

  • index.html - Example HTML file demonstrating usage of the WebAssembly module

Usage

To use the WebAssembly module in your HTML file:

<!-- Include the SQLite library -->
<script src="./static/sqlite3.js"></script>

<!-- Import the WebAssembly module -->
<script type="module">
    import init, { callService, createEntity, updateEntity, deleteEntity, findOne, findMany, exportDatabaseSchema } from './pkg/moquilang.js';
    
    // Your code here
</script>

Available Functions

callService(name: string, parameters: object) -> Promise

Calls a service with the given name and parameters. The parameters can be any JSON-serializable object. This function uses the JSON-based approach for serialization/deserialization between JavaScript and Rust, which can be more efficient in many cases.

import { callService } from "./pkg/moquilang.js";

// Example usage
const result = await callService("userService", {
  userId: 123,
  action: "getProfile",
  options: {
    includeDetails: true,
    format: "full"
  }
});

// The result will contain:
// {
//   service: "userService",
//   status: "success",
//   parameters: "{userId: 123, action: \"getProfile\", options: {...}}"
// }

Note: This implementation uses the JSON-based approach with gloo-utils rather than direct JavaScript value manipulation with serde-wasm-bindgen. This approach:

  • Is often faster for simple data structures
  • Has better compatibility with browser JSON implementations
  • Supports all JSON-serializable types
  • May have a slightly larger code size

Entity Operations

The module provides the following entity operation functions:

createEntity(entityName: string, entityData: object) -> Promise

Creates a new entity with the given name and data.

import { createEntity } from "./pkg/moquilang.js";

// Example usage
const result = await createEntity("UserAccount", {
  username: "johndoe",
  userFullName: "John Doe",
  emailAddress: "john@example.com",
  currentPassword: "password123",
  disabled: "N"
});

updateEntity(entityName: string, entityData: object) -> Promise

Updates an existing entity. The entity ID must be included in the entityData.

import { updateEntity } from "./pkg/moquilang.js";

// Example usage
const result = await updateEntity("UserAccount", {
  userId: "your-user-id-here",
  userFullName: "John Smith",
  emailAddress: "johnsmith@example.com"
});

deleteEntity(entityName: string, entityData: object) -> Promise

Deletes an entity. The entity ID must be included in the entityData.

import { deleteEntity } from "./pkg/moquilang.js";

// Example usage
const result = await deleteEntity("UserAccount", {
  userId: "your-user-id-here"
});

findOne(entityName: string, query: object) -> Promise

Finds one entity matching the query.

import { findOne } from "./pkg/moquilang.js";

// Example usage
const result = await findOne("UserAccount", {
  userId: "your-user-id-here"
});

findMany(entityName: string, query: object) -> Promise<object[]>

Finds multiple entities matching the query.

import { findMany } from "./pkg/moquilang.js";

// Example usage
const results = await findMany("UserAccount", {
  "_limit": 10,
  "_offset": 0,
  "_orderBy": "username",
  "_orderDir": "ASC"
});

Building the Project

  1. Build the WebAssembly module from source:
# Build the Rust WebAssembly module
cargo build --target wasm32-unknown-unknown

The project includes a build.rs script that automatically runs wasm-bindgen after successful compilation when targeting wasm32-unknown-unknown. The generated files will be placed in the pkg/ directory.

For a release build:

cargo build --release --target wasm32-unknown-unknown
  1. Start a local development server with:
python -m http.server
  1. Go to http://localhost:8000 in your browser

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Commit count: 0

cargo fmt