microsoft/typespec
Publicmirrored from https://github.com/microsoft/typespecAvailable
packages/compiler/lib/intrinsics.tsp
231lines · modecode
| 1 | import "../dist/src/lib/intrinsic/tsp-index.js"; |
| 2 | import "./prototypes.tsp"; |
| 3 | |
| 4 | // This file contains all the intrinsic types of typespec. Everything here will always be loaded |
| 5 | namespace TypeSpec; |
| 6 | |
| 7 | /** |
| 8 | * Represent a byte array |
| 9 | */ |
| 10 | scalar bytes; |
| 11 | |
| 12 | /** |
| 13 | * A numeric type |
| 14 | */ |
| 15 | scalar numeric; |
| 16 | |
| 17 | /** |
| 18 | * A whole number. This represent any `integer` value possible. |
| 19 | * It is commonly represented as `BigInteger` in some languages. |
| 20 | */ |
| 21 | scalar integer extends numeric; |
| 22 | |
| 23 | /** |
| 24 | * A number with decimal value |
| 25 | */ |
| 26 | scalar float extends numeric; |
| 27 | |
| 28 | /** |
| 29 | * A 64-bit integer. (`-9,223,372,036,854,775,808` to `9,223,372,036,854,775,807`) |
| 30 | */ |
| 31 | scalar int64 extends integer; |
| 32 | |
| 33 | /** |
| 34 | * A 32-bit integer. (`-2,147,483,648` to `2,147,483,647`) |
| 35 | */ |
| 36 | scalar int32 extends int64; |
| 37 | |
| 38 | /** |
| 39 | * A 16-bit integer. (`-32,768` to `32,767`) |
| 40 | */ |
| 41 | scalar int16 extends int32; |
| 42 | |
| 43 | /** |
| 44 | * A 8-bit integer. (`-128` to `127`) |
| 45 | */ |
| 46 | scalar int8 extends int16; |
| 47 | |
| 48 | /** |
| 49 | * A 64-bit unsigned integer (`0` to `18,446,744,073,709,551,615`) |
| 50 | */ |
| 51 | scalar uint64 extends integer; |
| 52 | |
| 53 | /** |
| 54 | * A 32-bit unsigned integer (`0` to `4,294,967,295`) |
| 55 | */ |
| 56 | scalar uint32 extends uint64; |
| 57 | |
| 58 | /** |
| 59 | * A 16-bit unsigned integer (`0` to `65,535`) |
| 60 | */ |
| 61 | scalar uint16 extends uint32; |
| 62 | |
| 63 | /** |
| 64 | * A 8-bit unsigned integer (`0` to `255`) |
| 65 | */ |
| 66 | scalar uint8 extends uint16; |
| 67 | |
| 68 | /** |
| 69 | * An integer that can be serialized to JSON (`−9007199254740991 (−(2^53 − 1))` to `9007199254740991 (2^53 − 1)` ) |
| 70 | */ |
| 71 | scalar safeint extends int64; |
| 72 | |
| 73 | /** |
| 74 | * A 64 bit floating point number. (`±5.0 × 10^−324` to `±1.7 × 10^308`) |
| 75 | */ |
| 76 | scalar float64 extends float; |
| 77 | |
| 78 | /** |
| 79 | * A 32 bit floating point number. (`±1.5 x 10^−45` to `±3.4 x 10^38`) |
| 80 | */ |
| 81 | scalar float32 extends float64; |
| 82 | |
| 83 | /** |
| 84 | * A decimal number with any length and precision. This represent any `decimal` value possible. |
| 85 | * It is commonly represented as `BigDecimal` in some languages. |
| 86 | */ |
| 87 | scalar decimal extends numeric; |
| 88 | |
| 89 | /** |
| 90 | * A 128-bit decimal number. |
| 91 | */ |
| 92 | scalar decimal128 extends decimal; |
| 93 | |
| 94 | /** |
| 95 | * A sequence of textual characters. |
| 96 | */ |
| 97 | scalar string; |
| 98 | |
| 99 | /** |
| 100 | * A date on a calendar without a time zone, e.g. "April 10th" |
| 101 | */ |
| 102 | scalar plainDate { |
| 103 | /** |
| 104 | * Create a plain date from an ISO 8601 string. |
| 105 | * @example |
| 106 | * |
| 107 | * ```tsp |
| 108 | * const date = plainDate.fromISO("2024-05-06"); |
| 109 | * ``` |
| 110 | */ |
| 111 | init fromISO(value: string); |
| 112 | |
| 113 | /** |
| 114 | * Create a plain date representing the current date. |
| 115 | * @example |
| 116 | * |
| 117 | * ```tsp |
| 118 | * const date = plainDate.now(); |
| 119 | * ``` |
| 120 | */ |
| 121 | init now(); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * A time on a clock without a time zone, e.g. "3:00 am" |
| 126 | */ |
| 127 | scalar plainTime { |
| 128 | /** |
| 129 | * Create a plain time from an ISO 8601 string. |
| 130 | * @example |
| 131 | * |
| 132 | * ```tsp |
| 133 | * const time = plainTime.fromISO("12:34"); |
| 134 | * ``` |
| 135 | */ |
| 136 | init fromISO(value: string); |
| 137 | |
| 138 | /** |
| 139 | * Create a plain time representing the current time. |
| 140 | * @example |
| 141 | * |
| 142 | * ```tsp |
| 143 | * const time = plainTime.now(); |
| 144 | * ``` |
| 145 | */ |
| 146 | init now(); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * An instant in coordinated universal time (UTC)" |
| 151 | */ |
| 152 | scalar utcDateTime { |
| 153 | /** |
| 154 | * Create a date from an ISO 8601 string. |
| 155 | * @example |
| 156 | * |
| 157 | * ```tsp |
| 158 | * const time = utcDateTime.fromISO("2024-05-06T12:20-12Z"); |
| 159 | * ``` |
| 160 | */ |
| 161 | init fromISO(value: string); |
| 162 | |
| 163 | /** |
| 164 | * Create a date representing the current date and time in UTC. |
| 165 | * @example |
| 166 | * |
| 167 | * ```tsp |
| 168 | * const time = utcDateTime.now(); |
| 169 | * ``` |
| 170 | */ |
| 171 | init now(); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * A date and time in a particular time zone, e.g. "April 10th at 3:00am in PST" |
| 176 | */ |
| 177 | scalar offsetDateTime { |
| 178 | /** |
| 179 | * Create a date from an ISO 8601 string. |
| 180 | * @example |
| 181 | * |
| 182 | * ```tsp |
| 183 | * const time = offsetDateTime.fromISO("2024-05-06T12:20-12-0700"); |
| 184 | * ``` |
| 185 | */ |
| 186 | init fromISO(value: string); |
| 187 | |
| 188 | /** |
| 189 | * Create a date representing the current date and time with offset. |
| 190 | * @example |
| 191 | * |
| 192 | * ```tsp |
| 193 | * const time = offsetDateTime.now(); |
| 194 | * ``` |
| 195 | */ |
| 196 | init now(); |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * A duration/time period. e.g 5s, 10h |
| 201 | */ |
| 202 | scalar duration { |
| 203 | /** |
| 204 | * Create a duration from an ISO 8601 string. |
| 205 | * @example |
| 206 | * |
| 207 | * ```tsp |
| 208 | * const time = duration.fromISO("P1Y1D"); |
| 209 | * ``` |
| 210 | */ |
| 211 | init fromISO(value: string); |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Boolean with `true` and `false` values. |
| 216 | */ |
| 217 | scalar boolean; |
| 218 | |
| 219 | /** |
| 220 | * @dev Array model type, equivalent to `Element[]` |
| 221 | * @template Element The type of the array elements |
| 222 | */ |
| 223 | @indexer(integer, Element) |
| 224 | model Array<Element> {} |
| 225 | |
| 226 | /** |
| 227 | * @dev Model with string properties where all the properties have type `Property` |
| 228 | * @template Element The type of the properties |
| 229 | */ |
| 230 | @indexer(string, Element) |
| 231 | model Record<Element> {} |
| 232 | |