complete object in .save() ParseSwift response - parse-platform

Is there a way how to control what fields are returned (or to return the complete object state) in the Parse server response when calling save in ParseSwift SDK?
When I use following function:
var prsUser = PrsUser()
prsUser.setData(from: user, syncData: syncData)
print("prsUser before save: \(prsUser)")
prsUser.save { result in
switch result {
case .success(let user):
print("prsUser saved: \(String(describing: user))")
success(true)
case .failure(let error):
print("Error saving: \(error)")
success(false)
}
}
I can see in console the print statement before save and as a response of the save:
prsUser before save: _User
({"createdAt":{"__type":"Date","iso":"2021-05-07T17:54:59.267Z"},"maxD":61,"objectId":"cLAdfV25wz"})
prsUser saved: _User
({"objectId":"cLAdfV25wz","updatedAt":{"__type":"Date","iso":"2021-05-08T13:57:35.950Z"},"maxD":61,"createdAt":{"__type":"Date","iso":"2021-05-07T17:54:59.267Z"}})
but in this simple case I have a two little issues:
in the cloud code I try to revert the value for certain fields and in this case the maxD was reverted in beforeSave trigger, as I can also confirm it being unchanged in the Parse Dashboard
request.object.set("maxD", request.original.get("maxD"));
there are other fields in the prsUser objects the were not modified, but I would expect them to show up in the response. In the Parse Dashboard console I can see in the log following:
Input:
{"email":"aa#aa.aa","username":"aa#aa.aa","emailVerified":false,"createdAt":"2021-05-07T17:54:59.267Z","updatedAt":"2021-05-08T13:57:35.950Z","gch":1,"minA":25,"sof":true,"maxD":87,"maxA":36,"updates":{"gch":"2021-05-7T12:00:00.000Z","minA":"2021-05-7T12:00:00.000Z","maxA":"2021-05-7T12:00:00.000Z"},"ACL":{"cLAdfV25wz":{"read":true,"write":true}},"objectId":"cLAdfV25wz"}
Result: {"object":{"maxD":87}}
When I log more info before and after the revert with the following code, I can clearly see the the only dirtyKey is maxD and also that it is being reverted from requested value back to original (in this case 87):
const dirtyKeys = request.object.dirtyKeys();
request.log.info(`request.object before revert ${JSON.stringify(request.object)}, dirtyKeys: ${dirtyKeys}`);
request.object.set("maxD", request.original.get("maxD"));
request.log.info(`request.object after revert ${JSON.stringify(request.object)}`);
But then I am confused again, why do I receive the response as above with saved value of 61.
Therefore my questions would be:
is there a way how to get the actual object state with all fields in the response? It seems that the Parse Server does read the object from database before updating and saving values and therefore could theoretically send back the whole object.
or do I understand it wrong and the Parse Server is not passing back more than "success" mark? With that case there would not be any way how to tell, what values were actually saved without extra fetch call?

Related

Powerautomate Parsing JSON Array

I've seen the JSON array questions here and I'm still a little lost, so could use some extra help.
Here's the setup:
My Flow calls a sproc on my DB and that sproc returns this JSON:
{
"ResultSets": {
"Table1": [
{
"OrderID": 9518338,
"BasketID": 9518338,
"RefID": 65178176,
"SiteConfigID": 237
}
]
},
"OutputParameters": {}
}
Then I use a PARSE JSON action to get what looks like the same result, but now I'm told it's parsed and I can call variables.
Issue is when I try to call just, say, SiteConfigID, I get "The output you selected is inside a collection and needs to be looped over to be accessed. This action cannot be inside a foreach."
After some research, I know what's going on here. Table1 is an Array, and I need to tell PowerAutomate to just grab the first record of that array so it knows it's working with just a record instead of a full array. Fair enough. So I spin up a "Return Values to Virtual Power Agents" action just to see my output. I know I'm supposed to use a 'first' expression or a 'get [0] from array expression here, but I can't seem to make them work. Below are what I've tried and the errors I get:
Tried:
first(body('Parse-Sproc')?['Table1/SiteConfigID'])
Got: InvalidTemplate. Unable to process template language expressions in action 'Return_value(s)_to_Power_Virtual_Agents' inputs at line '0' and column '0': 'The template language function 'first' expects its parameter be an array or a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#first for usage details.'.
Also Tried:
body('Parse-Sproc')?['Table1/SiteconfigID']
which just returns a null valued variable
Finally I tried
outputs('Parse-Sproc')?['Table1']?['value'][0]?['SiteConfigID']
Which STILL gives me a null-valued variable. It's the worst.
In that last expression, I also switched the variable type in the return to pva action to a string instead of a number, no dice.
Also, changed 'outputs' in that expression for 'body' .. also no dice
Here is a screenie of the setup:
To be clear: the end result i'm looking for is for the system to just return "SiteConfigID" as a string or an int so that I can pipe that into a virtual agent.
I believe this is what you need as an expression ...
body('Parse-Sproc')?['ResultSets']['Table1'][0]?['SiteConfigID']
You can see I'm just traversing down to the object and through the array to get the value.
Naturally, I don't have your exact flow but if I use your JSON and load it up into Parse JSON step to get the schema, I am able to get the result. I do get a different schema to you though so will be interesting to see if it directly translates.

