Transfer file to webworker: DataCloneError: The object could not be cloned - file

I want to transfer a file from a form to a webworker. In chrome i simple can use this code to transfer a FileList-Object:
worker.postMessage(files: array_files);
But with Firefox i get this error:
Transfer file to webworker: DataCloneError: The object could not be cloned.
So i tried to use the Syntax for transferable objects. Something like this?
var post = {files: array_files, file_ids: response.file_ids};
worker.postMessage(post, [post]);
But with that i get this in Chrome
Uncaught DataCloneError: Failed to execute 'postMessage' on 'Worker': Value at index 0 does not have a transferable type.
And still
DataCloneError: The object could not be cloned.
in Firefox.
What is the right way to pass a FileList to a worker?

I don't know how to pass File objects with postMessage, but at the least I can advise that transferable objects do not work in this way. The optional second parameter is an array of the backing ArrayBuffer instances of any typed arrays you wish to pass. So for instance, suppose the message you would like to post is a structured object:
var message = {foo: 'abc', bar: new Uint8Array(...)};
worker.postMessage(message, [message.bar.buffer])
Also notice that passing a typed array to another worker/window as a transferable object makes the transferred array inaccessible from the sending worker/window.

Related

Unable to access array within an array from Salesforce flow http callout (beta)

In sandbox, I am attempting to gather the information from https://data.nasdaq.com/api/v3/datasets/USTREASURY/YIELD.json
I used the beta feature of creating an HTTP callout right from the flow. It creates an external service based on the sample response you provide.
My problem is that within the JSON created, there is an array within an array; because the response is like
"data":[["2023-02-02","4.62","4.65","4.66","4.76","4.64","4.09","3.75","3.49","3.44","3.4","3.67","3.55"]],
When I access the response from the callout within the flow, the array column_names is available, but not the array data.
The JSON created is:
{"openapi":"3.0.1",
"info":{"title":"dataNasdaqGetRates"
,"description":""},
"paths":{"":{"get":{"description":"",
"operationId":"getRates",
"parameters":[{"name":"api_key","in":"query","required":true,"allowEmptyValue":false,
"schema":{"type":"string"}},
{"name":"order","in":"query","required":true,"allowEmptyValue":false,
"schema":{"type":"string"}},
{"name":"limit","in":"query","required":true,"allowEmptyValue":false,
"schema":{"type":"integer","format":"int32"}}],
"responses":{"2XX":{"description":"",
"content":{"application/json":{"schema":{"type":"object",
"properties":{"dataset":{"type":"object",
"properties":{"end_date":{"type":"string"},
"data":{"type":"array",
"items":{"type":"array",
"items":{"type":"string"}}},
"description":{"type":"string"},
"newest_available_date":{"type":"string"},
"type":{"type":"string"},
"dataset_code":{"type":"string"},
"column_index":{"type":"string"},
"frequency":{"type":"string"},
"oldest_available_date":{"type":"string"},
"transform":{"type":"string"},
"premium":{"type":"boolean"},
"refreshed_at":{"type":"string"},
"database_id":{"type":"integer",
"format":"int64"},
"database_code":{"type":"string"},
"name":{"type":"string"},
"limit":{"type":"integer","format":"int64"},
"id":{"type":"integer","format":"int64"},
"column_names":{"type":"array",
"items":{"type":"string"}},
"collapse":{"type":"string"},
"start_date":{"type":"string"},
"order":{"type":"string"}
}}}}}}}}}}}}
I've attempted to tweak the JSON to remove the nested array, hoping it might just work. I've attempted to add additional "type": to the nested array (technically the first item is a string and the rest are integers).
I was expecting there to be another apex-defined list called "data" listed after columnx5fnames; or even just a text collection or anything at all that I could add to a variable and access.
response items menu from flow

Calling push() on array, TypeError: Attempted to assign to readonly property

