#1 2022-10-10 23:03:49

rdevine
Member
Registered: 2014-02-20
Posts: 52

TMS WebCore

I've uploaded some files for creating TMS WebCore/mORMot clients to:

https://github.com/SigmaSciences/mORMot-Web

It still needs a lot of testing and has missing functionality (I only use interface and method-based service from Web clients), but will hopefully be useful. I use mORMot 2 exclusively so haven't tested with v1. Pull requests welcome, though drop me an email (@gmail) with any suggestions (rlsdevine).

Cheers, Bob

Offline

#2 2022-10-11 09:55:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: TMS WebCore

Great work!

The remote ORM part is not needed for sure. It is not safe enough to be published directly.
Interface based services is the way to go, for any serious and efficient service.

The only missing feature is IMHO the template to generate the client code directly from the server.

One question: why use an external sha256.js ? has the mormot/pascal version any bug?

Offline

#3 2022-10-11 10:17:04

rdevine
Member
Registered: 2014-02-20
Posts: 52

Re: TMS WebCore

Thanks Arnaud :-)

>why use an external sha256.js

When I started I couldn't get the mormot version to work, and was also learning about using external JS libraries in WebCore. I eventually figured out that I was picking up the wrong sh0 so restored the mormot code. I left the JS option in as an example of using an external library, but the default is the mormot code.

I'll need to learn a bit about Mustache but will try and find some time for the template soon.

Cheers, Bob

Offline

#4 2022-10-11 11:12:12

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: TMS WebCore

My guess is that the SmartMobileStudio template is very close to what you need to write a WebCore template.

Thanks again!

Offline

#5 2024-03-11 15:06:32

ttomas
Member
Registered: 2013-03-08
Posts: 135

Re: TMS WebCore

Hi @rdevine
I create Pull request
-Some small changes to be Pas2JS compatible without TMS Web Core
-Calculator service add code export wrappers and add procedure with 2 var params for testing
-Pas2JS Template in Template folder. Generated code mORMotPas2JsClient.pas is used in Pas2JSTest without any change
http://localhost:888/root/wrapper
-Pas2JSTest Demo
-Async and Sync calls works
I tested only on FPC and Pas2JS, not in Delphi or TMS Web Core
My fork: https://github.com/TTomas/mORMot-Web

Last edited by ttomas (2024-03-11 15:07:19)

Offline

#6 2024-03-11 16:47:06

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: TMS WebCore

This is great!

Thanks a lot!

Offline

#7 2024-03-11 20:19:55

rdevine
Member
Registered: 2014-02-20
Posts: 52

Re: TMS WebCore

Thank you! I've been meaning to get back to it and, e.g., sort out templates but it's been working great for me as-is so it keeps slipping down the list :-) I should find some time later in the week to test with WebCore before merging - thanks again.

Cheers, Bob

Offline

#8 2024-03-17 14:42:14

ttomas
Member
Registered: 2013-03-08
Posts: 135

Re: TMS WebCore

@ab, I create pull request
@rdevine, I update pull request
This type of interface is tested

  TSex = (cMale, cFemale);

  TCat = packed record
    Name: RawUtf8;
    Sex: TSex;
    Birthday: TDateTime;
  end;

  TCatDynArray = array of TCat;
  TCat3Array = array[0..2] of TCat;

  TPeople = packed record
    FirstName: RawUtf8;
    LastName: RawUtf8;
    Sex: TSex;
    Birthday: TDateTime;
    Cat: TCat;
    CatNested: packed record
        Name: RawUtf8;
        Sex: TSex;
        Birthday: TDateTime;
      end;
    Cat3: TCat3Array;
    Cats: TCatDynArray;
    CatsNested: array of TCat;
  end;

  ICalculator = interface(IInvokable)
    ['{9A60C8ED-CEB2-4E09-87D4-4A16F496E5FE}']
    function Add(n1, n2: integer): integer;
    function ArrayValue(const arrJSON: RawUtf8; ix: integer): variant;
    function CountArray(const jsn: RawUtf8): integer;
    function SumArray(const jsn: RawUtf8): double;
    procedure FullName(const aFirstName, aLastName: RawUtf8;
      var aFullName: RawUtf8; var aSize: integer);
    function CatIsMale(const aCat: TCat): Boolean;
    function GetCat: TCat;
    function GetPeople(aId: integer; var aPeople: TPeople): Boolean;
    function AddPeople(const aPeople: TPeople): integer;
    function AddCat2People(const aCat: TCat; var aPeople: TPeople): boolean;
  end; 

With this changes created client need only 2 manual changes, move array types before TPeople record and Replace All nested type names with correct type name.
In https://github.com/TTomas/mORMot-Web/tr … Pas2JSTest you can view context.json and exported client mORMotPas2JsClientExport.pas and edited mORMotPas2JsClient.pas.
I try version without helper record/array function, In GetPeople onSuccess to use

      onSuccess(TPeople(res[0]),Boolean(res[1]));

For simple types we can use this casting, but Birthday TDateTime field will be corrupt in pas2js. After this type of casting this field is no longer TDateTime (double/Number) but String (mormot serialize as iso8601) and using any datetime function is broken. This is JS world!
Using helper functions everythig is OK. Template is modified SMS and still there is a lot of SMS code in template. Need more testing on different structures.
@ab we need correct type naming for temporary nested fields (CatNested/CatsNested).

Last edited by ttomas (2024-03-17 14:54:09)

Offline

#9 2024-03-22 13:32:55

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: TMS WebCore

I have merged your Pull Request.
Thanks a lot for your very valuable input!

Feedback is welcome.

Offline

Board footer

Powered by FluxBB