Skip to content

Commit 5759401

Browse files
committed
java-1.1.2 js-1.7.1 js-core-1.7.2 monaco-1.2.3 - add aliases $$any and $$all. fix highlighting of aliases.
docs - add text template and api reference for java and ts
1 parent dbfc449 commit 5759401

File tree

27 files changed

+531
-66
lines changed

27 files changed

+531
-66
lines changed

docs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Website
22

3-
This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.
3+
This website is built using [Docusaurus 3](https://docusaurus.io/), a modern static website generator.
44

55
### Installation
66

docs/docs/07. text-template.md

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# Text Template
2+
3+
The library exposes a class called `TextTemplate`.
4+
5+
This utility helps render text templates providing a template `string` and a resolver (`ParameterResolver`).
6+
7+
## Examples
8+
9+
```mdx-code-block
10+
<div className="examples_grid">
11+
```
12+
13+
**Input**
14+
15+
**Definition**
16+
17+
**Output**
18+
19+
20+
```json
21+
{ "name": "John" }
22+
```
23+
```transformers
24+
"Hello {name}"
25+
```
26+
```json
27+
"Hello John"
28+
```
29+
30+
31+
```json
32+
{ "name": "John" }
33+
```
34+
```transformers
35+
"Hello {first_name,Anonymous}"
36+
```
37+
```json
38+
"Hello Anonymous"
39+
```
40+
41+
42+
```json
43+
{
44+
"name": "John",
45+
"children": 2
46+
}
47+
```
48+
```transformers
49+
"{name} has {children} children"
50+
```
51+
```json
52+
"John has 2 children"
53+
```
54+
55+
56+
```json
57+
{
58+
"first": "John",
59+
"last": "Doe"
60+
}
61+
```
62+
```transformers
63+
"Your initials are {$$substring(0,1):first}{$$substring(0,1):last}"
64+
```
65+
```json
66+
"Your initials are JD"
67+
```
68+
69+
```mdx-code-block
70+
</div>
71+
```
72+
73+
<br/>
74+
75+
:::info
76+
You can use text templates inside json transformers using the function [`$$template`](functions/template)
77+
:::
78+
79+
## API
80+
81+
### Java
82+
83+
```java
84+
class TextTemplate {
85+
86+
/**
87+
* Creates a new memory template for a string
88+
*
89+
* @param template The template text
90+
* @param defaultResolver (optional) defines how the template should resolve parameter default values
91+
*/
92+
public TextTemplate(String template, ParameterDefaultResolveOptions defaultResolver);
93+
94+
/**
95+
* Exposes a read only list to inspect the list of parameters
96+
*
97+
* @return a list of parameters in the template
98+
*/
99+
public List<TemplateParameter> getParameters();
100+
101+
/**
102+
* Renders the template after inserting the parameters
103+
*
104+
* @param resolver A resolver to extract parameter values
105+
* @param adapter (optional) The adapter to use for rendering
106+
* @param urlEncodeParameters (optional) if true, the parameters will be URL encoded
107+
* @return a string with its parameters replaced
108+
*/
109+
public String render(ParameterResolver resolver, JsonAdapter<?,?,?> adapter, Boolean urlEncodeParameters);
110+
111+
/**
112+
* gets or creates a template from the cache
113+
*
114+
* @param template the command to parse
115+
* @param defaultResolver (optional) defines how the template should resolve parameter default values
116+
* @return a new text template
117+
*/
118+
public static TextTemplate get(String template, ParameterDefaultResolveOptions defaultResolver);
119+
120+
/**
121+
* Creates a Map suitable to be used for a parameter resolver out of string parameters.
122+
* Parameters needs to be provided in pairs of key and value.
123+
*/
124+
public static Map<String, String> mapOf(String... parameters);
125+
126+
public static String render(String template, ParameterResolver resolver, ParameterDefaultResolveOptions defaultResolver, Boolean urlEncodeParameters);
127+
public static String render(String template, Map<String, ?> resolver, ParameterDefaultResolveOptions defaultResolver);
128+
}
129+
```
130+
131+
:::info
132+
Some methods will accept `Map<String, ?>` instead of `ParameterResolver`.<br/>
133+
You can use the static method `mapOf` to create such a map.
134+
:::
135+
136+
### TypeScript
137+
138+
```typescript
139+
class TextTemplate {
140+
/**
141+
* Creates a new memory template for a string
142+
*
143+
* @param template The template text
144+
* @param defaultResolver defines how the template should resolve parameter default values
145+
*/
146+
constructor(template: string, defaultResolver?: ParameterDefaultResolveOptions);
147+
/**
148+
* Exposes a list copy to inspect the list of parameters
149+
*
150+
* @return a list of parameters in the template
151+
*/
152+
getParameters(): TemplateParameter[];
153+
/**
154+
* gets or creates a template from the cache
155+
*
156+
* @param template the command to parse
157+
* @param defaultResolver defines how the template should resolve parameter default values
158+
* @return a new text template
159+
*/
160+
static get(template: string, defaultResolver?: ParameterDefaultResolveOptions): TextTemplate;
161+
/**
162+
* Renders the template after inserting the parameters
163+
*
164+
* @param resolver A resolver to extract parameter values
165+
* @param urlEncodeParameters if true, the parameters will be URL encoded
166+
* @return a string with its parameters replaced
167+
*/
168+
render(resolver: Record<string, string> | ParameterResolver, urlEncodeParameters?: boolean | null): Promise<string>;
169+
static render(template: string, resolver: Record<string, string> | ParameterResolver, defaultResolver?: ParameterDefaultResolveOptions, urlEncodeParameters?: boolean): Promise<string>;
170+
}
171+
```

docs/docs/api-reference/01. java.md

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Java
2+
3+
Java library API reference
4+
5+
:::info
6+
In java, you need to decide which [JSON implementation](#json-implementations) you want to use.
7+
:::
8+
9+
| Name | Description | License | Status |
10+
|---------------------------------------------------------------------------------------------|--------------------------------------------|--------------------|---------------------------------------------------------------------------------------------|
11+
| [co.nlighten.json-transform](https://mvnrepository.com/artifact/co.nlighten/json-transform) | Java library for transforming JSON objects | Apache License 2.0 | ![Maven Central Version](https://img.shields.io/maven-central/v/co.nlighten/json-transform) |
12+
13+
## Usage
14+
15+
### Initialization
16+
- In your app initialization (e.g. main method)
17+
```java title="e.g. for Gson as the JSON implementation"
18+
import co.nlighten.jsontransform.JsonTransformerConfiguration;
19+
import co.nlighten.jsontransform.adapters.gson.GsonJsonTransformerConfiguration;
20+
21+
JsonTransformerConfiguration.set(
22+
new GsonJsonTransformerConfiguration(() -> MyGsonBuilder.create())
23+
);
24+
```
25+
26+
### Transformation
27+
- Use the `JsonTransformer` class to transform JSON objects
28+
```java
29+
Transformer transformer = new JsonTransformer(definition);
30+
var result = transformer.transform(input);
31+
```
32+
:::info Notice
33+
Result is not unwrapped from the JSON implementation.
34+
You can either supply 'true' in the unwrap argument or use the JSON adapter to unwrap it after transformation.
35+
:::
36+
37+
- A way to get the current JSON adapter is
38+
```java
39+
var adapter = JsonTransformerConfiguration.get().getAdapter();
40+
```
41+
42+
43+
## API
44+
45+
### JsonTransformer
46+
47+
```java
48+
class JsonTransformer {
49+
50+
/**
51+
* Creates a new JSON transformer from definition
52+
*
53+
* @param definition The transformer definition
54+
* @param adapter (optional) A specific JSON implementation adapter (otherwise uses the configured default)
55+
* @param functionsAdapter (optional) A specific transformer functions adapter (otherwise uses the default)
56+
*/
57+
public JsonTransformer(
58+
final Object definition,
59+
final JsonAdapter<?, ?, ?> adapter,
60+
final TransformerFunctionsAdapter functionsAdapter
61+
);
62+
63+
/**
64+
* Transforms the payload using the transformer definition
65+
*
66+
* @param payload The payload to transform
67+
* @param additionalContext (optional) Additional context to use in the transformation
68+
* @param unwrap (optional) Unwrap the result to POJO from the used JSON implementation (default is false)
69+
*/
70+
public Object transform(Object payload, Map<String, Object> additionalContext, boolean unwrap);
71+
72+
/**
73+
* Gets the transformer definition
74+
*/
75+
public Object getDefinition();
76+
}
77+
```
78+
79+
### JsonTransformerConfiguration
80+
81+
```java
82+
class JsonTransformerConfiguration {
83+
84+
/**
85+
* Sets the default configuration (based on a specific JSON implementation)
86+
*
87+
* @param configuration The JSON transformer configuration implementation
88+
*/
89+
public static void set(JsonTransformerConfiguration configuration);
90+
91+
/**
92+
* Gets the current default JSON transformer configuration
93+
*/
94+
public static JsonTransformerConfiguration get();
95+
96+
/**
97+
* Gets the current JSON implementation adapter
98+
*/
99+
public JsonAdapter<?, ?, ?> getAdapter();
100+
}
101+
```
102+
## JSON Implementations
103+
104+
Possible implementations are:
105+
106+
| Name | Notes | JsonTransformerConfiguration class |
107+
|-----------|----------------------------------------------------------------------------------------------|-----------------------------------------|
108+
| Gson | package: [com.google.code.gson:gson](https://github.com/google/gson) | `GsonJsonTransformerConfiguration` |
109+
| Jackson | package: [com.fasterxml.jackson.core:jackson-databind](https://github.com/FasterXML/jackson) | `JacksonJsonTransformerConfiguration` |
110+
| JsonOrg | package: [org.json:json](https://github.com/stleary/JSON-java) | `JsonOrgJsonTransformerConfiguration` |
111+
| JsonSmart | package: [net.minidev:json-smart](https://github.com/netplex/json-smart-v2) (v2) | `JsonSmartJsonTransformerConfiguration` |
112+
| Pojo | (The default implementation) uses JsonPath's default (embedded) JSON provider | `PojoJsonTransformerConfiguration` |
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# TypeScript
2+
TypeScript/JavaScript library API reference
3+
4+
| Name | Description | License | Status |
5+
|------------------------------------------------------------------------------------|---------------------------------------------|---------|---------------------------------------------------------------|
6+
| [@nlighten/json-transform](https://www.npmjs.com/package/@nlighten/json-transform) | JSON transformers JavaScript implementation | MIT | ![npm](https://img.shields.io/npm/v/@nlighten/json-transform) |
7+
8+
## Usage
9+
10+
### Transformation
11+
- Use the `JsonTransformer` class to transform JSON objects
12+
13+
:::info Notice
14+
The implementation uses async methods and returns a `Promise`.
15+
:::
16+
17+
```typescript
18+
const transformer = new JsonTransformer(definition);
19+
const result = await transformer.transform(input);
20+
```
21+
22+
## API
23+
24+
### JsonTransformer
25+
26+
```typescript
27+
declare class JsonTransformer {
28+
29+
/**
30+
* Creates a new JSON transformer from definition
31+
*
32+
* @param definition The transformer definition
33+
* @param functionsAdapter (optional) A specific transformer functions adapter (otherwise uses the default)
34+
*/
35+
constructor(
36+
definition: any,
37+
functionsAdapter?: TransformerFunctionsAdapter
38+
);
39+
40+
/**
41+
* Transforms the payload using the transformer definition
42+
*
43+
* @param payload The payload to transform
44+
* @param additionalContext (optional) Additional context to use in the transformation
45+
* @returns A promise to the transformed payload
46+
*/
47+
transform(payload?: any, additionalContext?: Record<string, any>) : Promise<any>;
48+
49+
/**
50+
* Gets the transformer definition
51+
*/
52+
getDefinition() : any;
53+
}
54+
```
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "API Reference",
3+
"position": 9,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "API reference"
7+
}
8+
}

docs/docusaurus.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ const config: Config = {
160160
},
161161
prism: {
162162
theme: darkCodeTheme,
163+
additionalLanguages: ["java"],
163164
},
164165
},
165166
markdown: {

docs/src/css/custom.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
max-height: 500px;
8484
}
8585

86-
.prism-code > code {
86+
.prism-code:not(.language-java) > code {
8787
white-space: pre-wrap;
8888
overflow-wrap: anywhere;
8989
}

java/json-transform/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
}
1010

1111
group 'co.nlighten'
12-
version = '1.1.0'
12+
version = '1.1.2'
1313

1414
ext {
1515
gsonVersion = "2.10.1"

0 commit comments

Comments
 (0)