Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,21 @@
"./package.json": "./package.json",
".": "./src/index.ts",
"./api": "./src/api/index.ts",
"./api/budgets": "./src/api/budgets/index.ts",
"./api/sapWidgets": "./src/api/sapWidgets/index.ts",
"./api/budgets": "src/api/budgets/index.ts",
"./api/sapWidgets": "src/api/sapWidgets/index.ts",
"./models": "./src/models/index.ts"
},
"dialects": [
"esm",
"commonjs"
],
"esmDialects": [
"browser",
"react-native"
],
"dialects": ["esm", "commonjs"],
"esmDialects": ["browser", "react-native"],
"selfLink": false
},
"type": "module",
"browser": "./dist/browser/index.js",
"react-native": "./dist/react-native/index.js",
"keywords": [
"node",
"azure",
"cloud",
"typescript",
"browser",
"isomorphic"
],
"keywords": ["node", "azure", "cloud", "typescript", "browser", "isomorphic"],
"author": "Microsoft Corporation",
"license": "MIT",
"files": [
"dist/",
"!dist/**/*.d.*ts.map",
"README.md",
"LICENSE"
],
"files": ["dist/", "!dist/**/*.d.*ts.map", "README.md", "LICENSE"],
"dependencies": {
"@azure/core-util": "^1.9.2",
"@azure-rest/core-client": "^2.3.1",
Expand Down Expand Up @@ -72,101 +54,5 @@
"lint": "eslint package.json api-extractor.json src",
"lint:fix": "eslint package.json api-extractor.json src --fix --fix-type [problem,suggestion]",
"build": "npm run clean && tshy && npm run extract-api"
},
"exports": {
"./package.json": "./package.json",
".": {
"browser": {
"types": "./dist/browser/index.d.ts",
"default": "./dist/browser/index.js"
},
"react-native": {
"types": "./dist/react-native/index.d.ts",
"default": "./dist/react-native/index.js"
},
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
},
"./api": {
"browser": {
"types": "./dist/browser/api/index.d.ts",
"default": "./dist/browser/api/index.js"
},
"react-native": {
"types": "./dist/react-native/api/index.d.ts",
"default": "./dist/react-native/api/index.js"
},
"import": {
"types": "./dist/esm/api/index.d.ts",
"default": "./dist/esm/api/index.js"
},
"require": {
"types": "./dist/commonjs/api/index.d.ts",
"default": "./dist/commonjs/api/index.js"
}
},
"./api/budgets": {
"browser": {
"types": "./dist/browser/api/budgets/index.d.ts",
"default": "./dist/browser/api/budgets/index.js"
},
"react-native": {
"types": "./dist/react-native/api/budgets/index.d.ts",
"default": "./dist/react-native/api/budgets/index.js"
},
"import": {
"types": "./dist/esm/api/budgets/index.d.ts",
"default": "./dist/esm/api/budgets/index.js"
},
"require": {
"types": "./dist/commonjs/api/budgets/index.d.ts",
"default": "./dist/commonjs/api/budgets/index.js"
}
},
"./api/sapWidgets": {
"browser": {
"types": "./dist/browser/api/sapWidgets/index.d.ts",
"default": "./dist/browser/api/sapWidgets/index.js"
},
"react-native": {
"types": "./dist/react-native/api/sapWidgets/index.d.ts",
"default": "./dist/react-native/api/sapWidgets/index.js"
},
"import": {
"types": "./dist/esm/api/sapWidgets/index.d.ts",
"default": "./dist/esm/api/sapWidgets/index.js"
},
"require": {
"types": "./dist/commonjs/api/sapWidgets/index.d.ts",
"default": "./dist/commonjs/api/sapWidgets/index.js"
}
},
"./models": {
"browser": {
"types": "./dist/browser/models/index.d.ts",
"default": "./dist/browser/models/index.js"
},
"react-native": {
"types": "./dist/react-native/models/index.d.ts",
"default": "./dist/react-native/models/index.js"
},
"import": {
"types": "./dist/esm/models/index.d.ts",
"default": "./dist/esm/models/index.js"
},
"require": {
"types": "./dist/commonjs/models/index.d.ts",
"default": "./dist/commonjs/models/index.js"
}
}
},
"main": "./dist/commonjs/index.js",
"types": "./dist/commonjs/index.d.ts",
"module": "./dist/esm/index.js"
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
16 changes: 13 additions & 3 deletions packages/typespec-ts/src/modular/helpers/operationHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,24 @@ export function getDeserializePrivateFunction(
} else if (isAzureCoreErrorType(context.program, deserializedType.__raw)) {
statements.push(`return ${deserializedRoot}`);
} else {
// Determine if the response contains binary payload
// Use __raw if it exists and is a Type, otherwise fall back to the type itself
const rawType = (response.type as any)?.__raw;
const responseType =
rawType && typeof rawType === "object" && "kind" in rawType
? rawType
: response.type;
const isBinary =
responseType && contentTypes
? isBinaryPayload(context, responseType as any, contentTypes)
: false;

statements.push(
`return ${deserializeResponseValue(
context,
deserializedType,
deserializedRoot,
isBinaryPayload(context, response.type!.__raw!, contentTypes!)
? "binary"
: getEncodeForType(deserializedType)
isBinary ? "binary" : getEncodeForType(deserializedType)
)}`
);
}
Expand Down
8 changes: 6 additions & 2 deletions packages/typespec-ts/src/utils/modelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,23 @@ export function getBinaryType(usage: SchemaContext[]) {
}

export function isByteOrByteUnion(dpgContext: SdkContext, type: Type) {
if (!type) {
return false;
}
const schema = getSchemaForType(dpgContext, type);
return isBytesType(schema) || isBytesUnion(schema);
}

function isBytesType(schema: any) {
return (
schema &&
schema.type === "string" &&
(schema.format === "bytes" || schema.format === "binary")
);
}

function isBytesUnion(schema: any) {
if (!Array.isArray(schema.enum)) {
if (!schema || !Array.isArray(schema.enum)) {
return false;
}
for (const ele of schema.enum) {
Expand Down Expand Up @@ -289,7 +293,7 @@ export function getEffectiveModelFromType(
* If type is an anonymous model, tries to find a named model that has the same
* set of properties when non-schema properties are excluded.
*/
if (type.kind === "Model" && type.name === "") {
if (type && type.kind === "Model" && type.name === "") {
const effective = getEffectiveModelType(context.program, type, (property) =>
isSchemaProperty(context.program, property)
);
Expand Down
Loading
Loading