@azure-tools/typespec-ts 0.53.1 → 0.53.2-alpha.20260522.1
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/CHANGELOG.md +6 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +6 -0
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +5 -0
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/emitSamples.js +21 -1
- package/dist/src/modular/emitSamples.js.map +1 -1
- package/dist/src/modular/helpers/exampleValueHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/exampleValueHelpers.js +21 -1
- package/dist/src/modular/helpers/exampleValueHelpers.js.map +1 -1
- package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
- package/dist/src/transform/transfromRLCOptions.js +3 -1
- package/dist/src/transform/transfromRLCOptions.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/index.ts +3 -1
- package/src/lib.ts +12 -0
- package/src/modular/emitSamples.ts +41 -9
- package/src/modular/helpers/exampleValueHelpers.ts +35 -8
- package/src/transform/transfromRLCOptions.ts +4 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure-tools/typespec-ts",
|
|
3
|
-
"version": "0.53.1",
|
|
3
|
+
"version": "0.53.2-alpha.20260522.1",
|
|
4
4
|
"description": "An experimental TypeSpec emitter for TypeScript RLC",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"@typespec/xml": "^0.82.0"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@azure-tools/rlc-common": "
|
|
76
|
+
"@azure-tools/rlc-common": "0.53.2-alpha.20260522.1",
|
|
77
77
|
"fast-xml-parser": "^4.5.0",
|
|
78
78
|
"fs-extra": "^11.1.0",
|
|
79
79
|
"lodash": "^4.17.21",
|
package/src/index.ts
CHANGED
|
@@ -572,7 +572,9 @@ export async function $onEmit(context: EmitContext) {
|
|
|
572
572
|
if (option.azureSdkForJs) {
|
|
573
573
|
commonBuilders.push(buildTsSrcEsmConfig);
|
|
574
574
|
commonBuilders.push(buildTsSrcBrowserConfig);
|
|
575
|
-
|
|
575
|
+
if (option.generateReactNativeTarget) {
|
|
576
|
+
commonBuilders.push(buildTsSrcReactNativeConfig);
|
|
577
|
+
}
|
|
576
578
|
commonBuilders.push(buildTsSrcCjsConfig);
|
|
577
579
|
if (option.generateSample) {
|
|
578
580
|
commonBuilders.push(buildTsSampleConfig);
|
package/src/lib.ts
CHANGED
|
@@ -108,6 +108,12 @@ export interface EmitterOptions {
|
|
|
108
108
|
* (Modular SDK only) Defaults to `false`.
|
|
109
109
|
*/
|
|
110
110
|
"treat-unknown-as-record"?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* When set to true, generates React Native build targets (tsconfig, warp target,
|
|
113
|
+
* package.json exports). Defaults to `false`.
|
|
114
|
+
* Only applicable when `azure-sdk-for-js` is `true`.
|
|
115
|
+
*/
|
|
116
|
+
"generate-react-native-target"?: boolean;
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
export const RLCOptionsSchema: JSONSchemaType<EmitterOptions> = {
|
|
@@ -416,6 +422,12 @@ export const RLCOptionsSchema: JSONSchemaType<EmitterOptions> = {
|
|
|
416
422
|
nullable: true,
|
|
417
423
|
description:
|
|
418
424
|
"When set to true, TypeSpec `unknown` type will be translated to `Record<string, unknown>` instead of `any` in the generated Modular SDK. This is useful when migrating from HLC where `unknown` in swagger mapped to `Record<string, unknown>`. (Modular SDK only) Defaults to `false`."
|
|
425
|
+
},
|
|
426
|
+
"generate-react-native-target": {
|
|
427
|
+
type: "boolean",
|
|
428
|
+
nullable: true,
|
|
429
|
+
description:
|
|
430
|
+
"When set to true, generates React Native build targets (tsconfig, warp target, package.json exports). Only applicable when azure-sdk-for-js is true. Defaults to `false`."
|
|
419
431
|
}
|
|
420
432
|
},
|
|
421
433
|
required: []
|
|
@@ -466,15 +466,47 @@ function prepareExampleParameters(
|
|
|
466
466
|
);
|
|
467
467
|
}
|
|
468
468
|
} else {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
469
|
+
// Check if the body parameter is nested inside a wrapper (e.g., @bodyRoot)
|
|
470
|
+
const segments = bodyParam.methodParameterSegments;
|
|
471
|
+
const isNestedBody =
|
|
472
|
+
segments.length === 1 &&
|
|
473
|
+
segments[0] !== undefined &&
|
|
474
|
+
segments[0].length > 1;
|
|
475
|
+
if (isNestedBody) {
|
|
476
|
+
const path = segments[0]!;
|
|
477
|
+
// The first segment is the method-level wrapper param (e.g., "body")
|
|
478
|
+
const methodParamName = path[0]!.name;
|
|
479
|
+
const methodParamOptional = path[0]!.optional;
|
|
480
|
+
// Wrap the example value with the intermediate property names
|
|
481
|
+
let wrappedValue = getParameterValue(dpgContext, bodyExample.value);
|
|
482
|
+
for (let i = path.length - 1; i >= 1; i--) {
|
|
483
|
+
const propName = normalizeName(
|
|
484
|
+
path[i]!.name,
|
|
485
|
+
NameType.Property,
|
|
486
|
+
true
|
|
487
|
+
);
|
|
488
|
+
wrappedValue = `{ ${propName}: ${wrappedValue} }`;
|
|
489
|
+
}
|
|
490
|
+
result.push(
|
|
491
|
+
prepareExampleValue(
|
|
492
|
+
dpgContext,
|
|
493
|
+
methodParamName,
|
|
494
|
+
wrappedValue,
|
|
495
|
+
methodParamOptional,
|
|
496
|
+
bodyParam.onClient
|
|
497
|
+
)
|
|
498
|
+
);
|
|
499
|
+
} else {
|
|
500
|
+
result.push(
|
|
501
|
+
prepareExampleValue(
|
|
502
|
+
dpgContext,
|
|
503
|
+
bodyParam.name,
|
|
504
|
+
bodyExample.value,
|
|
505
|
+
bodyParam.optional,
|
|
506
|
+
bodyParam.onClient
|
|
507
|
+
)
|
|
508
|
+
);
|
|
509
|
+
}
|
|
478
510
|
}
|
|
479
511
|
}
|
|
480
512
|
// optional parameters
|
|
@@ -494,14 +494,41 @@ export function prepareCommonParameters(
|
|
|
494
494
|
);
|
|
495
495
|
}
|
|
496
496
|
} else {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
497
|
+
// Check if the body parameter is nested inside a wrapper (e.g., @bodyRoot)
|
|
498
|
+
const segments = bodyParam.methodParameterSegments;
|
|
499
|
+
const isNestedBody =
|
|
500
|
+
segments.length === 1 &&
|
|
501
|
+
segments[0] !== undefined &&
|
|
502
|
+
segments[0].length > 1;
|
|
503
|
+
if (isNestedBody) {
|
|
504
|
+
const path = segments[0]!;
|
|
505
|
+
// The first segment is the method-level wrapper param (e.g., "body")
|
|
506
|
+
const methodParamName = path[0]!.name;
|
|
507
|
+
const methodParamOptional = path[0]!.optional;
|
|
508
|
+
// Wrap the example value with the intermediate property names
|
|
509
|
+
let wrappedValue = serializeExampleValue(bodyExample.value);
|
|
510
|
+
for (let i = path.length - 1; i >= 1; i--) {
|
|
511
|
+
const propName = normalizeName(path[i]!.name, NameType.Property);
|
|
512
|
+
wrappedValue = `{ ${propName}: ${wrappedValue} }`;
|
|
513
|
+
}
|
|
514
|
+
result.push(
|
|
515
|
+
prepareCommonValue(
|
|
516
|
+
methodParamName,
|
|
517
|
+
wrappedValue,
|
|
518
|
+
methodParamOptional,
|
|
519
|
+
bodyParam.onClient
|
|
520
|
+
)
|
|
521
|
+
);
|
|
522
|
+
} else {
|
|
523
|
+
result.push(
|
|
524
|
+
prepareCommonValue(
|
|
525
|
+
bodyParam.name,
|
|
526
|
+
bodyExample.value,
|
|
527
|
+
bodyParam.optional,
|
|
528
|
+
bodyParam.onClient
|
|
529
|
+
)
|
|
530
|
+
);
|
|
531
|
+
}
|
|
505
532
|
}
|
|
506
533
|
}
|
|
507
534
|
|
|
@@ -97,6 +97,8 @@ function extractRLCOptions(
|
|
|
97
97
|
emitterOptions["treat-unknown-as-record"] === true;
|
|
98
98
|
const headAsBoolean = emitterOptions["head-as-boolean"] === true;
|
|
99
99
|
const typespecTitleMap = emitterOptions["typespec-title-map"];
|
|
100
|
+
const generateReactNativeTarget =
|
|
101
|
+
emitterOptions["generate-react-native-target"] === true;
|
|
100
102
|
const hasSubscriptionId = getSubscriptionId(dpgContext);
|
|
101
103
|
const ignoreNullableOnOptional = getIgnoreNullableOnOptional(
|
|
102
104
|
emitterOptions,
|
|
@@ -143,7 +145,8 @@ function extractRLCOptions(
|
|
|
143
145
|
isMultiService,
|
|
144
146
|
enableStorageCompat,
|
|
145
147
|
treatUnknownAsRecord,
|
|
146
|
-
headAsBoolean
|
|
148
|
+
headAsBoolean,
|
|
149
|
+
generateReactNativeTarget
|
|
147
150
|
};
|
|
148
151
|
}
|
|
149
152
|
|