···277 ///
278 /// - `tid`: Record key is a Timestamp Identifier (auto-generated)
279 /// - `any`: Record key can be any valid record key format
0280 /// - `literal:self`: Record key must be exactly "self"
281 ///
282 /// # Arguments
···291 /// - The key is not one of the valid types
292 fn validate_key(def_name: &str, key_value: &Value) -> Result<(), ValidationError> {
293 match key_value.as_str() {
294- Some("tid") | Some("any") => Ok(()),
295 Some(k) if k.starts_with("literal:") => Ok(()),
296 Some(invalid) => Err(ValidationError::InvalidSchema(format!(
297- "Record '{}' has invalid key type '{}'. Must be 'tid', 'any', or 'literal:*'",
298 def_name, invalid
299 ))),
300 None => Err(ValidationError::InvalidSchema(format!(
···586 let record = json!({
587 "type": "record",
588 "key": "tid",
000000000000000000000000000589 "record": {
590 "type": "object",
591 "properties": {
···277 ///
278 /// - `tid`: Record key is a Timestamp Identifier (auto-generated)
279 /// - `any`: Record key can be any valid record key format
280+ /// - `nsid`: Record key must be a valid NSID
281 /// - `literal:self`: Record key must be exactly "self"
282 ///
283 /// # Arguments
···292 /// - The key is not one of the valid types
293 fn validate_key(def_name: &str, key_value: &Value) -> Result<(), ValidationError> {
294 match key_value.as_str() {
295+ Some("tid") | Some("any") | Some("nsid") => Ok(()),
296 Some(k) if k.starts_with("literal:") => Ok(()),
297 Some(invalid) => Err(ValidationError::InvalidSchema(format!(
298+ "Record '{}' has invalid key type '{}'. Must be 'tid', 'any', 'nsid', or 'literal:*'",
299 def_name, invalid
300 ))),
301 None => Err(ValidationError::InvalidSchema(format!(
···587 let record = json!({
588 "type": "record",
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",
617 "record": {
618 "type": "object",
619 "properties": {
+1-1
packages/lexicon-intellisense/package.json
···1{
2 "name": "lexicon-intellisense",
3- "version": "0.2.1",
4 "description": "VS Code IntelliSense support for AT Protocol lexicon JSON files",
5 "main": "./out/extension.js",
6 "license": "MIT",
···1{
2 "name": "lexicon-intellisense",
3+ "version": "0.3.0",
4 "description": "VS Code IntelliSense support for AT Protocol lexicon JSON files",
5 "main": "./out/extension.js",
6 "license": "MIT",
+40-20
packages/lexicon-intellisense/wasm/README.md
···1-# lexicon-rs
23Rust implementation of AT Protocol lexicon validation.
45## Overview
67-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.
00089## Architecture
1011-This package serves as the core validation engine and is typically consumed by higher-level packages:
01213- **`@slices/lexicon`** - TypeScript/Deno package with ergonomic APIs
014- **`lexicon-intellisense`** - VS Code extension for lexicon development
15-- **Slices CLI** - Command-line tooling for lexicon management
1617## Features
18···3132```toml
33[dependencies]
34-slices-lexicon = "0.1"
35```
3637Basic validation:
···91Use in JavaScript environments:
9293```javascript
94-import init, {
95- WasmLexiconValidator,
96- validate_lexicons_and_get_errors,
97- is_valid_nsid
98-} from './pkg/slices_lexicon.js';
99100await init();
101102// Validate lexicons
103const lexicons = [{
104- id: "com.example.post",
105- lexicon: 1,
106- defs: { /* ... */ }
000000000000107}];
108109-const errors = validate_lexicons_and_get_errors(JSON.stringify(lexicons));
110-console.log('Validation errors:', JSON.parse(errors));
0111112-// Validate NSID format
113-const isValid = is_valid_nsid("com.example.post");
00000114```
115116## JavaScript/TypeScript Usage
117118-If you're using JavaScript or TypeScript, use the higher-level packages instead of consuming this library directly:
0119120-- **TypeScript/JavaScript**: Use `@slices/lexicon` for ergonomic APIs with automatic resource management
0121- **VS Code Development**: Install the `lexicon-intellisense` extension
122- **CLI Tools**: Use the Slices CLI for lexicon management tasks
123···151152## License
153154-MIT
···1+# slices-lexicon
23Rust implementation of AT Protocol lexicon validation.
45## Overview
67+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.
1112## Architecture
1314+This package serves as the core validation engine and is typically consumed by
15+higher-level packages:
1617- **`@slices/lexicon`** - TypeScript/Deno package with ergonomic APIs
18+- **`@slices/cli`** - Deno command-line tool for lexicon/appview management
19- **`lexicon-intellisense`** - VS Code extension for lexicon development
02021## Features
22···3536```toml
37[dependencies]
38+slices-lexicon = "0.2"
39```
4041Basic validation:
···95Use in JavaScript environments:
9697```javascript
98+import init, { WasmLexiconValidator } from "./pkg/slices_lexicon.js";
000099100await init();
101102// Validate lexicons
103const lexicons = [{
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+ },
119}];
120121+const validator = new WasmLexiconValidator(JSON.stringify(lexicons));
122+const errorsJson = validator.validate_lexicons();
123+const errors = JSON.parse(errorsJson);
124125+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
132```
133134## JavaScript/TypeScript Usage
135136+If you're using JavaScript or TypeScript, use the higher-level packages instead
137+of consuming this library directly:
138139+- **TypeScript/JavaScript**: Use `@slices/lexicon` for ergonomic APIs with
140+ automatic resource management
141- **VS Code Development**: Install the `lexicon-intellisense` extension
142- **CLI Tools**: Use the Slices CLI for lexicon management tasks
143···171172## License
173174+MIT
···1-# lexicon-rs
23Rust implementation of AT Protocol lexicon validation.
45## Overview
67-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.
00089## Architecture
1011-This package serves as the core validation engine and is typically consumed by higher-level packages:
01213- **`@slices/lexicon`** - TypeScript/Deno package with ergonomic APIs
014- **`lexicon-intellisense`** - VS Code extension for lexicon development
15-- **Slices CLI** - Command-line tooling for lexicon management
1617## Features
18···3132```toml
33[dependencies]
34-slices-lexicon = "0.1"
35```
3637Basic validation:
···91Use in JavaScript environments:
9293```javascript
94-import init, {
95- WasmLexiconValidator,
96- validate_lexicons_and_get_errors,
97- is_valid_nsid
98-} from './pkg/slices_lexicon.js';
99100await init();
101102// Validate lexicons
103const lexicons = [{
104- id: "com.example.post",
105- lexicon: 1,
106- defs: { /* ... */ }
000000000000107}];
108109-const errors = validate_lexicons_and_get_errors(JSON.stringify(lexicons));
110-console.log('Validation errors:', JSON.parse(errors));
0111112-// Validate NSID format
113-const isValid = is_valid_nsid("com.example.post");
00000114```
115116## JavaScript/TypeScript Usage
117118-If you're using JavaScript or TypeScript, use the higher-level packages instead of consuming this library directly:
0119120-- **TypeScript/JavaScript**: Use `@slices/lexicon` for ergonomic APIs with automatic resource management
0121- **VS Code Development**: Install the `lexicon-intellisense` extension
122- **CLI Tools**: Use the Slices CLI for lexicon management tasks
123···151152## License
153154-MIT
···1+# slices-lexicon
23Rust implementation of AT Protocol lexicon validation.
45## Overview
67+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.
1112## Architecture
1314+This package serves as the core validation engine and is typically consumed by
15+higher-level packages:
1617- **`@slices/lexicon`** - TypeScript/Deno package with ergonomic APIs
18+- **`@slices/cli`** - Deno command-line tool for lexicon/appview management
19- **`lexicon-intellisense`** - VS Code extension for lexicon development
02021## Features
22···3536```toml
37[dependencies]
38+slices-lexicon = "0.2"
39```
4041Basic validation:
···95Use in JavaScript environments:
9697```javascript
98+import init, { WasmLexiconValidator } from "./pkg/slices_lexicon.js";
000099100await init();
101102// Validate lexicons
103const lexicons = [{
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+ },
119}];
120121+const validator = new WasmLexiconValidator(JSON.stringify(lexicons));
122+const errorsJson = validator.validate_lexicons();
123+const errors = JSON.parse(errorsJson);
124125+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
132```
133134## JavaScript/TypeScript Usage
135136+If you're using JavaScript or TypeScript, use the higher-level packages instead
137+of consuming this library directly:
138139+- **TypeScript/JavaScript**: Use `@slices/lexicon` for ergonomic APIs with
140+ automatic resource management
141- **VS Code Development**: Install the `lexicon-intellisense` extension
142- **CLI Tools**: Use the Slices CLI for lexicon management tasks
143···171172## License
173174+MIT