Working in React Native. I'm trying to declare an array and then push things to said array, but I'm getting the error TypeError: Attempted to assign to readonly property
CONTEXT:
The app prints via a thermal printer.
The print method receives an array of commands
Example:
print([{appendText: "blah"}, {
appendCutPaper: StarPRNT.CutPaperAction.PartialCutWithFeed,
}]
The print method is asynchronous and if you attempt to call the method again before the last call has finished, it errors.
Because of #2, we created a queue system that accepts a job (array of commands) and then works through the jobs synchronously.
In a React component, I'm attempting to create a job by declaring an empty array named printJob
and then pushing various commands to it. In this case, we take a snapshot of a View and then push the commands returned by the printImage method to the printJob array.
onClick={() => {
const printJob = []
viewShot.current
.capture()
.then((uri) => {
printJob.push(...printImage(uri))
})
.catch((err) => alert(err))
newPrintJob(printJob)
}
printImage returns the array of commands to print an image and cut the paper:
const CUT_PAPER = {
appendCutPaper: StarPRNT.CutPaperAction.PartialCutWithFeed,
}
export function printImage(uri) {
return [{ appendBitmap: uri }, CUT_PAPER]
}
So the goal is to generate the array of commands and pass that to the queue as a job. Now, I could just do newPrintJob(printImage(uri)) in the above case, which works completely fine. However, there is a particular setting the user can configure where it will need to print multiple images, one per ticket (in other words, multiple printImages). I want to consider all of that one job, hence the need to create the printJob array.
THE PROBLEM:
I'm getting an error TypeError: Attempted to assign to readonly property which seems to be triggered by printJob.push(...printImage(uri)). If I comment that line out, the error doesn't get thrown.
I don't understand why this would happen because you can call push on an array, even if it's declared as a constant. I also tried declaring it with var and let and still received the same error.
I hope I've provided enough context here. LMK if I need to add more.
Additional info:
"react": "16.13.1"
"react-native": "~0.63.3"
Turns out the issue was not pushing to the array. The issue was was trying to add the job to the queue:
newPrintJob(printJob)
...outside of the async's callback. Solution was to move the newPrintJob line into the .then block.

Use content of a tuple as variable session

I extracted from a previous response an Object of tuple with the following regex :
.check(regex(""""idSc":(.{1,8}),"pasTemps":."codePasTemps":(.),"""").ofType[(String,String)].findAll.saveAs ("OBJECTS1"))
So I get my object :
OBJECTS1 -> List((1657751,2), (1658105,2), (4557378,2), (1657750,1), (916,1), (917,2), (1658068,1), (1658069,2), (4557379,2), (1658082,1), (4557367,1), (4557368,1), (1660865,2), (1660866,2), (1658122,1), (921,1), (922,2), (923,2), (1660875,1), (1660876,2), (1660877,2), (1658300,1), (1658301,1), (1658302,1), (1658309,1), (1658310,1), (2996562,1), (4638455,1))
After that I did a Foreach and need to extract every couple to add them in next requests So we tried :
.foreach("${OBJECTS1}", "couple") {
exec(http("request_foreach47"
.get("/ctr/web/api/seriegraph/bydates/${couple(0)}/${couple(1)}/1552863600000/1554191743799")
.headers(headers_27))
}
But I get the message : named 'couple' does not support index access
I also though that to use 2 regex on the couple to extract both part could work but I haven't found any way to use a regex on a session variable. (Even if its not needed for this case but possible im really interessed to learn how as it could be usefull)
If would be really thankfull if you could provided me help. (Im using Gatling 2 but can,'t use a more recent version as its for work and others scripts have been develloped with Gatling2)
each "couple" is a scala tuple which can't be indexed into like a collection. Fortunately the gatling EL has a function that handles tuples.
so instead of
.get("/ctr/web/api/seriegraph/bydates/${couple(0)}/${couple(1)}/1552863600000/1554191743799")
you can use
.get("/ctr/web/api/seriegraph/bydates/${couple._1}/${couple._2}/1552863600000/1554191743799")

Jasmine - How to Write Test for Array with Named properties and Object

I ran into a strange situation today, thanks to Javascript. I have a Object that look something like this.
$scope.main = [{main : 1},service:true];
Now when I try to expect this inside the jasmine test case for equating the Objects :
expect($scope.main).toEqual([{main : 1},service:true]);
This gives me an error :
Unexpected Token.
Strangely, This is a valid object for Javascript. But Jasmine is not able to accept that.
Is there any way to test this?
Thanks in advance!
EDIT : Attaching a structure screenshot.
Update
I see now based on your screenshot that you are creating the main object in multiple steps. I've shortened it to the following:
var main = [{main: 1}];
main.service = true;
In dev-tools, you are seeing main as something that looks like this: [{main: 1}, service: true].
However, don't be mislead. Dev-tools is showing you a structure that is just meant to be informative. You can't actually create that structure in one line of javascript, because it is invalid. You have to create it in multiple steps, like you have.
This is why when you try to create it in your test in one line, you are getting an Unexpected Token. error. In your test, you have to create the expected object in a similar fashion to how you created your main object. For example:
var expected = [{main: 1}];
expected.service = true;
expect(main).toEqual(expected);

Configure Interception with Unity AutoConfig in VB.NET

I'm trying to get interception working in vb.net since my work only allows that. The way I would use it is to configure say some logger so that every business logic function that gets run is intercepted and logged to the database (bad idea, but its just an example). This is an example that I found:
container
.ConfigureAutoRegistration()
.Include(If.Implements<IBusinessService>, (x, y) =>
{
if (x.IsClass)
y.Configure<Interception>().
SetDefaultInterceptorFor(x,new VirtualMethodInterceptor());
})
This is what I tried to get working in vb.net, but it keeps throwing an error.
container.
ConfigureAutoRegistration().
Include([if].ImplementsITypeName, Function(x, y)
if x.IsClass
y.Configure(of Interception)()
.SetDefaultInterceptorFor(x,new VirtualMethodInterceptor())
End Function)
The error is:
Argument not specified for parameter 'type' of 'Public Shared Function ImplementsITypeName(type as System.Type) As Boolean.
Now obviously I need to specify some type, but the point is that I need to autoregister, so why do I need to provide a type? Also, the C# code doesn't require it, and neither does the code sample (see below).
var container = new UnityContainer();
container
.ConfigureAutoRegistration()
.ExcludeAssemblies(a => a.GetName().FullName.Contains("Test"))
.Include(If.Implements<ILogger>, Then.Register().UsingPerCallMode())
.Include(If.ImplementsITypeName, Then.Register().WithTypeName())
.Include(If.Implements<ICustomerRepository>, Then.Register().WithName("Sample"))
.Include(If.Implements<IOrderRepository>,
Then.Register().AsSingleInterfaceOfType().UsingPerCallMode())
.Include(If.DecoratedWith<LoggerAttribute>,
Then.Register()
.As<IDisposable>()
.WithTypeName()
.UsingLifetime<MyLifetimeManager>())
.Exclude(t => t.Name.Contains("Trace"))
.ApplyAutoRegistration();
http://autoregistration.codeplex.com/
I ended up using structure map.

Resources