Highly ambitious ATProtocol AppView service and sdks
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

mv intellisense tasks to root

+80 -24
+2
deno.json
··· 15 15 "codegen:cli": "deno task dev:cli codegen --lexicons ./lexicons --slice at://did:plc:bcgltzqazw5tb6k2g3ttenbj/network.slices.slice/3lymhd4jhrd2z --output ./packages/cli/src/generated_client.ts --include-slices", 16 16 "codegen:frontend": "deno task dev:cli codegen --lexicons ./lexicons --slice at://did:plc:bcgltzqazw5tb6k2g3ttenbj/network.slices.slice/3lymhd4jhrd2z --output ./frontend/src/client.ts --include-slices", 17 17 "dev:frontend": "cd frontend && deno task dev", 18 + "build:lexicon-intellisense-wasm": "cd ./packages/lexicon-rs && wasm-pack build --target web --features wasm && cp pkg/* ../lexicon-intellisense/wasm/", 19 + "build:lexicon-intellisense-lexicon": "deno bundle ./packages/lexicon/mod.ts -o ./packages/lexicon-intellisense/src/slices_lexicon.js", 18 20 "test": "deno test --allow-all packages/*/tests/ packages/*/src/ frontend/src/", 19 21 "check": "deno check packages/*/src/ packages/*/mod.ts packages/*/src/mod.ts frontend/src/**/*.ts frontend/src/**/*.tsx", 20 22 "fmt": "deno fmt packages/ frontend/",
+2 -2
packages/lexicon-intellisense/src/slices_lexicon.js
··· 1 - // ../lexicon/wasm/slices_lexicon.js 1 + // packages/lexicon/wasm/slices_lexicon.js 2 2 var wasm; 3 3 var cachedUint8ArrayMemory0 = null; 4 4 function getUint8ArrayMemory0() { ··· 341 341 } 342 342 var slices_lexicon_default = __wbg_init; 343 343 344 - // ../lexicon/lexicon.ts 344 + // packages/lexicon/lexicon.ts 345 345 var _computedKey; 346 346 var _computedKey1; 347 347 var wasmInitialized = false;
+76 -22
packages/lexicon-intellisense/wasm/README.md
··· 1 - # slices-lexicon 1 + # lexicon-rs 2 + 3 + Rust implementation of AT Protocol lexicon validation. 4 + 5 + ## Overview 6 + 7 + This validation engine can be used in any project that needs AT Protocol lexicon validation. It provides high-performance, spec-compliant validation of AT Protocol lexicon documents and data records. It can also be compiled to WebAssembly for use in JavaScript/TypeScript environments. 8 + 9 + ## Architecture 2 10 3 - AT Protocol lexicon validation library for Rust, compiled to WebAssembly. 11 + This package serves as the core validation engine and is typically consumed by higher-level packages: 12 + 13 + - **`@slices/lexicon`** - TypeScript/Deno package with ergonomic APIs 14 + - **`lexicon-intellisense`** - VS Code extension for lexicon development 15 + - **Slices CLI** - Command-line tooling for lexicon management 4 16 5 17 ## Features 6 18 7 - - 🚀 Fast lexicon validation written in Rust 8 - - 🌐 WebAssembly support for browser and Node.js environments 9 - - 📦 Zero JavaScript dependencies 10 - - 🔒 Type-safe validation with comprehensive error messages 11 - - ✅ Full AT Protocol lexicon specification support 19 + - High-performance lexicon validation implemented in Rust 20 + - Comprehensive error reporting with detailed context 21 + - Full AT Protocol lexicon specification compliance 22 + - Support for all lexicon types: records, queries, procedures, subscriptions 23 + - Optional WebAssembly compilation for JavaScript/TypeScript environments 24 + - Zero JavaScript runtime dependencies when using WebAssembly 25 + 26 + ## Direct Usage 27 + 28 + ### Rust Library 12 29 13 - ## Installation 30 + Add to your `Cargo.toml`: 14 31 15 32 ```toml 16 33 [dependencies] 17 34 slices-lexicon = "0.1" 18 35 ``` 19 36 20 - ## Usage 21 - 22 - ### In Rust 37 + Basic validation: 23 38 24 39 ```rust 25 - use slices_lexicon::{LexiconValidator, ValidationError}; 40 + use slices_lexicon::{validate, validate_record, is_valid_nsid}; 26 41 use serde_json::json; 27 42 43 + // Define lexicon documents 28 44 let lexicons = vec![ 29 45 json!({ 30 46 "id": "com.example.post", 47 + "lexicon": 1, 31 48 "defs": { 32 49 "main": { 33 50 "type": "record", 51 + "key": "tid", 34 52 "record": { 35 53 "type": "object", 54 + "required": ["text"], 36 55 "properties": { 37 - "text": { "type": "string" } 56 + "text": { "type": "string", "maxLength": 300 } 38 57 } 39 58 } 40 59 } ··· 42 61 }) 43 62 ]; 44 63 45 - let validator = LexiconValidator::new(lexicons)?; 64 + // Validate lexicon documents 65 + match validate(lexicons.clone()) { 66 + Ok(()) => println!("All lexicons are valid"), 67 + Err(errors) => { 68 + for (lexicon_id, error_list) in errors { 69 + println!("Errors in {}: {:?}", lexicon_id, error_list); 70 + } 71 + } 72 + } 73 + 74 + // Validate a data record against the schema 46 75 let record = json!({ "text": "Hello, world!" }); 76 + validate_record(lexicons, "com.example.post", record)?; 47 77 48 - validator.validate_record("com.example.post", &record)?; 78 + // Validate NSID format 79 + let is_valid = is_valid_nsid("com.example.post"); 80 + println!("NSID valid: {}", is_valid); 49 81 ``` 50 82 51 - ### As WebAssembly 83 + ### WebAssembly 52 84 53 - Build with wasm-pack: 85 + Build the WASM module: 54 86 55 87 ```bash 56 - wasm-pack build --target web 88 + wasm-pack build --target web --features wasm 57 89 ``` 58 90 59 - Then use in JavaScript/TypeScript: 91 + Use in JavaScript environments: 60 92 61 93 ```javascript 62 - import init, { WasmLexiconValidator } from './pkg/slices_lexicon.js'; 94 + import init, { 95 + WasmLexiconValidator, 96 + validate_lexicons_and_get_errors, 97 + is_valid_nsid 98 + } from './pkg/slices_lexicon.js'; 63 99 64 100 await init(); 65 101 66 - const validator = new WasmLexiconValidator(JSON.stringify(lexicons)); 67 - validator.validate_record("com.example.post", JSON.stringify(record)); 102 + // Validate lexicons 103 + const lexicons = [{ 104 + id: "com.example.post", 105 + lexicon: 1, 106 + defs: { /* ... */ } 107 + }]; 108 + 109 + const errors = validate_lexicons_and_get_errors(JSON.stringify(lexicons)); 110 + console.log('Validation errors:', JSON.parse(errors)); 111 + 112 + // Validate NSID format 113 + const isValid = is_valid_nsid("com.example.post"); 68 114 ``` 115 + 116 + ## JavaScript/TypeScript Usage 117 + 118 + If you're using JavaScript or TypeScript, use the higher-level packages instead of consuming this library directly: 119 + 120 + - **TypeScript/JavaScript**: Use `@slices/lexicon` for ergonomic APIs with automatic resource management 121 + - **VS Code Development**: Install the `lexicon-intellisense` extension 122 + - **CLI Tools**: Use the Slices CLI for lexicon management tasks 69 123 70 124 ## Supported Types 71 125