@azure-tools/typespec-ts 0.54.0-dev.7 → 0.54.0-dev.8
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/src/index.d.ts.map +1 -1
- package/dist/src/index.js +23 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/rlc-common/buildObjectTypes.js +2 -2
- package/dist/src/rlc-common/buildObjectTypes.js.map +1 -1
- package/dist/src/rlc-common/buildParameterTypes.d.ts.map +1 -1
- package/dist/src/rlc-common/buildParameterTypes.js +21 -0
- package/dist/src/rlc-common/buildParameterTypes.js.map +1 -1
- package/dist/src/rlc-common/buildSchemaType.d.ts.map +1 -1
- package/dist/src/rlc-common/buildSchemaType.js +22 -0
- package/dist/src/rlc-common/buildSchemaType.js.map +1 -1
- package/dist/src/utils/modelUtils.d.ts +3 -3
- package/dist/src/utils/modelUtils.d.ts.map +1 -1
- package/dist/src/utils/modelUtils.js +1 -1
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/index.ts +28 -0
- package/src/rlc-common/buildObjectTypes.ts +2 -2
- package/src/rlc-common/buildParameterTypes.ts +24 -0
- package/src/rlc-common/buildSchemaType.ts +25 -0
- package/src/utils/modelUtils.ts +1 -1
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -298,6 +298,34 @@ export async function $onEmit(context: EmitContext) {
|
|
|
298
298
|
dpgContext.generationPathDetail?.metadataDir,
|
|
299
299
|
);
|
|
300
300
|
}
|
|
301
|
+
// The binder is only resolved in the modular path, so static helper files
|
|
302
|
+
// loaded into the outputProject are never written to disk in the RLC path.
|
|
303
|
+
// The RLC builders reference the platform-types helper (NodeReadableStream),
|
|
304
|
+
// so emit those files here.
|
|
305
|
+
await emitRLCStaticHelpers();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async function emitRLCStaticHelpers() {
|
|
309
|
+
if (program.compilerOptions.noEmit || program.hasError() || !rlcCodeModels[0]) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const project = useContext("outputProject");
|
|
313
|
+
for (const helperFile of project.getSourceFiles()) {
|
|
314
|
+
const filePath = helperFile.getFilePath();
|
|
315
|
+
// RLC builders (buildParameterTypes / buildSchemaType) only reference
|
|
316
|
+
// platform-types (and its browser/react-native variants); emit those
|
|
317
|
+
// files directly under src/ (strip the static-helpers/ segment) to match
|
|
318
|
+
// the RLC design where all generated output lives in src/.
|
|
319
|
+
if (!basename(filePath).startsWith("platform-types")) {
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
const outputPath = filePath.replace(/\/static-helpers\//g, "/");
|
|
323
|
+
await emitContentByBuilder(
|
|
324
|
+
program,
|
|
325
|
+
() => ({ content: helperFile.getFullText(), path: outputPath }),
|
|
326
|
+
rlcCodeModels[0],
|
|
327
|
+
);
|
|
328
|
+
}
|
|
301
329
|
}
|
|
302
330
|
|
|
303
331
|
async function generateModularSources() {
|
|
@@ -527,8 +527,8 @@ function getPropertySignatures(
|
|
|
527
527
|
function isBinaryArray(schema: Schema): boolean {
|
|
528
528
|
return Boolean(
|
|
529
529
|
isArraySchema(schema) &&
|
|
530
|
-
(schema.items?.typeName?.includes("
|
|
531
|
-
schema.items?.outputTypeName?.includes("
|
|
530
|
+
(schema.items?.typeName?.includes("NodeReadableStream") ||
|
|
531
|
+
schema.items?.outputTypeName?.includes("NodeReadableStream")),
|
|
532
532
|
);
|
|
533
533
|
}
|
|
534
534
|
|
|
@@ -169,6 +169,30 @@ export function buildParameterTypes(model: RLCModel) {
|
|
|
169
169
|
},
|
|
170
170
|
]);
|
|
171
171
|
}
|
|
172
|
+
// Add NodeReadableStream import if binary types are used in parameters.
|
|
173
|
+
// platform-types.ts is generated directly under src/ (no static-helpers/
|
|
174
|
+
// subdirectory) to match the RLC design where all output lives in src/.
|
|
175
|
+
// The platform-types static helper resolves NodeReadableStream to
|
|
176
|
+
// NodeJS.ReadableStream on Node and `never` on browser/react-native, so the
|
|
177
|
+
// union arm drops out naturally in non-Node builds.
|
|
178
|
+
if (parametersFile.getFullText().includes("NodeReadableStream")) {
|
|
179
|
+
const platformTypesModuleSpecifier = model.options?.azureSdkForJs
|
|
180
|
+
? "#platform/platform-types"
|
|
181
|
+
: getImportModuleName(
|
|
182
|
+
{
|
|
183
|
+
cjsName: `./platform-types`,
|
|
184
|
+
esModulesName: `./platform-types.js`,
|
|
185
|
+
},
|
|
186
|
+
model,
|
|
187
|
+
);
|
|
188
|
+
parametersFile.addImportDeclarations([
|
|
189
|
+
{
|
|
190
|
+
isTypeOnly: true,
|
|
191
|
+
namedImports: ["NodeReadableStream"],
|
|
192
|
+
moduleSpecifier: platformTypesModuleSpecifier,
|
|
193
|
+
},
|
|
194
|
+
]);
|
|
195
|
+
}
|
|
172
196
|
return { path: filePath, content: parametersFile.getFullText() };
|
|
173
197
|
}
|
|
174
198
|
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
buildPolymorphicAliases,
|
|
10
10
|
} from "./buildObjectTypes.js";
|
|
11
11
|
import { getImportSpecifier } from "./helpers/importsUtil.js";
|
|
12
|
+
import { getImportModuleName } from "./helpers/nameConstructors.js";
|
|
12
13
|
import { RLCModel, SchemaContext } from "./interfaces.js";
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -58,6 +59,30 @@ export function generateModelFiles(
|
|
|
58
59
|
},
|
|
59
60
|
]);
|
|
60
61
|
}
|
|
62
|
+
// Add NodeReadableStream import if binary types are used in models.
|
|
63
|
+
// platform-types.ts is generated directly under src/ (no static-helpers/
|
|
64
|
+
// subdirectory) to match the RLC design where all output lives in src/.
|
|
65
|
+
// The platform-types static helper resolves NodeReadableStream to
|
|
66
|
+
// NodeJS.ReadableStream on Node and `never` on browser/react-native, so the
|
|
67
|
+
// union arm drops out naturally in non-Node builds.
|
|
68
|
+
if (modelsFile.getFullText().includes("NodeReadableStream")) {
|
|
69
|
+
const platformTypesModuleSpecifier = model.options?.azureSdkForJs
|
|
70
|
+
? "#platform/platform-types"
|
|
71
|
+
: getImportModuleName(
|
|
72
|
+
{
|
|
73
|
+
cjsName: `./platform-types`,
|
|
74
|
+
esModulesName: `./platform-types.js`,
|
|
75
|
+
},
|
|
76
|
+
model,
|
|
77
|
+
);
|
|
78
|
+
modelsFile.addImportDeclarations([
|
|
79
|
+
{
|
|
80
|
+
isTypeOnly: true,
|
|
81
|
+
namedImports: ["NodeReadableStream"],
|
|
82
|
+
moduleSpecifier: platformTypesModuleSpecifier,
|
|
83
|
+
},
|
|
84
|
+
]);
|
|
85
|
+
}
|
|
61
86
|
return { path: filePath, content: modelsFile.getFullText() };
|
|
62
87
|
}
|
|
63
88
|
return undefined;
|
package/src/utils/modelUtils.ts
CHANGED
|
@@ -81,7 +81,7 @@ import { reportDiagnostic } from "../lib.js";
|
|
|
81
81
|
import { getModelNamespaceName } from "./namespaceUtils.js";
|
|
82
82
|
|
|
83
83
|
export const BINARY_TYPE_UNION =
|
|
84
|
-
"string | Uint8Array | ReadableStream<Uint8Array> |
|
|
84
|
+
"string | Uint8Array | ReadableStream<Uint8Array> | NodeReadableStream";
|
|
85
85
|
|
|
86
86
|
export const BINARY_AND_FILE_TYPE_UNION = `${BINARY_TYPE_UNION} | File`;
|
|
87
87
|
|