@typespec/compiler 0.44.0-dev.2 → 0.44.0-dev.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cmd/runner.js.map +1 -1
- package/dist/core/checker.d.ts +1 -6
- package/dist/core/checker.d.ts.map +1 -1
- package/dist/core/checker.js +22 -18
- package/dist/core/checker.js.map +1 -1
- package/dist/core/cli/args.d.ts.map +1 -1
- package/dist/core/cli/args.js +3 -2
- package/dist/core/cli/args.js.map +1 -1
- package/dist/core/decorator-utils.d.ts +1 -0
- package/dist/core/decorator-utils.d.ts.map +1 -1
- package/dist/core/decorator-utils.js +5 -1
- package/dist/core/decorator-utils.js.map +1 -1
- package/dist/core/helpers/type-name-utils.d.ts.map +1 -1
- package/dist/core/helpers/type-name-utils.js +8 -5
- package/dist/core/helpers/type-name-utils.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +6 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/messages.d.ts +30 -20
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +8 -6
- package/dist/core/messages.js.map +1 -1
- package/dist/core/node-host.js.map +1 -1
- package/dist/core/parser.d.ts.map +1 -1
- package/dist/core/parser.js +1 -7
- package/dist/core/parser.js.map +1 -1
- package/dist/core/path-utils.d.ts +10 -0
- package/dist/core/path-utils.d.ts.map +1 -1
- package/dist/core/path-utils.js +116 -1
- package/dist/core/path-utils.js.map +1 -1
- package/dist/core/program.d.ts +4 -0
- package/dist/core/program.d.ts.map +1 -1
- package/dist/core/program.js +19 -14
- package/dist/core/program.js.map +1 -1
- package/dist/core/projection-members.js +1 -1
- package/dist/core/projection-members.js.map +1 -1
- package/dist/core/projector.d.ts.map +1 -1
- package/dist/core/projector.js +11 -0
- package/dist/core/projector.js.map +1 -1
- package/dist/core/scanner.d.ts.map +1 -1
- package/dist/core/scanner.js.map +1 -1
- package/dist/core/type-utils.d.ts +2 -1
- package/dist/core/type-utils.d.ts.map +1 -1
- package/dist/core/type-utils.js.map +1 -1
- package/dist/core/types.d.ts +14 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/emitter-framework/asset-emitter.js.map +1 -1
- package/dist/emitter-framework/builders/object-builder.d.ts +1 -1
- package/dist/emitter-framework/builders/object-builder.d.ts.map +1 -1
- package/dist/emitter-framework/builders/object-builder.js +11 -2
- package/dist/emitter-framework/builders/object-builder.js.map +1 -1
- package/dist/emitter-framework/type-emitter.d.ts.map +1 -1
- package/dist/emitter-framework/type-emitter.js +0 -1
- package/dist/emitter-framework/type-emitter.js.map +1 -1
- package/dist/formatter/print/printer.js +1 -1
- package/dist/formatter/print/printer.js.map +1 -1
- package/dist/lib/decorators.d.ts +10 -10
- package/dist/lib/decorators.d.ts.map +1 -1
- package/dist/lib/decorators.js +83 -19
- package/dist/lib/decorators.js.map +1 -1
- package/dist/manifest.js +1 -1
- package/dist/server/serverlib.d.ts +1 -1
- package/dist/server/serverlib.d.ts.map +1 -1
- package/dist/server/serverlib.js +10 -3
- package/dist/server/serverlib.js.map +1 -1
- package/dist/testing/expect.d.ts.map +1 -1
- package/dist/testing/expect.js +1 -1
- package/dist/testing/expect.js.map +1 -1
- package/dist/testing/test-host.js.map +1 -1
- package/dist/testing/test-server-host.d.ts.map +1 -1
- package/dist/testing/test-server-host.js +1 -1
- package/dist/testing/test-server-host.js.map +1 -1
- package/lib/decorators.tsp +119 -11
- package/lib/lib.tsp +25 -1
- package/lib/reflection.tsp +4 -2
- package/package.json +17 -18
package/lib/decorators.tsp
CHANGED
|
@@ -92,11 +92,11 @@ extern dec service(target: Namespace, options?: ServiceOptions);
|
|
|
92
92
|
* }
|
|
93
93
|
* ```
|
|
94
94
|
*/
|
|
95
|
-
extern dec error(target:
|
|
95
|
+
extern dec error(target: Model);
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
98
|
* Specify a known data format hint for this string type. For example `uuid`, `uri`, etc.
|
|
99
|
-
* This
|
|
99
|
+
* This differs from the `@pattern` decorator which is meant to specify a regular expression while `@format` accepts a known format name.
|
|
100
100
|
* The format names are open ended and are left to emitter to interpret.
|
|
101
101
|
*
|
|
102
102
|
* @param format format name.
|
|
@@ -242,7 +242,7 @@ extern dec tag(target: Namespace | Interface | Operation, tag: string);
|
|
|
242
242
|
/**
|
|
243
243
|
* Specifies how a templated type should name their instances.
|
|
244
244
|
* @param name name the template instance should take
|
|
245
|
-
* @formatArgs Model with key value used to interpolate the name
|
|
245
|
+
* @param formatArgs Model with key value used to interpolate the name
|
|
246
246
|
*
|
|
247
247
|
* @example
|
|
248
248
|
* ```typespec
|
|
@@ -274,6 +274,7 @@ extern dec knownValues(target: string | numeric | ModelProperty, values: Enum);
|
|
|
274
274
|
|
|
275
275
|
/**
|
|
276
276
|
* Mark a model property as the key to identify instances of that type
|
|
277
|
+
* @param altName Name of the property. If not specified, the decorated property name is used.
|
|
277
278
|
*
|
|
278
279
|
* @example
|
|
279
280
|
* ```typespec
|
|
@@ -316,6 +317,7 @@ extern dec projectedName(target: unknown, targetName: string, projectedName: str
|
|
|
316
317
|
|
|
317
318
|
/**
|
|
318
319
|
* Specify the property to be used to discriminate this type.
|
|
320
|
+
* @param propertyName The property name to use for discrimination
|
|
319
321
|
*
|
|
320
322
|
* @example
|
|
321
323
|
*
|
|
@@ -335,7 +337,80 @@ extern dec projectedName(target: unknown, targetName: string, projectedName: str
|
|
|
335
337
|
* model Dog extends Pet {kind: "dog", bark: boolean}
|
|
336
338
|
* ```
|
|
337
339
|
*/
|
|
338
|
-
extern dec discriminator(target:
|
|
340
|
+
extern dec discriminator(target: Model | Union, propertyName: string);
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Known encoding to use on utcDateTime or offsetDateTime
|
|
344
|
+
*/
|
|
345
|
+
enum DateTimeKnownEncoding {
|
|
346
|
+
/**
|
|
347
|
+
* RFC 3339 standard. https://www.ietf.org/rfc/rfc3339.txt
|
|
348
|
+
* Encode to string.
|
|
349
|
+
*/
|
|
350
|
+
rfc3339: "rfc3339",
|
|
351
|
+
/**
|
|
352
|
+
* RFC 7231 standard. https://www.ietf.org/rfc/rfc7231.txt
|
|
353
|
+
* Encode to string.
|
|
354
|
+
*/
|
|
355
|
+
rfc7231: "rfc7231",
|
|
356
|
+
/**
|
|
357
|
+
* Encode to integer
|
|
358
|
+
*/
|
|
359
|
+
unixTimestamp: "unixTimestamp",
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Known encoding to use on duration
|
|
364
|
+
*/
|
|
365
|
+
enum DurationKnownEncoding {
|
|
366
|
+
/**
|
|
367
|
+
* ISO8601 duration
|
|
368
|
+
*/
|
|
369
|
+
ISO8601: "ISO8601",
|
|
370
|
+
/**
|
|
371
|
+
* Encode to integer or float
|
|
372
|
+
*/
|
|
373
|
+
seconds: "seconds",
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Known encoding to use on bytes
|
|
378
|
+
*/
|
|
379
|
+
enum BytesKnownEncoding {
|
|
380
|
+
/**
|
|
381
|
+
* ISO8601 duration
|
|
382
|
+
*/
|
|
383
|
+
ISO8601: "ISO8601",
|
|
384
|
+
/**
|
|
385
|
+
* Encode to integer or float
|
|
386
|
+
*/
|
|
387
|
+
seconds: "seconds",
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Specify how to encode the target type.
|
|
392
|
+
* @param encoding Known name of an encoding.
|
|
393
|
+
* @param encodedAs What target type is this being encoded as. Default to string.
|
|
394
|
+
*
|
|
395
|
+
* @example offsetDateTime encoded with rfc7231
|
|
396
|
+
*
|
|
397
|
+
* ```tsp
|
|
398
|
+
* @encode("rfc7231")
|
|
399
|
+
* scalar myDateTime extends offsetDateTime;
|
|
400
|
+
* ```
|
|
401
|
+
*
|
|
402
|
+
* @example utcDateTime encoded with unixTimestamp
|
|
403
|
+
*
|
|
404
|
+
* ```tsp
|
|
405
|
+
* @encode("unixTimestamp", int32)
|
|
406
|
+
* scalar myDateTime extends unixTimestamp;
|
|
407
|
+
* ```
|
|
408
|
+
*/
|
|
409
|
+
extern dec encode(
|
|
410
|
+
target: Scalar | ModelProperty,
|
|
411
|
+
encoding: string | EnumMember,
|
|
412
|
+
encodedAs?: string | numeric
|
|
413
|
+
);
|
|
339
414
|
|
|
340
415
|
/**
|
|
341
416
|
* Indicates that a property is only considered to be present or applicable ("visible") with
|
|
@@ -352,7 +427,9 @@ extern dec discriminator(target: object | Union, propertyName: string);
|
|
|
352
427
|
* - "update": input to operations that update data.
|
|
353
428
|
* - "delete": input to operations that delete data.
|
|
354
429
|
*
|
|
355
|
-
* See also: [Automatic visibility](https://microsoft.github.io/typespec/standard-library/
|
|
430
|
+
* See also: [Automatic visibility](https://microsoft.github.io/typespec/standard-library/http/operations#automatic-visibility)
|
|
431
|
+
*
|
|
432
|
+
* @param visibilities List of visibilities which apply to this property.
|
|
356
433
|
*
|
|
357
434
|
* @example
|
|
358
435
|
*
|
|
@@ -375,11 +452,13 @@ extern dec visibility(target: ModelProperty, ...visibilities: string[]);
|
|
|
375
452
|
* together with spread to effectively spread only visible properties into
|
|
376
453
|
* a new model.
|
|
377
454
|
*
|
|
378
|
-
* See also: [Automatic visibility](https://microsoft.github.io/typespec/standard-library/
|
|
455
|
+
* See also: [Automatic visibility](https://microsoft.github.io/typespec/standard-library/http/operations#automatic-visibility)
|
|
379
456
|
*
|
|
380
457
|
* When using an emitter that applies visibility automatically, it is generally
|
|
381
458
|
* not necessary to use this decorator.
|
|
382
459
|
*
|
|
460
|
+
* @param visibilities List of visibilities which apply to this property.
|
|
461
|
+
*
|
|
383
462
|
* @example
|
|
384
463
|
* ```typespec
|
|
385
464
|
* model Dog {
|
|
@@ -407,14 +486,43 @@ extern dec visibility(target: ModelProperty, ...visibilities: string[]);
|
|
|
407
486
|
* }
|
|
408
487
|
* ```
|
|
409
488
|
*/
|
|
410
|
-
extern dec withVisibility(target:
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
489
|
+
extern dec withVisibility(target: Model, ...visibilities: string[]);
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Set the visibility of key properties in a model if not already set.
|
|
493
|
+
*
|
|
494
|
+
* @param visibility The desired default visibility value. If a key property already has a `visibility` decorator then the default visibility is not applied.
|
|
495
|
+
*/
|
|
496
|
+
extern dec withDefaultKeyVisibility(target: Model, visibility: unknown);
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Returns the model with non-updateable properties removed.
|
|
500
|
+
*/
|
|
501
|
+
extern dec withUpdateableProperties(target: Model);
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Returns the model with any default values removed.
|
|
505
|
+
*/
|
|
506
|
+
extern dec withoutDefaultValues(target: Model);
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Returns the model with the given properties omitted.
|
|
510
|
+
* @param omit List of properties to omit
|
|
511
|
+
*/
|
|
512
|
+
extern dec withoutOmittedProperties(target: Model, omit: string | Union);
|
|
415
513
|
|
|
416
514
|
//---------------------------------------------------------------------------
|
|
417
515
|
// Debugging
|
|
418
516
|
//---------------------------------------------------------------------------
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* A debugging decorator used to inspect a type.
|
|
520
|
+
* @param text Custom text to log
|
|
521
|
+
*/
|
|
419
522
|
extern dec inspectType(target: unknown, text: string);
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* A debugging decorator used to inspect a type name.
|
|
526
|
+
* @param text Custom text to log
|
|
527
|
+
*/
|
|
420
528
|
extern dec inspectTypeName(target: unknown, text: string);
|
package/lib/lib.tsp
CHANGED
|
@@ -117,45 +117,69 @@ model object {}
|
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
119
|
* Array model type, equivalent to `T[]`
|
|
120
|
+
* @template T The type of the array elements
|
|
120
121
|
*/
|
|
121
122
|
@indexer(integer, T)
|
|
122
123
|
model Array<T> {}
|
|
123
124
|
|
|
124
125
|
/**
|
|
125
126
|
* Model with string properties where all the properties have type `T`
|
|
127
|
+
* @template T The type of the properties
|
|
126
128
|
*/
|
|
127
129
|
@indexer(string, T)
|
|
128
130
|
model Record<T> {}
|
|
129
131
|
|
|
130
132
|
/**
|
|
131
|
-
* Represent a
|
|
133
|
+
* Represent a URL string as described by https://url.spec.whatwg.org/
|
|
132
134
|
*/
|
|
133
135
|
@format("url")
|
|
134
136
|
scalar url extends string;
|
|
135
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Represents a collection of optional properties.
|
|
140
|
+
* @template T An object whose spread properties are all optional.
|
|
141
|
+
*/
|
|
136
142
|
@doc("The template for adding optional properties.")
|
|
137
143
|
@withOptionalProperties
|
|
138
144
|
model OptionalProperties<T> {
|
|
139
145
|
...T;
|
|
140
146
|
}
|
|
141
147
|
|
|
148
|
+
/**
|
|
149
|
+
* Represents a collection of updateable properties.
|
|
150
|
+
* @template T An object whose spread properties are all updateable.
|
|
151
|
+
*/
|
|
142
152
|
@doc("The template for adding updateable properties.")
|
|
143
153
|
@withUpdateableProperties
|
|
144
154
|
model UpdateableProperties<T> {
|
|
145
155
|
...T;
|
|
146
156
|
}
|
|
147
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Represents a collection of omitted properties.
|
|
160
|
+
* @template T An object whose properties are spread.
|
|
161
|
+
* @template TKeys The property keys to omit.
|
|
162
|
+
*/
|
|
148
163
|
@doc("The template for omitting properties.")
|
|
149
164
|
@withoutOmittedProperties(TKeys)
|
|
150
165
|
model OmitProperties<T, TKeys extends string> {
|
|
151
166
|
...T;
|
|
152
167
|
}
|
|
153
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Represents a collection of properties with default values omitted.
|
|
171
|
+
* @template T An object whose spread property defaults are all omitted.
|
|
172
|
+
*/
|
|
154
173
|
@withoutDefaultValues
|
|
155
174
|
model OmitDefaults<T> {
|
|
156
175
|
...T;
|
|
157
176
|
}
|
|
158
177
|
|
|
178
|
+
/**
|
|
179
|
+
* Applies a visiblity setting to a collection of properties.
|
|
180
|
+
* @template T An object whose properties are spread.
|
|
181
|
+
* @template Visibility The visibility to apply to all properties.
|
|
182
|
+
*/
|
|
159
183
|
@doc("The template for setting the default visibility of key properties.")
|
|
160
184
|
@withDefaultKeyVisibility(Visibility)
|
|
161
185
|
model DefaultKeyVisibility<T, Visibility extends string> {
|
package/lib/reflection.tsp
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
namespace TypeSpec.Reflection;
|
|
2
2
|
|
|
3
|
-
model ModelProperty {}
|
|
4
|
-
model Interface {}
|
|
5
3
|
model Enum {}
|
|
6
4
|
model EnumMember {}
|
|
5
|
+
model Interface {}
|
|
6
|
+
model Model {}
|
|
7
|
+
model ModelProperty {}
|
|
7
8
|
model Namespace {}
|
|
8
9
|
model Operation {}
|
|
10
|
+
model Scalar {}
|
|
9
11
|
model Union {}
|
|
10
12
|
model UnionVariant {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/compiler",
|
|
3
|
-
"version": "0.44.0-dev.
|
|
3
|
+
"version": "0.44.0-dev.20",
|
|
4
4
|
"description": "TypeSpec Compiler Preview",
|
|
5
5
|
"author": "Microsoft Corporation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -56,48 +56,47 @@
|
|
|
56
56
|
"!dist/test/**"
|
|
57
57
|
],
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@babel/code-frame": "~7.
|
|
60
|
-
"ajv": "~8.
|
|
59
|
+
"@babel/code-frame": "~7.21.4",
|
|
60
|
+
"ajv": "~8.12.0",
|
|
61
61
|
"picocolors": "~1.0.0",
|
|
62
62
|
"globby": "~13.1.1",
|
|
63
63
|
"js-yaml": "~4.1.0",
|
|
64
|
-
"mkdirp": "~1.
|
|
64
|
+
"mkdirp": "~2.1.6",
|
|
65
65
|
"mustache": "~4.2.0",
|
|
66
|
-
"prettier": "~2.8.
|
|
66
|
+
"prettier": "~2.8.7",
|
|
67
67
|
"node-fetch": "3.2.8",
|
|
68
68
|
"prompts": "~2.4.1",
|
|
69
|
-
"vscode-languageserver": "~8.0
|
|
69
|
+
"vscode-languageserver": "~8.1.0",
|
|
70
70
|
"vscode-languageserver-textdocument": "~1.0.1",
|
|
71
|
-
"yargs": "~17.
|
|
71
|
+
"yargs": "~17.7.1",
|
|
72
72
|
"node-watch": "~0.7.1",
|
|
73
73
|
"change-case": "~4.1.2"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/babel__code-frame": "~7.0.3",
|
|
77
77
|
"@types/js-yaml": "~4.0.1",
|
|
78
|
-
"@types/mkdirp": "~1.0.1",
|
|
79
78
|
"@types/mocha": "~10.0.0",
|
|
80
79
|
"@types/mustache": "~4.2.1",
|
|
81
80
|
"@types/node": "~18.11.9",
|
|
82
81
|
"@types/prettier": "2.6.0",
|
|
83
|
-
"@types/prompts": "~2.4.
|
|
84
|
-
"@types/yargs": "~17.0.
|
|
82
|
+
"@types/prompts": "~2.4.3",
|
|
83
|
+
"@types/yargs": "~17.0.24",
|
|
85
84
|
"@typespec/eslint-config-typespec": ">=0.6.0",
|
|
86
85
|
"@typespec/internal-build-utils": ">=0.4.0",
|
|
87
|
-
"eslint": "^8.
|
|
86
|
+
"eslint": "^8.36.0",
|
|
88
87
|
"grammarkdown": "~3.2.0",
|
|
89
|
-
"mocha": "~10.
|
|
88
|
+
"mocha": "~10.2.0",
|
|
90
89
|
"mocha-junit-reporter": "~2.2.0",
|
|
91
90
|
"mocha-multi-reporters": "~1.5.1",
|
|
92
|
-
"c8": "~7.
|
|
91
|
+
"c8": "~7.13.0",
|
|
93
92
|
"prettier-plugin-organize-imports": "~3.2.0",
|
|
94
93
|
"source-map-support": "~0.5.19",
|
|
95
|
-
"rimraf": "~
|
|
94
|
+
"rimraf": "~5.0.0",
|
|
96
95
|
"tmlanguage-generator": ">=0.4.0",
|
|
97
|
-
"typescript": "~
|
|
98
|
-
"vscode-oniguruma": "~1.
|
|
99
|
-
"vscode-textmate": "~
|
|
100
|
-
"sinon": "~15.0.
|
|
96
|
+
"typescript": "~5.0.2",
|
|
97
|
+
"vscode-oniguruma": "~1.7.0",
|
|
98
|
+
"vscode-textmate": "~9.0.0",
|
|
99
|
+
"sinon": "~15.0.3",
|
|
101
100
|
"@types/sinon": "~10.0.13"
|
|
102
101
|
},
|
|
103
102
|
"peerDependencies": {},
|