Highly ambitious ATProtocol AppView service and sdks

allow nsid as record key type

Changed files
+125 -49
api
crates
slices-lexicon
src
validation
primary
packages
+1 -1
api/Cargo.lock
··· 2963 2963 2964 2964 [[package]] 2965 2965 name = "slices-lexicon" 2966 - version = "0.2.3" 2966 + version = "0.3.0" 2967 2967 dependencies = [ 2968 2968 "base64 0.21.7", 2969 2969 "chrono",
+1 -1
crates/slices-lexicon/Cargo.lock
··· 347 347 348 348 [[package]] 349 349 name = "slices-lexicon" 350 - version = "0.2.3" 350 + version = "0.3.0" 351 351 dependencies = [ 352 352 "base64", 353 353 "chrono",
+1 -1
crates/slices-lexicon/Cargo.toml
··· 1 1 [package] 2 2 name = "slices-lexicon" 3 - version = "0.2.3" 3 + version = "0.3.0" 4 4 edition = "2021" 5 5 description = "AT Protocol lexicon validation library for Slices" 6 6 license = "MIT"
+30 -2
crates/slices-lexicon/src/validation/primary/record.rs
··· 277 277 /// 278 278 /// - `tid`: Record key is a Timestamp Identifier (auto-generated) 279 279 /// - `any`: Record key can be any valid record key format 280 + /// - `nsid`: Record key must be a valid NSID 280 281 /// - `literal:self`: Record key must be exactly "self" 281 282 /// 282 283 /// # Arguments ··· 291 292 /// - The key is not one of the valid types 292 293 fn validate_key(def_name: &str, key_value: &Value) -> Result<(), ValidationError> { 293 294 match key_value.as_str() { 294 - Some("tid") | Some("any") => Ok(()), 295 + Some("tid") | Some("any") | Some("nsid") => Ok(()), 295 296 Some(k) if k.starts_with("literal:") => Ok(()), 296 297 Some(invalid) => Err(ValidationError::InvalidSchema(format!( 297 - "Record '{}' has invalid key type '{}'. Must be 'tid', 'any', or 'literal:*'", 298 + "Record '{}' has invalid key type '{}'. Must be 'tid', 'any', 'nsid', or 'literal:*'", 298 299 def_name, invalid 299 300 ))), 300 301 None => Err(ValidationError::InvalidSchema(format!( ··· 586 587 let record = json!({ 587 588 "type": "record", 588 589 "key": "tid", 590 + "record": { 591 + "type": "object", 592 + "properties": { 593 + "text": { "type": "string" } 594 + } 595 + } 596 + }); 597 + 598 + let ctx = ValidationContext::builder() 599 + .with_lexicons(vec![json!({ 600 + "lexicon": 1, 601 + "id": "com.example.test", 602 + "defs": { "main": record.clone() } 603 + })]) 604 + .unwrap() 605 + .build() 606 + .unwrap(); 607 + 608 + let validator = RecordValidator; 609 + assert!(validator.validate(&record, &ctx).is_ok()); 610 + } 611 + 612 + #[test] 613 + fn test_valid_record_nsid() { 614 + let record = json!({ 615 + "type": "record", 616 + "key": "nsid", 589 617 "record": { 590 618 "type": "object", 591 619 "properties": {
+1 -1
packages/lexicon-intellisense/package.json
··· 1 1 { 2 2 "name": "lexicon-intellisense", 3 - "version": "0.2.1", 3 + "version": "0.3.0", 4 4 "description": "VS Code IntelliSense support for AT Protocol lexicon JSON files", 5 5 "main": "./out/extension.js", 6 6 "license": "MIT",
+40 -20
packages/lexicon-intellisense/wasm/README.md
··· 1 - # lexicon-rs 1 + # slices-lexicon 2 2 3 3 Rust implementation of AT Protocol lexicon validation. 4 4 5 5 ## Overview 6 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. 7 + This validation engine can be used in any project that needs AT Protocol lexicon 8 + validation. It provides high-performance, spec-compliant validation of AT 9 + Protocol lexicon documents and data records. It can also be compiled to 10 + WebAssembly for use in JavaScript/TypeScript environments. 8 11 9 12 ## Architecture 10 13 11 - This package serves as the core validation engine and is typically consumed by higher-level packages: 14 + This package serves as the core validation engine and is typically consumed by 15 + higher-level packages: 12 16 13 17 - **`@slices/lexicon`** - TypeScript/Deno package with ergonomic APIs 18 + - **`@slices/cli`** - Deno command-line tool for lexicon/appview management 14 19 - **`lexicon-intellisense`** - VS Code extension for lexicon development 15 - - **Slices CLI** - Command-line tooling for lexicon management 16 20 17 21 ## Features 18 22 ··· 31 35 32 36 ```toml 33 37 [dependencies] 34 - slices-lexicon = "0.1" 38 + slices-lexicon = "0.2" 35 39 ``` 36 40 37 41 Basic validation: ··· 91 95 Use in JavaScript environments: 92 96 93 97 ```javascript 94 - import init, { 95 - WasmLexiconValidator, 96 - validate_lexicons_and_get_errors, 97 - is_valid_nsid 98 - } from './pkg/slices_lexicon.js'; 98 + import init, { WasmLexiconValidator } from "./pkg/slices_lexicon.js"; 99 99 100 100 await init(); 101 101 102 102 // Validate lexicons 103 103 const lexicons = [{ 104 - id: "com.example.post", 105 - lexicon: 1, 106 - defs: { /* ... */ } 104 + id: "com.example.post", 105 + lexicon: 1, 106 + defs: { 107 + main: { 108 + type: "record", 109 + key: "tid", 110 + record: { 111 + type: "object", 112 + required: ["text"], 113 + properties: { 114 + text: { type: "string", maxLength: 300 }, 115 + }, 116 + }, 117 + }, 118 + }, 107 119 }]; 108 120 109 - const errors = validate_lexicons_and_get_errors(JSON.stringify(lexicons)); 110 - console.log('Validation errors:', JSON.parse(errors)); 121 + const validator = new WasmLexiconValidator(JSON.stringify(lexicons)); 122 + const errorsJson = validator.validate_lexicons(); 123 + const errors = JSON.parse(errorsJson); 111 124 112 - // Validate NSID format 113 - const isValid = is_valid_nsid("com.example.post"); 125 + if (Object.keys(errors).length > 0) { 126 + console.log("Validation errors:", errors); 127 + } else { 128 + console.log("All lexicons valid"); 129 + } 130 + 131 + validator.free(); // Clean up WASM resources 114 132 ``` 115 133 116 134 ## JavaScript/TypeScript Usage 117 135 118 - If you're using JavaScript or TypeScript, use the higher-level packages instead of consuming this library directly: 136 + If you're using JavaScript or TypeScript, use the higher-level packages instead 137 + of consuming this library directly: 119 138 120 - - **TypeScript/JavaScript**: Use `@slices/lexicon` for ergonomic APIs with automatic resource management 139 + - **TypeScript/JavaScript**: Use `@slices/lexicon` for ergonomic APIs with 140 + automatic resource management 121 141 - **VS Code Development**: Install the `lexicon-intellisense` extension 122 142 - **CLI Tools**: Use the Slices CLI for lexicon management tasks 123 143 ··· 151 171 152 172 ## License 153 173 154 - MIT 174 + MIT
+5 -1
packages/lexicon-intellisense/wasm/package.json
··· 2 2 "name": "slices-lexicon", 3 3 "type": "module", 4 4 "description": "AT Protocol lexicon validation library for Slices", 5 - "version": "0.1.4", 5 + "version": "0.3.0", 6 6 "license": "MIT", 7 + "repository": { 8 + "type": "git", 9 + "url": "https://tangled.org/@slices.network/slices/tree/main/crates/slices-lexicon" 10 + }, 7 11 "files": [ 8 12 "slices_lexicon_bg.wasm", 9 13 "slices_lexicon.js",
packages/lexicon-intellisense/wasm/slices_lexicon_bg.wasm

This is a binary file and will not be displayed.

+1 -1
packages/lexicon/deno.json
··· 1 1 { 2 2 "name": "@slices/lexicon", 3 - "version": "0.1.0", 3 + "version": "0.3.0", 4 4 "description": "AT Protocol lexicon validation", 5 5 "license": "MIT", 6 6 "exports": "./mod.ts",
+40 -20
packages/lexicon/wasm/README.md
··· 1 - # lexicon-rs 1 + # slices-lexicon 2 2 3 3 Rust implementation of AT Protocol lexicon validation. 4 4 5 5 ## Overview 6 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. 7 + This validation engine can be used in any project that needs AT Protocol lexicon 8 + validation. It provides high-performance, spec-compliant validation of AT 9 + Protocol lexicon documents and data records. It can also be compiled to 10 + WebAssembly for use in JavaScript/TypeScript environments. 8 11 9 12 ## Architecture 10 13 11 - This package serves as the core validation engine and is typically consumed by higher-level packages: 14 + This package serves as the core validation engine and is typically consumed by 15 + higher-level packages: 12 16 13 17 - **`@slices/lexicon`** - TypeScript/Deno package with ergonomic APIs 18 + - **`@slices/cli`** - Deno command-line tool for lexicon/appview management 14 19 - **`lexicon-intellisense`** - VS Code extension for lexicon development 15 - - **Slices CLI** - Command-line tooling for lexicon management 16 20 17 21 ## Features 18 22 ··· 31 35 32 36 ```toml 33 37 [dependencies] 34 - slices-lexicon = "0.1" 38 + slices-lexicon = "0.2" 35 39 ``` 36 40 37 41 Basic validation: ··· 91 95 Use in JavaScript environments: 92 96 93 97 ```javascript 94 - import init, { 95 - WasmLexiconValidator, 96 - validate_lexicons_and_get_errors, 97 - is_valid_nsid 98 - } from './pkg/slices_lexicon.js'; 98 + import init, { WasmLexiconValidator } from "./pkg/slices_lexicon.js"; 99 99 100 100 await init(); 101 101 102 102 // Validate lexicons 103 103 const lexicons = [{ 104 - id: "com.example.post", 105 - lexicon: 1, 106 - defs: { /* ... */ } 104 + id: "com.example.post", 105 + lexicon: 1, 106 + defs: { 107 + main: { 108 + type: "record", 109 + key: "tid", 110 + record: { 111 + type: "object", 112 + required: ["text"], 113 + properties: { 114 + text: { type: "string", maxLength: 300 }, 115 + }, 116 + }, 117 + }, 118 + }, 107 119 }]; 108 120 109 - const errors = validate_lexicons_and_get_errors(JSON.stringify(lexicons)); 110 - console.log('Validation errors:', JSON.parse(errors)); 121 + const validator = new WasmLexiconValidator(JSON.stringify(lexicons)); 122 + const errorsJson = validator.validate_lexicons(); 123 + const errors = JSON.parse(errorsJson); 111 124 112 - // Validate NSID format 113 - const isValid = is_valid_nsid("com.example.post"); 125 + if (Object.keys(errors).length > 0) { 126 + console.log("Validation errors:", errors); 127 + } else { 128 + console.log("All lexicons valid"); 129 + } 130 + 131 + validator.free(); // Clean up WASM resources 114 132 ``` 115 133 116 134 ## JavaScript/TypeScript Usage 117 135 118 - If you're using JavaScript or TypeScript, use the higher-level packages instead of consuming this library directly: 136 + If you're using JavaScript or TypeScript, use the higher-level packages instead 137 + of consuming this library directly: 119 138 120 - - **TypeScript/JavaScript**: Use `@slices/lexicon` for ergonomic APIs with automatic resource management 139 + - **TypeScript/JavaScript**: Use `@slices/lexicon` for ergonomic APIs with 140 + automatic resource management 121 141 - **VS Code Development**: Install the `lexicon-intellisense` extension 122 142 - **CLI Tools**: Use the Slices CLI for lexicon management tasks 123 143 ··· 151 171 152 172 ## License 153 173 154 - MIT 174 + MIT
+5 -1
packages/lexicon/wasm/package.json
··· 2 2 "name": "slices-lexicon", 3 3 "type": "module", 4 4 "description": "AT Protocol lexicon validation library for Slices", 5 - "version": "0.1.4", 5 + "version": "0.3.0", 6 6 "license": "MIT", 7 + "repository": { 8 + "type": "git", 9 + "url": "https://tangled.org/@slices.network/slices/tree/main/crates/slices-lexicon" 10 + }, 7 11 "files": [ 8 12 "slices_lexicon_bg.wasm", 9 13 "slices_lexicon.js",
packages/lexicon/wasm/slices_lexicon_bg.wasm

This is a binary file and will not be displayed.