@microsoft/dotnet-js-interop
Advanced tools
Comparing version 6.0.2 to 7.0.0-preview.1.22109.13
@@ -156,7 +156,7 @@ export declare module DotNet { | ||
/** | ||
* Supplies a stream of data being sent from .NET. | ||
* | ||
* @param streamId The identifier previously passed to JSRuntime's BeginTransmittingStream in .NET code | ||
* @param stream The stream data. | ||
*/ | ||
* Supplies a stream of data being sent from .NET. | ||
* | ||
* @param streamId The identifier previously passed to JSRuntime's BeginTransmittingStream in .NET code | ||
* @param stream The stream data. | ||
*/ | ||
supplyDotNetStream: (streamId: number, stream: ReadableStream) => void; | ||
@@ -163,0 +163,0 @@ }; |
@@ -0,1 +1,3 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// This is a single-file self-contained module to avoid the need for a Webpack build | ||
@@ -9,7 +11,8 @@ export var DotNet; | ||
const jsObjectIdKey = "__jsObjectId"; | ||
const dotNetObjectRefKey = '__dotNetObject'; | ||
const byteArrayRefKey = '__byte[]'; | ||
const dotNetStreamRefKey = '__dotNetStream'; | ||
const dotNetObjectRefKey = "__dotNetObject"; | ||
const byteArrayRefKey = "__byte[]"; | ||
const dotNetStreamRefKey = "__dotNetStream"; | ||
const jsStreamReferenceLengthKey = "__jsStreamReferenceLength"; | ||
class JSObject { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
constructor(_jsObject) { | ||
@@ -26,3 +29,3 @@ this._jsObject = _jsObject; | ||
let lastSegmentValue; | ||
identifier.split('.').forEach(segment => { | ||
identifier.split(".").forEach(segment => { | ||
if (segment in result) { | ||
@@ -41,5 +44,3 @@ lastSegmentValue = result; | ||
} | ||
else { | ||
throw new Error(`The value '${identifier}' is not a function.`); | ||
} | ||
throw new Error(`The value '${identifier}' is not a function.`); | ||
} | ||
@@ -53,9 +54,9 @@ getWrappedObject() { | ||
const cachedJSObjectsById = { | ||
[windowJSObjectId]: new JSObject(window), | ||
[windowJSObjectId]: new JSObject(window) | ||
}; | ||
cachedJSObjectsById[windowJSObjectId]._cachedFunctions.set('import', (url) => { | ||
cachedJSObjectsById[windowJSObjectId]._cachedFunctions.set("import", (url) => { | ||
// In most cases developers will want to resolve dynamic imports relative to the base HREF. | ||
// However since we're the one calling the import keyword, they would be resolved relative to | ||
// this framework bundle URL. Fix this by providing an absolute URL. | ||
if (typeof url === 'string' && url.startsWith('./')) { | ||
if (typeof url === "string" && url.startsWith("./")) { | ||
url = document.baseURI + url.substr(2); | ||
@@ -119,3 +120,3 @@ } | ||
function createJSObjectReference(jsObject) { | ||
if (jsObject && typeof jsObject === 'object') { | ||
if (jsObject && typeof jsObject === "object") { | ||
cachedJSObjectsById[nextJsObjectId] = new JSObject(jsObject); | ||
@@ -128,5 +129,3 @@ const result = { | ||
} | ||
else { | ||
throw new Error(`Cannot create a JSObjectReference from the value '${jsObject}'.`); | ||
} | ||
throw new Error(`Cannot create a JSObjectReference from the value '${jsObject}'.`); | ||
} | ||
@@ -158,6 +157,6 @@ DotNet.createJSObjectReference = createJSObjectReference; | ||
else { | ||
throw new Error('Supplied value is not a typed array or blob.'); | ||
throw new Error("Supplied value is not a typed array or blob."); | ||
} | ||
const result = { | ||
[jsStreamReferenceLengthKey]: length, | ||
[jsStreamReferenceLengthKey]: length | ||
}; | ||
@@ -181,3 +180,3 @@ try { | ||
const id = jsObjectReference && jsObjectReference[jsObjectIdKey]; | ||
if (typeof id === 'number') { | ||
if (typeof id === "number") { | ||
disposeJSObjectReferenceById(id); | ||
@@ -206,5 +205,3 @@ } | ||
} | ||
else { | ||
throw new Error('The current dispatcher does not support synchronous calls from JS to .NET. Use invokeMethodAsync instead.'); | ||
} | ||
throw new Error("The current dispatcher does not support synchronous calls from JS to .NET. Use invokeMethodAsync instead."); | ||
} | ||
@@ -233,3 +230,3 @@ function invokePossibleInstanceMethodAsync(assemblyName, methodIdentifier, dotNetObjectId, args) { | ||
} | ||
throw new Error('No .NET call dispatcher has been set.'); | ||
throw new Error("No .NET call dispatcher has been set."); | ||
} | ||
@@ -252,2 +249,3 @@ function completePendingCall(asyncCallId, success, resultOrError) { | ||
*/ | ||
// eslint-disable-next-line no-shadow | ||
let JSCallResultType; | ||
@@ -314,3 +312,11 @@ (function (JSCallResultType) { | ||
// Not using "await" because it codegens a lot of boilerplate | ||
promise.then(result => getRequiredDispatcher().endInvokeJSFromDotNet(asyncHandle, true, stringifyArgs([asyncHandle, true, createJSCallResult(result, resultType)])), error => getRequiredDispatcher().endInvokeJSFromDotNet(asyncHandle, false, JSON.stringify([asyncHandle, false, formatError(error)]))); | ||
promise.then(result => getRequiredDispatcher().endInvokeJSFromDotNet(asyncHandle, true, stringifyArgs([ | ||
asyncHandle, | ||
true, | ||
createJSCallResult(result, resultType) | ||
])), error => getRequiredDispatcher().endInvokeJSFromDotNet(asyncHandle, false, JSON.stringify([ | ||
asyncHandle, | ||
false, | ||
formatError(error) | ||
]))); | ||
} | ||
@@ -328,3 +334,3 @@ }, | ||
: new Error(resultJsonOrExceptionMessage); | ||
completePendingCall(parseInt(asyncCallId), success, resultOrError); | ||
completePendingCall(parseInt(asyncCallId, 10), success, resultOrError); | ||
}, | ||
@@ -340,7 +346,7 @@ /** | ||
/** | ||
* Supplies a stream of data being sent from .NET. | ||
* | ||
* @param streamId The identifier previously passed to JSRuntime's BeginTransmittingStream in .NET code | ||
* @param stream The stream data. | ||
*/ | ||
* Supplies a stream of data being sent from .NET. | ||
* | ||
* @param streamId The identifier previously passed to JSRuntime's BeginTransmittingStream in .NET code | ||
* @param stream The stream data. | ||
*/ | ||
supplyDotNetStream: (streamId, stream) => { | ||
@@ -359,3 +365,3 @@ if (pendingDotNetToJSStreams.has(streamId)) { | ||
} | ||
}, | ||
} | ||
}; | ||
@@ -366,14 +372,10 @@ function formatError(error) { | ||
} | ||
else { | ||
return error ? error.toString() : 'null'; | ||
} | ||
return error ? error.toString() : "null"; | ||
} | ||
function findJSFunction(identifier, targetInstanceId) { | ||
let targetInstance = cachedJSObjectsById[targetInstanceId]; | ||
const targetInstance = cachedJSObjectsById[targetInstanceId]; | ||
if (targetInstance) { | ||
return targetInstance.findFunction(identifier); | ||
} | ||
else { | ||
throw new Error(`JS object instance with ID ${targetInstanceId} does not exist (has it been disposed?).`); | ||
} | ||
throw new Error(`JS object instance with ID ${targetInstanceId} does not exist (has it been disposed?).`); | ||
} | ||
@@ -384,2 +386,3 @@ function disposeJSObjectReferenceById(id) { | ||
class DotNetObject { | ||
// eslint-disable-next-line no-empty-function | ||
constructor(_id) { | ||
@@ -395,3 +398,3 @@ this._id = _id; | ||
dispose() { | ||
const promise = invokePossibleInstanceMethodAsync(null, '__Dispose', this._id, null); | ||
const promise = invokePossibleInstanceMethodAsync(null, "__Dispose", this._id, null); | ||
promise.catch(error => console.error(error)); | ||
@@ -405,3 +408,3 @@ } | ||
attachReviver(function reviveReference(key, value) { | ||
if (value && typeof value === 'object') { | ||
if (value && typeof value === "object") { | ||
if (value.hasOwnProperty(dotNetObjectRefKey)) { | ||
@@ -416,5 +419,3 @@ return new DotNetObject(value[dotNetObjectRefKey]); | ||
} | ||
else { | ||
throw new Error(`JS object instance with Id '${id}' does not exist. It may have been disposed.`); | ||
} | ||
throw new Error(`JS object instance with Id '${id}' does not exist. It may have been disposed.`); | ||
} | ||
@@ -439,3 +440,2 @@ else if (value.hasOwnProperty(byteArrayRefKey)) { | ||
constructor(streamId) { | ||
var _a; | ||
// This constructor runs when we're JSON-deserializing some value from the .NET side. | ||
@@ -447,3 +447,3 @@ // At this point we might already have started receiving the stream, or maybe it will come later. | ||
// We've already started receiving the stream, so no longer need to track it as pending | ||
this._streamPromise = (_a = pendingDotNetToJSStreams.get(streamId)) === null || _a === void 0 ? void 0 : _a.streamPromise; | ||
this._streamPromise = pendingDotNetToJSStreams.get(streamId).streamPromise; | ||
pendingDotNetToJSStreams.delete(streamId); | ||
@@ -459,4 +459,4 @@ } | ||
/** | ||
* Supplies a readable stream of data being sent from .NET. | ||
*/ | ||
* Supplies a readable stream of data being sent from .NET. | ||
*/ | ||
stream() { | ||
@@ -466,5 +466,5 @@ return this._streamPromise; | ||
/** | ||
* Supplies a array buffer of data being sent from .NET. | ||
* Note there is a JavaScript limit on the size of the ArrayBuffer equal to approximately 2GB. | ||
*/ | ||
* Supplies a array buffer of data being sent from .NET. | ||
* Note there is a JavaScript limit on the size of the ArrayBuffer equal to approximately 2GB. | ||
*/ | ||
async arrayBuffer() { | ||
@@ -471,0 +471,0 @@ return new Response(await this.stream()).arrayBuffer(); |
{ | ||
"name": "@microsoft/dotnet-js-interop", | ||
"version": "6.0.2", | ||
"version": "7.0.0-preview.1.22109.13", | ||
"description": "Provides abstractions and features for interop between .NET and JavaScript code.", | ||
@@ -12,3 +12,3 @@ "main": "dist/Microsoft.JSInterop.js", | ||
"build": "npm run clean && npm run build:esm", | ||
"build:lint": "node node_modules/tslint/bin/tslint -p ./tsconfig.json", | ||
"build:lint": "eslint -c .eslintrc.json --ext .ts ./src", | ||
"build:esm": "node node_modules/typescript/bin/tsc --project ./tsconfig.json" | ||
@@ -30,6 +30,10 @@ }, | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^5.8.0", | ||
"@typescript-eslint/parser": "^5.8.0", | ||
"eslint": "^8.5.0", | ||
"eslint-plugin-jsdoc": "^37.4.0", | ||
"eslint-plugin-prefer-arrow": "^1.2.3", | ||
"rimraf": "^3.0.2", | ||
"tslint": "^6.1.3", | ||
"typescript": "^4.2.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46838
7
665
1