jaydata icon indicating copy to clipboard operation
jaydata copied to clipboard

JaySvcUtil doesn't seem to generate anything useful?

Open sheam opened this issue 9 years ago • 2 comments

I installed jaysvcutil from npm.

I run it on my oData v4 endpoint: jaysvcutil -m http://localhost:17257/odata/$metadata -n XXX

A JayDataContext.d.ts which shows my context class as this:

declare module XXX
{
    export class Container extends $data.EntityContext
    {
        onReady(): Promise<Container>;
        Recipes: $data.EntitySet<typeof ViewModels.RecipeSummary, ViewModels.RecipeSummary>;
    }
}

In my

I include:
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="js/jaydata/jaydata.js"></script>
<script src="js/jaydata/jaydataproviders/oDataProvider.js"></script>
<script src="app/data/entities/JayDataContext.js"></script>

I am using JayData 1.5.1 CTP. But if I try and create a new context: x = new XXX.Container(), I see that XXX is not defined at run time. So essentially the generated JS is matching the the TS definition file.

None of the 4 year old examples cover this. And the older version of JayData does not support oData v4.

Are there any examples of using 1.5.1, with JaySvcUtil?

I am also getting a '@@@@' print out for each entity type defined by my odata, at the page load. Is that normal?

image

sheam avatar Apr 27 '16 00:04 sheam

So I ran JaySvcUtil with a -b so that it generates a context... just to see if anything changed. Now my project gives an error that odatajs is required. Ok, so I added the node odatajs package, which seems to be a bit of a mess. The documentation for the package says just add this <script type="text/javascript" src="./sources/odatajs-4.0.0.min.js"></script>. Well of course the npm package does not contain that file. Maybe it means the index.js file? I referenced that file, now it complains that it doesn't know what require is. Added the requirejs npm package. A little further, now the index.js requires files but seems to have the path wrong. FML.

The jaydata package on npms is the old version that doesn't support oData v4, and such has no value to us.

sheam avatar Apr 27 '16 01:04 sheam

You can install the latest JayData CTP from npm with npm install jaydata@next. On the client side, you have to use the client odatajs script file. You can find it here. You don't need requirejs and don't have to install odatajs from npm. Latest JayData no longer leaking the global or window objects. To access your entity and entity context type, you can use a CommonJS or AMD module loader or you can tell JayData to use a specific model container.

$data.setModelContainer(window)

You have to use this function after JayData, but before your context script file.

<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="js/jaydata/jaydata.js"></script>
<script src="js/jaydata/jaydataproviders/oDataProvider.js"></script>
<script>$data.setModelContainer(window)</script>
<script src="app/data/entities/JayDataContext.js"></script>

But it's recommended to use a module loader. See this example repository to see a working JayData OData example.

lazarv avatar Apr 27 '16 11:04 lazarv