go properly handling slices and strings

I am using goRequest http://parnurzeal.github.io/gorequest/ to make some HTTP requests against a server process I need to talk to. The authentication process works like this;
send in a GET request with an authentication header set. No problem there, but I need to grab a header from the response and use a returned value to reauthenticate each following request.
The retuned HTTP header looks like this.
Response headers
map[Location:[900767244] Content-Type:[application/xml] Date:[Fri, 18 Sep 2015 18:19:41 GMT] Server:[Apache] X-Frame-Options:[SAMEORIGIN] Set-Cookie:[JSESSIONID=D5C976F5646365FF030DBAD770DA774C; Path=/; Secure; HttpOnly]]
I need to get that location value as it's my session token going forward. If I grap it like this:
session, ok := response.Header["Location"]
if !ok {
fmt.Println("Did not receive a location header.")
}
fmt.Println("Session: ", session)
I can get it, but it's a slice and NOT a string. How can I get that value as a string so I can pop it back into my request headers going forward? As you can see in the following error:
./login.go:133: cannot use session (type []string) as type string in argument to logoutRequest.Delete
Thanks a lot!
Craig
If you want one value, use the Header's Get method
location := response.Header.Get("Location")
This also canonicalizes the header name for you, so that you still get a value even when using slightly different capitalization.
You only need to index an http.Header value directly when you need to get more than than the first possible value. If you want all values with a canonicalized header name, you can use textproto.CanonicalMIMEHeaderKey
vals := response.Header[textproto.CanonicalMIMEHeaderKey(header)]
The headers have location as an array, you just need to pass Location[0] to that method rather than simply Location because it is a slice. That being said, indexing into the array without checking the bounds is unsafe so you should probably do;
if len(Location) == 1 {
logoutRequest(Location[0])
} else {
// error state
}
One last thing to provide you guidance in the future. You can tell that the response headers object has a type more like this; map[string][]string (in reality that maybe []interface{} but I'm not certain from the output) by seeing that each item inside the outer brackets [] has it's values contained within another set of brackets, meaning it is an array that could contain 0 or more values.

how to send regex to server side in meteor

In my application, I'm building a query object some thing like below
Object {pointType: /analog/i, _id: Object}
I tried to store it in session variable,
Session.set("currentPointsQueryObject",queryObj);
Then on click event I'm getting this object
var res= Session.get("currentPointsQueryObject");
console.log(res);
but here I'm getting like below
Object {pointType: Object, _id: Object}
Meanwhile, I sent group_id to the server
by geting it from session variable like
var group_id=Session.get("currentGroupId");
which is working fine(it is displaying id in server log)
Then, I've tried storing it in global variable, which returning as expected
like below on click event
Object {pointType: /analog/i, _id: Object}
but when I sent it to server side method (Immediate line after console.log() )
Meteor.call("updateGroupPoints",res,function(err,data){
console.log("updated points");
console.log(data);
});
when I log res in server console, it is showing
{ pointType: {}, _id: { '$nin': [] } }
Althoug I have something in pointType, It is not passed to the server.
Anyone had idea, Is this the thing related storing?
You cannot directly serialize RegExp to EJSON, but you can:
var regexp = /^[0-9]+$/;
var serialized = regexp.source;
Send serialized and then deserialize:
new RegExp(serialized)
Take a look at : Meteor: Save RegExp Object to Session
/analog/i is a regular expression, right? Values stored in Session and values sent to methods must be part of EJSON values. Regular expression aren't.
There's a handy way to teach EJSON how to serialize/parse Regular Expressions (RegExp) as of 2015 documented in this SO question:
How to extend EJSON to serialize RegEx for Meteor Client-Server interactions?
Basically, we can extend the RegExp object class and use EJSON.addType to teach the serialization to both client and server. Hope this helps someone out there in the Universe. :)
Simply stringify your RegExp via .toString(), send it to the server and then parse it back to RegExp.

