+63
-2
DOCS.md
+63
-2
DOCS.md
···
41
41
42
42
Use `/** */` doc comments for descriptions (or `@doc()` decorator as alternative).
43
43
44
+
## Reserved Words
45
+
44
46
Use backticks for TypeScript/TypeSpec reserved words:
45
47
46
48
```typescript
···
49
51
}
50
52
```
51
53
52
-
The first namespace in the file will be turned into JSON. However, you can put more of them in the same file (if you want to reference them).
54
+
## Many Lexicons in One File
55
+
56
+
Multiple namespaces can be defined in one file:
57
+
58
+
```typescript
59
+
import "@typelex/emitter";
60
+
61
+
namespace com.example.foo {
62
+
@rec("tid")
63
+
model Main {
64
+
bar?: com.example.bar.Main
65
+
}
66
+
}
67
+
68
+
namespace com.example.bar {
69
+
model Main {
70
+
@maxGraphemes(1)
71
+
bla?: string;
72
+
}
73
+
}
74
+
```
75
+
76
+
This single `.tsp` file will turn into two Lexicon files in the output folder:
77
+
78
+
```
79
+
- com/example/foo.json
80
+
- com/example/bar.json
81
+
```
82
+
83
+
You can see this in action in the Playground, where every example is written as a single input file. For example, [this `app.bsky.actor.profile` example](https://playground.typelex.org/?sample=app.bsky.actor.profile) "spits out" multiple outputs like `app/bsky/actor/profile.json`, `com/atproto/label/defs.json`, and so on, which you can see in the right pane.
53
84
54
85
## Dependencies
55
86
56
-
You can `import` other `.tsp` files.
87
+
You can `import` other `.tsp` files. This lets you avoid defining the same thing many times if you want to refer to it from many files.
88
+
89
+
For example:
90
+
91
+
```typescript
92
+
// main.tsp
93
+
94
+
import "@typelex/emitter";
95
+
import "./bar.tsp";
96
+
97
+
namespace com.example.foo {
98
+
@rec("tid")
99
+
model Main {
100
+
bar?: com.example.bar.Main
101
+
}
102
+
}
103
+
````
104
+
105
+
```typescript
106
+
// bar.tsp
107
+
namespace com.example.bar {
108
+
model Main {
109
+
@maxGraphemes(1)
110
+
bla?: string;
111
+
}
112
+
}
113
+
````
114
+
115
+
It doesn't matter how you split input into files. The output structure is only determined by namespaces.
116
+
117
+
## Stubs
57
118
58
119
For now, we're assuming you write everything in TypeSpec. You can grab common Lexicons from the [Playground](https://playground.typelex.org/). However, if you just want a ref, you could stub out any external Lexicon, like this:
59
120