-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Context Referencing Shortcut (#51)
- Loading branch information
1 parent
fa18185
commit 8f9c2ca
Showing
14 changed files
with
238 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
docs/docs/System-Documentation/Standards/99_context-accessing.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Context Accessing Shortcut | ||
|
||
To simplify the context accessing and its definition, there's a shortcut notation defined. | ||
This type of declaration was chosen to enable simplicity of the schema definition based on | ||
more dynamic schema compilation approach. | ||
|
||
Instead of somewhat statically typed names of standards, this approach lets you pass configuration | ||
as a part of the name to your Field declaration. | ||
|
||
This notation is based on two parts - `!ref-<<path>>`, where the `<<path>>` is the path in the | ||
given context object using dots (`.`) as separators. | ||
|
||
!!! example | ||
|
||
In this example, you can see how you can access the desired value by specifying the path through the | ||
Fabrication Context object. | ||
|
||
``` | ||
const context = { | ||
myField: { | ||
myValue: 'some-value' | ||
} | ||
}; | ||
|
||
const valueGenerator = getStandard('!ref-myField.myValue'); | ||
|
||
const generatedValue = valueGenerator.generate(context); | ||
``` | ||
|
||
!!! abstract "Output" | ||
|
||
``` | ||
'some-value' | ||
``` | ||
|
||
Here's a full demonstration of how the shortcut can be used: | ||
|
||
!!! example | ||
|
||
You can declare your schema with usage of identifiers [profile](../Profiles/00_introduction.md). | ||
This profile passes pregenerated values into a context object accessible to each value generator, | ||
so you can easily access it. | ||
|
||
You can also specify other fields; in this case `addressId` field - to take a value from given | ||
context object passed during the fabrication. This can be useful for example when you are generating | ||
instances of multiple entities linked by foreign keys. | ||
|
||
```typescript linenums="1" | ||
// Declare your schema | ||
const schema: SchemaInput = { | ||
profiles: ['identifiers'], | ||
fields: { | ||
userId: '!ref-profiles.identifiers.uuid', | ||
addressId: '!ref-addressId', | ||
|
||
// ... another fields ... | ||
} | ||
}; | ||
|
||
// Create a Fabricator instance | ||
const fabricator = new Fabricator(schema); | ||
|
||
// Generate a Falsum object with specified context | ||
const generated: Falsum = fabricator.generate({ | ||
addressId: 123456 | ||
}); | ||
|
||
console.log(generated); | ||
``` | ||
|
||
!!! abstract "Output" | ||
|
||
``` | ||
{ userId: 'f85d6bc3-1391-488b-90ad-8a114d1be5be', addressId: 123456 } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.