···277277 ///
278278 /// - `tid`: Record key is a Timestamp Identifier (auto-generated)
279279 /// - `any`: Record key can be any valid record key format
280280+ /// - `nsid`: Record key must be a valid NSID
280281 /// - `literal:self`: Record key must be exactly "self"
281282 ///
282283 /// # Arguments
···291292 /// - The key is not one of the valid types
292293 fn validate_key(def_name: &str, key_value: &Value) -> Result<(), ValidationError> {
293294 match key_value.as_str() {
294294- Some("tid") | Some("any") => Ok(()),
295295+ Some("tid") | Some("any") | Some("nsid") => Ok(()),
295296 Some(k) if k.starts_with("literal:") => Ok(()),
296297 Some(invalid) => Err(ValidationError::InvalidSchema(format!(
297297- "Record '{}' has invalid key type '{}'. Must be 'tid', 'any', or 'literal:*'",
298298+ "Record '{}' has invalid key type '{}'. Must be 'tid', 'any', 'nsid', or 'literal:*'",
298299 def_name, invalid
299300 ))),
300301 None => Err(ValidationError::InvalidSchema(format!(
···586587 let record = json!({
587588 "type": "record",
588589 "key": "tid",
590590+ "record": {
591591+ "type": "object",
592592+ "properties": {
593593+ "text": { "type": "string" }
594594+ }
595595+ }
596596+ });
597597+598598+ let ctx = ValidationContext::builder()
599599+ .with_lexicons(vec![json!({
600600+ "lexicon": 1,
601601+ "id": "com.example.test",
602602+ "defs": { "main": record.clone() }
603603+ })])
604604+ .unwrap()
605605+ .build()
606606+ .unwrap();
607607+608608+ let validator = RecordValidator;
609609+ assert!(validator.validate(&record, &ctx).is_ok());
610610+ }
611611+612612+ #[test]
613613+ fn test_valid_record_nsid() {
614614+ let record = json!({
615615+ "type": "record",
616616+ "key": "nsid",
589617 "record": {
590618 "type": "object",
591619 "properties": {
+1-1
packages/lexicon-intellisense/package.json
···11{
22 "name": "lexicon-intellisense",
33- "version": "0.2.1",
33+ "version": "0.3.0",
44 "description": "VS Code IntelliSense support for AT Protocol lexicon JSON files",
55 "main": "./out/extension.js",
66 "license": "MIT",
+40-20
packages/lexicon-intellisense/wasm/README.md
···11-# lexicon-rs
11+# slices-lexicon
2233Rust implementation of AT Protocol lexicon validation.
4455## Overview
6677-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.
77+This validation engine can be used in any project that needs AT Protocol lexicon
88+validation. It provides high-performance, spec-compliant validation of AT
99+Protocol lexicon documents and data records. It can also be compiled to
1010+WebAssembly for use in JavaScript/TypeScript environments.
811912## Architecture
10131111-This package serves as the core validation engine and is typically consumed by higher-level packages:
1414+This package serves as the core validation engine and is typically consumed by
1515+higher-level packages:
12161317- **`@slices/lexicon`** - TypeScript/Deno package with ergonomic APIs
1818+- **`@slices/cli`** - Deno command-line tool for lexicon/appview management
1419- **`lexicon-intellisense`** - VS Code extension for lexicon development
1515-- **Slices CLI** - Command-line tooling for lexicon management
16201721## Features
1822···31353236```toml
3337[dependencies]
3434-slices-lexicon = "0.1"
3838+slices-lexicon = "0.2"
3539```
36403741Basic validation:
···9195Use in JavaScript environments:
92969397```javascript
9494-import init, {
9595- WasmLexiconValidator,
9696- validate_lexicons_and_get_errors,
9797- is_valid_nsid
9898-} from './pkg/slices_lexicon.js';
9898+import init, { WasmLexiconValidator } from "./pkg/slices_lexicon.js";
9999100100await init();
101101102102// Validate lexicons
103103const lexicons = [{
104104- id: "com.example.post",
105105- lexicon: 1,
106106- defs: { /* ... */ }
104104+ id: "com.example.post",
105105+ lexicon: 1,
106106+ defs: {
107107+ main: {
108108+ type: "record",
109109+ key: "tid",
110110+ record: {
111111+ type: "object",
112112+ required: ["text"],
113113+ properties: {
114114+ text: { type: "string", maxLength: 300 },
115115+ },
116116+ },
117117+ },
118118+ },
107119}];
108120109109-const errors = validate_lexicons_and_get_errors(JSON.stringify(lexicons));
110110-console.log('Validation errors:', JSON.parse(errors));
121121+const validator = new WasmLexiconValidator(JSON.stringify(lexicons));
122122+const errorsJson = validator.validate_lexicons();
123123+const errors = JSON.parse(errorsJson);
111124112112-// Validate NSID format
113113-const isValid = is_valid_nsid("com.example.post");
125125+if (Object.keys(errors).length > 0) {
126126+ console.log("Validation errors:", errors);
127127+} else {
128128+ console.log("All lexicons valid");
129129+}
130130+131131+validator.free(); // Clean up WASM resources
114132```
115133116134## JavaScript/TypeScript Usage
117135118118-If you're using JavaScript or TypeScript, use the higher-level packages instead of consuming this library directly:
136136+If you're using JavaScript or TypeScript, use the higher-level packages instead
137137+of consuming this library directly:
119138120120-- **TypeScript/JavaScript**: Use `@slices/lexicon` for ergonomic APIs with automatic resource management
139139+- **TypeScript/JavaScript**: Use `@slices/lexicon` for ergonomic APIs with
140140+ automatic resource management
121141- **VS Code Development**: Install the `lexicon-intellisense` extension
122142- **CLI Tools**: Use the Slices CLI for lexicon management tasks
123143···151171152172## License
153173154154-MIT174174+MIT
···11-# lexicon-rs
11+# slices-lexicon
2233Rust implementation of AT Protocol lexicon validation.
4455## Overview
6677-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.
77+This validation engine can be used in any project that needs AT Protocol lexicon
88+validation. It provides high-performance, spec-compliant validation of AT
99+Protocol lexicon documents and data records. It can also be compiled to
1010+WebAssembly for use in JavaScript/TypeScript environments.
811912## Architecture
10131111-This package serves as the core validation engine and is typically consumed by higher-level packages:
1414+This package serves as the core validation engine and is typically consumed by
1515+higher-level packages:
12161317- **`@slices/lexicon`** - TypeScript/Deno package with ergonomic APIs
1818+- **`@slices/cli`** - Deno command-line tool for lexicon/appview management
1419- **`lexicon-intellisense`** - VS Code extension for lexicon development
1515-- **Slices CLI** - Command-line tooling for lexicon management
16201721## Features
1822···31353236```toml
3337[dependencies]
3434-slices-lexicon = "0.1"
3838+slices-lexicon = "0.2"
3539```
36403741Basic validation:
···9195Use in JavaScript environments:
92969397```javascript
9494-import init, {
9595- WasmLexiconValidator,
9696- validate_lexicons_and_get_errors,
9797- is_valid_nsid
9898-} from './pkg/slices_lexicon.js';
9898+import init, { WasmLexiconValidator } from "./pkg/slices_lexicon.js";
9999100100await init();
101101102102// Validate lexicons
103103const lexicons = [{
104104- id: "com.example.post",
105105- lexicon: 1,
106106- defs: { /* ... */ }
104104+ id: "com.example.post",
105105+ lexicon: 1,
106106+ defs: {
107107+ main: {
108108+ type: "record",
109109+ key: "tid",
110110+ record: {
111111+ type: "object",
112112+ required: ["text"],
113113+ properties: {
114114+ text: { type: "string", maxLength: 300 },
115115+ },
116116+ },
117117+ },
118118+ },
107119}];
108120109109-const errors = validate_lexicons_and_get_errors(JSON.stringify(lexicons));
110110-console.log('Validation errors:', JSON.parse(errors));
121121+const validator = new WasmLexiconValidator(JSON.stringify(lexicons));
122122+const errorsJson = validator.validate_lexicons();
123123+const errors = JSON.parse(errorsJson);
111124112112-// Validate NSID format
113113-const isValid = is_valid_nsid("com.example.post");
125125+if (Object.keys(errors).length > 0) {
126126+ console.log("Validation errors:", errors);
127127+} else {
128128+ console.log("All lexicons valid");
129129+}
130130+131131+validator.free(); // Clean up WASM resources
114132```
115133116134## JavaScript/TypeScript Usage
117135118118-If you're using JavaScript or TypeScript, use the higher-level packages instead of consuming this library directly:
136136+If you're using JavaScript or TypeScript, use the higher-level packages instead
137137+of consuming this library directly:
119138120120-- **TypeScript/JavaScript**: Use `@slices/lexicon` for ergonomic APIs with automatic resource management
139139+- **TypeScript/JavaScript**: Use `@slices/lexicon` for ergonomic APIs with
140140+ automatic resource management
121141- **VS Code Development**: Install the `lexicon-intellisense` extension
122142- **CLI Tools**: Use the Slices CLI for lexicon management tasks
123143···151171152172## License
153173154154-MIT174174+MIT