microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
4199f83575db84feb69e28f57d78c400aec1eab4

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

packages/compiler/lib/lib.tsp

212lines · modecode

1namespace TypeSpec;
2
3/**
4 * Represent a byte array
5 */
6scalar bytes;
7
8/**
9 * A numeric type
10 */
11scalar numeric;
12
13/**
14 * A whole number. This represent any `integer` value possible.
15 * It is commonly represented as `BigInteger` in some languages.
16 */
17scalar integer extends numeric;
18
19/**
20 * A number with decimal value
21 */
22scalar float extends numeric;
23
24/**
25 * A 64-bit integer. (`-9,223,372,036,854,775,808` to `9,223,372,036,854,775,807`)
26 */
27scalar int64 extends integer;
28
29/**
30 * A 32-bit integer. (`-2,147,483,648` to `2,147,483,647`)
31 */
32scalar int32 extends int64;
33
34/**
35 * A 16-bit integer. (`-32,768` to `32,767`)
36 */
37scalar int16 extends int32;
38
39/**
40 * A 8-bit integer. (`-128` to `127`)
41 */
42scalar int8 extends int16;
43
44/**
45 * A 64-bit unsigned integer (`0` to `18,446,744,073,709,551,615`)
46 */
47scalar uint64 extends integer;
48
49/**
50 * A 32-bit unsigned integer (`0` to `4,294,967,295`)
51 */
52scalar uint32 extends uint64;
53
54/**
55 * A 16-bit unsigned integer (`0` to `65,535`)
56 */
57scalar uint16 extends uint32;
58
59/**
60 * A 8-bit unsigned integer (`0` to `255`)
61 */
62scalar uint8 extends uint16;
63
64/**
65 * An integer that can be serialized to JSON (`−9007199254740991 (−(2^53 − 1))` to `9007199254740991 (2^53 − 1)` )
66 */
67scalar safeint extends int64;
68
69/**
70 * A 32 bit floating point number. (`±1.5 x 10^−45` to `±3.4 x 10^38`)
71 */
72scalar float64 extends float;
73
74/**
75 * A 32 bit floating point number. (`±5.0 × 10^−324` to `±1.7 × 10^308`)
76 */
77scalar float32 extends float64;
78
79/**
80 * A decimal number with any length and precision. This represent any `decimal` value possible.
81 * It is commonly represented as `BigDecimal` in some languages.
82 */
83scalar decimal extends numeric;
84
85/**
86 * A 128-bit decimal number.
87 */
88scalar decimal128 extends decimal;
89
90/**
91 * A sequence of textual characters.
92 */
93scalar string;
94
95/**
96 * A date on a calendar without a time zone, e.g. "April 10th"
97 */
98scalar plainDate;
99
100/**
101 * A time on a clock without a time zone, e.g. "3:00 am"
102 */
103scalar plainTime;
104
105/**
106 * An instant in coordinated universal time (UTC)"
107 */
108scalar utcDateTime;
109
110/**
111 * A date and time in a particular time zone, e.g. "April 10th at 3:00am in PST"
112 */
113scalar offsetDateTime;
114
115/**
116 * A duration/time period. e.g 5s, 10h
117 */
118scalar duration;
119
120/**
121 * Boolean with `true` and `false` values.
122 */
123scalar boolean;
124
125/**
126 * Represent a 32-bit unix timestamp datetime with 1s of granularity.
127 * It measures time by the number of seconds that have elapsed since 00:00:00 UTC on 1 January 1970.
128 */
129@encode("unixTimestamp", int32)
130scalar unixTimestamp32 extends utcDateTime;
131
132/**
133 * Represent a model
134 */
135// Deprecated June 2023 sprint
136#deprecated "object is deprecated. Please use {} for an empty model, `Record<unknown>` for a record with unknown property types, `unknown[]` for an array."
137model object {}
138
139/**
140 * @dev Array model type, equivalent to `Element[]`
141 * @template Element The type of the array elements
142 */
143@indexer(integer, Element)
144model Array<Element> {}
145
146/**
147 * @dev Model with string properties where all the properties have type `Property`
148 * @template Element The type of the properties
149 */
150@indexer(string, Element)
151model Record<Element> {}
152
153/**
154 * Represent a URL string as described by https://url.spec.whatwg.org/
155 */
156scalar url extends string;
157
158/**
159 * Represents a collection of optional properties.
160 *
161 * @template Source An object whose spread properties are all optional.
162 */
163@doc("The template for adding optional properties.")
164@withOptionalProperties
165model OptionalProperties<Source> {
166 ...Source;
167}
168
169/**
170 * Represents a collection of updateable properties.
171 *
172 * @template Source An object whose spread properties are all updateable.
173 */
174@doc("The template for adding updateable properties.")
175@withUpdateableProperties
176model UpdateableProperties<Source> {
177 ...Source;
178}
179
180/**
181 * Represents a collection of omitted properties.
182 *
183 * @template Source An object whose properties are spread.
184 * @template Keys The property keys to omit.
185 */
186@doc("The template for omitting properties.")
187@withoutOmittedProperties(Keys)
188model OmitProperties<Source, Keys extends string> {
189 ...Source;
190}
191
192/**
193 * Represents a collection of properties with default values omitted.
194 *
195 * @template Source An object whose spread property defaults are all omitted.
196 */
197@withoutDefaultValues
198model OmitDefaults<Source> {
199 ...Source;
200}
201
202/**
203 * Applies a visibility setting to a collection of properties.
204 *
205 * @template Source An object whose properties are spread.
206 * @template Visibility The visibility to apply to all properties.
207 */
208@doc("The template for setting the default visibility of key properties.")
209@withDefaultKeyVisibility(Visibility)
210model DefaultKeyVisibility<Source, Visibility extends valueof string> {
211 ...Source;
212}
213