Skip to content

Commit

Permalink
add new example
Browse files Browse the repository at this point in the history
  • Loading branch information
TamimiGitHub committed Jan 20, 2025
1 parent 54d091c commit 70317c5
Show file tree
Hide file tree
Showing 3 changed files with 286 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main

jobs:
bump-version:
publish:
runs-on: ubuntu-latest

steps:
Expand Down
287 changes: 283 additions & 4 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,288 @@ const event = {
]
}

const sap = {
"topic": "sap/erp/businesspartner/create/V1/{businessPartnerType}/{partnerId}",
"topicParameters": {
"partnerId": {
"schema": {
"type": "string"
},
"rule": {
"name": "partnerId",
"type": "string",
"group": "StringRules",
"rule": "alpha",
"casing": "mixed",
"minLength": 10,
"maxLength": 10
}
},
"businessPartnerType": {
"schema": {
"type": "string"
},
"rule": {
"name": "businessPartnerType",
"type": "string",
"group": "StringRules",
"rule": "enum",
"enum": [
"PARTNER1",
"PARTNER2",
"PRTNER3"
]
}
}
},
"eventName": "Business Partner Create",
"eventVersion": "0.1.0",
"messageName": "Business_Partner_Create",
"hasPayload": true,
"payload": {
"businessPartner": {
"type": "array",
"items": {
"type": "object",
"properties": {
"firstName": {
"type": "string",
"rule": {
"name": "firstName",
"type": "string",
"group": "StringRules",
"rule": "alpha",
"casing": "mixed",
"minLength": 10,
"maxLength": 10
}
},
"lastName": {
"type": "string",
"rule": {
"name": "lastName",
"type": "string",
"group": "StringRules",
"rule": "alpha",
"casing": "mixed",
"minLength": 10,
"maxLength": 10
}
},
"addressLink": {
"type": "array",
"items": {
"type": "object",
"properties": {
"address": {
"type": "array",
"items": {
"type": "object",
"properties": {
"country": {
"type": "string",
"rule": {
"name": "country",
"type": "string",
"group": "StringRules",
"rule": "alpha",
"casing": "mixed",
"minLength": 10,
"maxLength": 10
}
},
"nation": {
"type": "string",
"rule": {
"name": "nation",
"type": "string",
"group": "StringRules",
"rule": "alpha",
"casing": "mixed",
"minLength": 10,
"maxLength": 10
}
},
"city": {
"type": "string",
"rule": {
"name": "city",
"type": "string",
"group": "StringRules",
"rule": "alpha",
"casing": "mixed",
"minLength": 10,
"maxLength": 10
}
},
"street": {
"type": "string",
"rule": {
"name": "street",
"type": "string",
"group": "StringRules",
"rule": "alpha",
"casing": "mixed",
"minLength": 10,
"maxLength": 10
}
},
"postalCode": {
"type": "string",
"rule": {
"name": "postalCode",
"type": "string",
"group": "StringRules",
"rule": "alpha",
"casing": "mixed",
"minLength": 10,
"maxLength": 10
}
},
"houseNumber": {
"type": "string",
"rule": {
"name": "houseNumber",
"type": "string",
"group": "StringRules",
"rule": "alpha",
"casing": "mixed",
"minLength": 10,
"maxLength": 10
}
}
}
},
"subType": "object",
"name": "address",
"rule": {
"name": "address",
"type": "object"
}
},
"addressNumber": {
"type": "string",
"rule": {
"name": "addressNumber",
"type": "string",
"group": "StringRules",
"rule": "alpha",
"casing": "mixed",
"minLength": 10,
"maxLength": 10
}
},
"dateFrom": {
"type": "number",
"rule": {
"name": "dateFrom",
"type": "number",
"group": "NumberRules",
"rule": "float",
"minimum": 0,
"maximum": 1000,
"fractionDigits": 2
}
}
}
},
"subType": "object",
"name": "addressLink",
"rule": {
"name": "addressLink",
"type": "object"
}
},
"partnerId": {
"type": "string",
"rule": {
"name": "partnerId",
"type": "string",
"group": "StringRules",
"rule": "alpha",
"casing": "mixed",
"minLength": 10,
"maxLength": 10
}
},
"businessPartnerType": {
"type": "string",
"rule": {
"name": "businessPartnerType",
"type": "string",
"group": "StringRules",
"rule": "alpha",
"casing": "mixed",
"minLength": 10,
"maxLength": 10
}
}
}
},
"subType": "object",
"name": "businessPartner",
"rule": {
"name": "businessPartner",
"type": "object"
}
}
},
"publishSettings": {
"count": 0,
"interval": 1000,
"delay": 0
},
"mappings": [
{
"type": "Payload Parameter",
"source": {
"type": "Topic Parameter",
"name": "partnerId",
"fieldName": "partnerId",
"fieldType": "string"
},
"target": {
"type": "Payload Parameter",
"name": "businessPartner[0].partnerId",
"fieldName": "partnerId",
"fieldType": "string"
}
},
{
"type": "Payload Parameter",
"source": {
"type": "Payload Parameter",
"name": "businessPartner[0].addressLink[0].address[0].nation",
"fieldName": "nation",
"fieldType": "string"
},
"target": {
"type": "Payload Parameter",
"name": "businessPartner[0].addressLink[0].address[0].country",
"fieldName": "country",
"fieldType": "string"
}
},
{
"type": "Topic Parameter",
"source": {
"type": "Payload Parameter",
"name": "businessPartner[0].addressLink[0].address[0].country",
"fieldName": "country",
"fieldType": "string"
},
"target": {
"type": "Topic Parameter",
"name": "partnerId",
"fieldName": "partnerId",
"fieldType": "string"
}
}
]
};

const payload = generateRandomPayload(event.payload);
const topic = generateRandomTopic(event, payload);
const payload = generateRandomPayload(sap.payload);
const topic = generateRandomTopic(sap, payload);

console.log('Payload:', payload);
console.log('Topic:', topic);
console.log('Payload:\n', JSON.stringify(payload, null, 2));
console.log('Topic:', topic);
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SolaceDataGenerator {
// a. if its object --> process object
// b. if its non object --> generate content
value.subType === 'object'
? processObject(value.properties || {})
? processObject(value.items.properties || value.items.properties || {})
: generateContent(value)
);
} else {
Expand Down Expand Up @@ -427,6 +427,7 @@ class SolaceDataGenerator {
return faker.commerce.productName();
}
}

processInternetRules(rule) {
var data = [];
switch (rule.rule) {
Expand Down

0 comments on commit 70317c5

Please sign in to comment.