An experimental TypeSpec syntax for Lexicon

ok

+324 -3
+18
packages/emitter/test/spec/basic/input/com/example/createRecord.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.createRecord { 4 + @doc("The provided text is invalid") 5 + model InvalidText {} 6 + 7 + @doc("Create a new record") 8 + @procedure 9 + @errors(InvalidText) 10 + op main(input: { 11 + @doc("The text content") 12 + @required 13 + text: string; 14 + }): { 15 + @required uri: atUri; 16 + @required cid: cid; 17 + }; 18 + }
+9
packages/emitter/test/spec/basic/input/com/example/deleteRecord.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.deleteRecord { 4 + @doc("Delete a record (no output)") 5 + @procedure 6 + op main(input: { 7 + @required uri: atUri; 8 + }): void; 9 + }
+43
packages/emitter/test/spec/basic/input/com/example/eventStream.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.eventStream { 4 + @doc("Cursor is in the future") 5 + model FutureCursor {} 6 + 7 + @doc("Subscription with union message schema") 8 + @subscription 9 + @errors(FutureCursor) 10 + op main(cursor?: integer): (Commit | Identity | Account | Handle | Tombstone); 11 + 12 + model Commit { 13 + @required seq: integer; 14 + @required time: datetime; 15 + @required repo: did; 16 + } 17 + 18 + model Identity { 19 + @required seq: integer; 20 + @required time: datetime; 21 + @required did: did; 22 + } 23 + 24 + model Account { 25 + @required seq: integer; 26 + @required time: datetime; 27 + @required did: did; 28 + @required active: boolean; 29 + } 30 + 31 + model Handle { 32 + @required seq: integer; 33 + @required time: datetime; 34 + @required did: did; 35 + @required handle: handle; 36 + } 37 + 38 + model Tombstone { 39 + @required seq: integer; 40 + @required time: datetime; 41 + @required did: did; 42 + } 43 + }
+10
packages/emitter/test/spec/basic/input/com/example/flexibleRecord.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.flexibleRecord { 4 + @rec("any") 5 + @doc("Record with any key type") 6 + model Main { 7 + data?: string; 8 + tags?: string[]; 9 + } 10 + }
+13
packages/emitter/test/spec/basic/input/com/example/getRecord.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.getRecord { 4 + @doc("Retrieve a record by ID") 5 + @query 6 + op main( 7 + @doc("The record identifier") 8 + @required 9 + id: string 10 + ): { 11 + @required record: com.example.`record`.Main; 12 + }; 13 + }
+10
packages/emitter/test/spec/basic/input/com/example/getStatus.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.getStatus { 4 + @doc("Get system status (no parameters)") 5 + @query 6 + op main(): { 7 + @required status: string; 8 + uptime?: integer; 9 + }; 10 + }
+8
packages/emitter/test/spec/basic/input/com/example/outputWithoutSchema.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.outputWithoutSchema { 4 + @query 5 + @encoding("application/json") 6 + @doc("Query with JSON output but no schema defined") 7 + op main(id?: string): never; 8 + }
+14
packages/emitter/test/spec/basic/input/com/example/profile.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.profile { 4 + @rec("literal:self") 5 + @doc("Record with literal 'self' key") 6 + model Main { 7 + @maxGraphemes(64) 8 + @required 9 + displayName: string; 10 + 11 + @maxGraphemes(256) 12 + description?: string; 13 + } 14 + }
+29
packages/emitter/test/spec/basic/input/com/example/queryParams.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.queryParams { 4 + @doc("Query with various parameter types") 5 + @query 6 + op main( 7 + @doc("A required query parameter") 8 + @required 9 + requiredParam: string, 10 + 11 + @doc("Optional boolean parameter") 12 + boolParam?: boolean, 13 + 14 + @doc("Optional integer parameter") 15 + intParam?: integer, 16 + 17 + @doc("Optional string parameter") 18 + @maxLength(100) 19 + stringParam?: string, 20 + 21 + @doc("Array of strings") 22 + arrayParam?: string[], 23 + 24 + @doc("Unknown type parameter") 25 + unknownParam?: unknown 26 + ): { 27 + @required result: string; 28 + }; 29 + }
+15
packages/emitter/test/spec/basic/input/com/example/record.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.`record` { 4 + @rec("tid") 5 + @doc("A simple record with basic properties") 6 + model Main { 7 + @doc("The text content") 8 + @required 9 + text: string; 10 + 11 + @doc("When the record was created") 12 + @required 13 + createdAt: datetime; 14 + } 15 + }
+16
packages/emitter/test/spec/basic/input/com/example/refInOutput.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.refInOutput { 4 + @doc("Procedure with ref in output schema") 5 + @procedure 6 + op main(input: InputData): OutputData; 7 + 8 + model InputData { 9 + @required value: string; 10 + } 11 + 12 + model OutputData { 13 + @required result: string; 14 + @required timestamp: datetime; 15 + } 16 + }
+19
packages/emitter/test/spec/basic/input/com/example/refs.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.refs { 4 + @doc("Reference examples") 5 + model Main { 6 + @doc("Reference to local definition") 7 + localRef?: LocalDef; 8 + 9 + @doc("Reference to external definition") 10 + externalRef?: com.example.defs.Metadata; 11 + 12 + @doc("Reference to main definition (no fragment)") 13 + mainRef?: com.example.`record`.Main; 14 + } 15 + 16 + model LocalDef { 17 + @required value: string; 18 + } 19 + }
+19
packages/emitter/test/spec/basic/input/com/example/subscribeRecords.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.subscribeRecords { 4 + @doc("Subscribe to record updates") 5 + @subscription 6 + op main( 7 + @doc("Optional cursor for resuming") 8 + cursor?: integer 9 + ): (Record | Delete); 10 + 11 + model Record { 12 + @required uri: atUri; 13 + @required record: com.example.`record`.Main; 14 + } 15 + 16 + model Delete { 17 + @required uri: atUri; 18 + } 19 + }
+20
packages/emitter/test/spec/basic/input/com/example/tokens.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.tokens { 4 + @doc("Token usage example") 5 + model Main { 6 + @required status: Active; 7 + } 8 + 9 + @doc("Indicates an active state") 10 + @token 11 + model Active {} 12 + 13 + @doc("Indicates an inactive state") 14 + @token 15 + model Inactive {} 16 + 17 + @doc("Indicates a pending state") 18 + @token 19 + model Pending {} 20 + }
+9
packages/emitter/test/spec/basic/input/com/example/unionEmpty.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.unionEmpty { 4 + @doc("Empty open union (similar to unknown but requires $type)") 5 + model Main { 6 + @doc("Empty open union - any object with $type allowed") 7 + data?: (never | unknown); 8 + } 9 + }
+34
packages/emitter/test/spec/basic/input/com/example/unionOpen.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.unionOpen { 4 + @doc("Open union example (default)") 5 + model Main { 6 + @doc("Open union - more variants can be added in future") 7 + @required 8 + item: TypeA | TypeB | TypeC | unknown; 9 + } 10 + 11 + model TypeA { 12 + @readOnly 13 + @required 14 + kind: string = "a"; 15 + 16 + @required valueA: string; 17 + } 18 + 19 + model TypeB { 20 + @readOnly 21 + @required 22 + kind: string = "b"; 23 + 24 + @required valueB: integer; 25 + } 26 + 27 + model TypeC { 28 + @readOnly 29 + @required 30 + kind: string = "c"; 31 + 32 + @required valueC: boolean; 33 + } 34 + }
+14
packages/emitter/test/spec/basic/input/com/example/unknown.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + using TypeSpec.Reflection; 4 + 5 + namespace com.example.`unknown` { 6 + @doc("Unknown type usage") 7 + model Main { 8 + @doc("Any object data without validation") 9 + metadata?: unknown; 10 + 11 + @doc("Optional unknown field") 12 + optionalMetadata?: unknown; 13 + } 14 + }
+23
packages/emitter/test/spec/basic/input/com/example/withErrors.tsp
··· 1 + import "@tylex/emitter"; 2 + 3 + namespace com.example.withErrors { 4 + @doc("The provided value is invalid") 5 + model InvalidValue {} 6 + 7 + @doc("Too many requests") 8 + model RateLimitExceeded {} 9 + 10 + model Unauthorized {} 11 + 12 + @doc("Procedure with error definitions") 13 + @procedure 14 + @errors(InvalidValue, RateLimitExceeded, Unauthorized) 15 + op main(input: { 16 + @minValue(1) 17 + @maxValue(100) 18 + @required 19 + value: integer; 20 + }): { 21 + @required result: string; 22 + }; 23 + }
-1
packages/emitter/test/spec/basic/output/com/example/eventStream.json
··· 14 14 } 15 15 }, 16 16 "message": { 17 - "description": "Stream of events", 18 17 "schema": { 19 18 "type": "union", 20 19 "refs": ["#commit", "#identity", "#account", "#handle", "#tombstone"]
+1 -2
packages/emitter/test/spec/basic/output/com/example/outputWithoutSchema.json
··· 14 14 } 15 15 }, 16 16 "output": { 17 - "encoding": "application/json", 18 - "description": "Returns JSON data without a defined schema" 17 + "encoding": "application/json" 19 18 } 20 19 } 21 20 }