web audio filter response

I have a simple filter.
var filter = ctx.createBiquadFilter();
filter.type = 'highpass';
filter.frequency.setValueAtTime(10,ctx.currentTime);
I would like to see its frequency response using getFrequencyResponse
window.setInterval(function() {
var frequencyHz = new Float32Array(1),
magResponse = new Float32Array(1),
phaseResponse = new Float32Array(1);
frequencyHz[0] = 10;
filter.getFrequencyResponse(frequencyHz,magResponse,phaseResponse);
console.log(magResponse);
},100);
I expect to see [0.9565200805664062] which is the correct response for 10Hz, but instead I see [0.0008162903832271695] which is the response for 350Hz, the default frequency value.
I can only get a sensible response if I manually set the value, whereas if I use param methods such as setValueAtTime, the filter response ignores them and spits out the default. In other words, getFrequencyResponse seems to only work if the filter values are set manually, preventing filter analysis when the values are set by automation. If this is true, this seems like more than a small problem with the api.
Someone please try something near to this, and if it works (doubtful) please post the code.
Actually, no, it should be taking effect, but because you're causing an instantaneous value change at the NEXT processing block (that's what ".currentTime" means), that change has not yet been processed - so you're seeing the default value. You should see, for example, getFrequencyResponse changes over time for a setLinearRamp.

Filter Too Quickly issue

In ExtJS 4.1.3 we have a filter setup on a text field to run 'onchange' of the text field. This is the function onchange:
var store = this.getStore();
value = field.getValue();
if (value.length > 0) {
// Param name is ignored here since we use custom encoding in the proxy.
// id is used by the Store to replace any previous filter
store.filter({
id: 'query',
property: 'query',
value: 'LegalName|#|#|' + value
});
} else {
store.clearFilter();
}
Now, we are running into an issue where when I type something in the text field too fast I am getting errors and am getting stuck on a load screen. When I type in the same thing slowly it works. Considering typing it in slowly makes it work, but fast makes it fail and the data coming back from the server is the same in both instances, I'm assuming it's an issue with ExtJS. Has anyone seen an issue like this? What are potential problems and fixes. I can't figure out why it's breaking. Here is the trail I get:
Uncaught TypeError: Cannot convert null to object ext-all-debug.js:51752
Ext.define.cancelAllPrefetches ext-all-debug.js:51752
Ext.util.Event.Ext.extend.fire ext-all-debug.js:8638
Ext.define.continueFireEvent ext-all-debug.js:25117
Ext.define.fireEvent ext-all-debug.js:25095
Ext.define.clear ext-all-debug.js:44718
Base.implement.callParent ext-all-debug.js:3735
Ext.define.clear ext-all-debug.js:47485
Base.implement.callParent ext-all-debug.js:3735
PageMap.Ext.Class.clear ext-all-debug.js:52358
Ext.define.filter ext-all-debug.js:51377
Ext.define.onTextfieldChange /TEST/app/view/ContractGrid.js?_dc=1354553533935:447
Ext.util.Event.Ext.extend.fire ext-all-debug.js:8638
Ext.define.continueFireEvent ext-all-debug.js:25117
Ext.define.fireEvent ext-all-debug.js:25095
Ext.override.fireEvent ext-all-debug.js:58382
Ext.define.checkChange ext-all-debug.js:30310
call ext-all-debug.js:8426
Any thoughts?
I was able to fix the issue by changing the buffer setting on the store. Looks like I had set 'buffered' to true in the store and once I removed it, the issue went away.

Resources