StrongLoop LoopBack change models layout - layout

does anyone knows if it is possible to change the layout of models folder in loopback? For instance:
test1: models/test1/test1.js or json
test2: models/test2/test2.js or json
Thanks in advance

You can define any directory you want in model-config.json file.
{
"_meta": {
"sources": [
" models/test1",
" models/test2",
...
]
...
}
}

Related

How to change Pydantic default __root__ example

So I have this class:
class Table(BaseModel):
__root__: Dict[int, Test]
and I'm using the __root__ since it is a dynamic value but when I go to /redoc (I'm using FastAPI) the example values it defaults to is property1, property2 as in the image below but I wanted the default example to be id_1, id_2 for example. How can I achieve this?
I tried changing the alias and title using the Field method of the library but didn't seem to work like I expected.
Have you tried doing it with the schema customization ?
class QcastTable(BaseModel):
__root__: Dict[int, Test]
class Config:
schema_extra = {
"examples": [
{
"id_1": {
"title": "yourTitle",
"description": "yourDescription",
},
"id_2": {
"title": "yourTitle2",
"description": "yourDescription2",
}
}
]
}

How to make complex Prisma Schema from JSON data?

I'm very new to Prisma ORM. All the tutorials and articles show the basics of model and relations.
But my use case is different, I want to convert the below JSON to Prisma model.
Think this is an Item model and has a relation with options and additions. And options has relation with list.
And what would be the model definition for image object in Prisma model.
Thanks in advance.
{
"id":1,
"name":"American Classic",
"image":{
"title":"Image Title",
"url":"https://assets.suelo.pl/soup/img/products/burger01.jpg"
},
"description":"Beef, Cheese, Potato, Onion, Fries",
"price":9,
"options":[
{
"id":1,
"name":"Size",
"list":[
{
"id":1,
"name":"Normal - 200g",
"price":0
}
]
},
],
"additions":[
{
"id":1,
"name":"Prosciutto",
"price":3
}
]
}

How filter & format a json in node.js?

I want to format a JSON object in my Nodejs server. Delete some fields, rename some fields, and move some fields.
I have many different schemas need to apply to many different JSON, so I hope has a lib that can parse a configuration file and to it.
Maybe a configuration file like this:
DELETE request.logid
DELETE request.data.*.time
MOVE request.data.images data.images
And a JSON before applies an above schema:
{
"request": {
"data": {
"book": {
"name": "Hello World",
"time": 1546269044490
},
"images": [
"a-book.jpg"
]
},
"logid": "a514-afe1f0a2ac02_DCSix"
}
}
After applied:
{
"request": {
"data": {
"book": {
"name": "Hello World"
}
}
},
"data": {
"images": [
"a-book.jpg"
]
}
}
Where is the lib it is?
I know that write a function can do the same thing directly, but the problem is I have too many different schemas and too many different JSON, so I wanna manage them by configuration file rather than a js function.
Yes you could do something like this...
// Note: psuedocode
// Read the configuration file;
const commands = (await readFile('config')).split('\r\n').split(' ');
// your original JSON;
const obj = {...};
// Modify the JSON given the commands
commands.forEach( row=>{
if(row[0]==="DELETE"){
delete obj[row[1]];
}else if(row[0]==="MOVE"){
// use lodash to make your life easier.
_.set(obj,`${row[2]}`,_.get(obj,`${row[1]}`));
delete obj[row[1]];
}else if(...){
...
}
})

I can't get GitBook mermaid plugin to work, what a, i doing wrong?

I'm new at Gitbook and can not get the mermaid plugin to work.
book.json
{
"plugins": ["mermaid-2"
],
"pluginsConfig": {
"mermaid-2": {
"theme": "forest"
}
} }
file.md : I put the code into fenced code block and tag it mermaid
mermaid
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
But it is not showing diagrams, it display as:
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
Please help me, why is this not working?
Since gitbook-plugin-mermaid-2 does not work as it is, you need to edit node_modules/gitbook-plugin-mermaid-2/index.js as below.(Around line 33)
js: [
'bower_components/mermaid/dist/mermaid.min.js',
'plugin.js'
]
then surround file.md with ```mermaid.

Sync'ing ACL permissions in a NodeJS application using MongoDB

Currently using the Node ACL module from:
https://github.com/OptimalBits/node_acl
This is working a treat but now the requirement is have to reflect any changes to our security config in our ACL layer.
What Im looking for is a clean way to iterate over the roles defined in our security config, decide whether the permissions/resources have changed and if they have update or remove them.
Here is a sample security config file, take the scenario where 'put' is removed from the resource /projectId.
"roles":{
"itemRole":[
{
"roles":"owner-projectId",
"allows":[
{
"resources":"/projectId",
"permissions": ["put", "post", "patch","get","delete"]
},
{
"resources":"/projectId/settings",
"permissions": ["put"]
}
]
},
{
"roles":"collaborator-projectId",
"allows":[
{
"resources":"/itemId",
"permissions":["put","post", "patch","get"]
},
{
"resources":"/api/resource/itemId",
"permissions":["put", "post", "patch","get"]
}
]
},
{
"roles":"spectator-newId",
"allows":[ ]
},
{
"roles":"admin-newId",
"allows":[
{
"resources":"/api/resource/itemId/update",
"permissions":[ "put"]
}
]
}
]
}
The following query will allow me iterate over the different roles and return all the allows for that resources, these allow_* should match what is currently in the security.config:
db.getCollection('authACLresources').find( { _bucketname: {"$regex":"allows_*"}, key: { '$in': [ 'spectator-2bc240c6ffa988260b501922' ] }})
I can then look at the different permissions and compare - just wondering if there is a better way to do this? I know the node ACL module has a method called whatResources but doesn't give you the permissions just the resources.

Resources