@devkong/cli-nx 0.0.58 → 0.0.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/generators/preset/files/kotlin/README.md +0 -25
- package/src/generators/preset/files/kotlin/build.gradle.kts.template +3 -2
- package/src/generators/preset/files/kotlin/src/main/kotlin/io/kong/extension/Main.kt +22 -15
- package/src/generators/preset/files/kotlin/src/main/resources/application.properties.template +1 -0
- package/src/generators/preset/files/kotlin/src/test/kotlin/io/kong/extension/Test.kt +7 -8
- package/src/generators/preset/generator.js +11 -1
- package/src/generators/preset/generator.js.map +1 -1
package/package.json
CHANGED
|
@@ -43,31 +43,6 @@ To automatically tag your code with an incremented version number (e.g., 1, 2, 3
|
|
|
43
43
|
kong publish-version --verbose
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
**NOTE:** before publishing a new version, ensure that your extension JSON Schema includes the required `operation` field. This input field has `enum` type and defines the action to be performed by the extension.
|
|
47
|
-
|
|
48
|
-
**Purpose:**
|
|
49
|
-
|
|
50
|
-
- When an extension supports multiple usage variants or endpoints, this field identifies the specific operation to execute.
|
|
51
|
-
- It enables routing and logic selection within the extension workflow.
|
|
52
|
-
- If an extension has only one primary function, this `enum` contains a single value that uniquely identifies its operation.
|
|
53
|
-
|
|
54
|
-
**Usage Example:**
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
58
|
-
"title": "Input",
|
|
59
|
-
"type": "object",
|
|
60
|
-
"properties": {
|
|
61
|
-
"operation": {
|
|
62
|
-
"enum": ["score digital profile", ...],
|
|
63
|
-
"examples": ["score digital profile"],
|
|
64
|
-
"description": "Operation type."
|
|
65
|
-
},
|
|
66
|
-
...
|
|
67
|
-
"required": ["operation", ... ]
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
46
|
### List Available Versions
|
|
72
47
|
|
|
73
48
|
To see all available versions of your extension, run:
|
|
@@ -23,8 +23,9 @@ repositories {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
dependencies {
|
|
26
|
-
implementation("io.kong:kong-common:$kongVersion")
|
|
27
26
|
implementation("io.kong:kong-sdk-function-template:$kongSdkVersion")
|
|
27
|
+
implementation("io.kong:kong-sdk-kotlin:$kongSdkVersion")
|
|
28
|
+
implementation("io.kong:kong-common:$kongVersion")
|
|
28
29
|
|
|
29
30
|
implementation(enforcedPlatform("io.quarkus.platform:quarkus-bom:$quarkusVersion"))
|
|
30
31
|
implementation("io.quarkus:quarkus-arc")
|
|
@@ -38,7 +39,7 @@ dependencies {
|
|
|
38
39
|
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinxCoroutinesTestVersion")
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
group = "io.kong"
|
|
42
|
+
group = "io.kong.extension"
|
|
42
43
|
version = "0.0.1-SNAPSHOT"
|
|
43
44
|
|
|
44
45
|
java {
|
|
@@ -6,6 +6,7 @@ import io.kong.sdk.KongFunction
|
|
|
6
6
|
import io.kong.sdk.KongFunctionContext
|
|
7
7
|
import io.kong.sdk.function.template.Field
|
|
8
8
|
import io.quarkus.runtime.annotations.RegisterForReflection
|
|
9
|
+
import jakarta.inject.Inject
|
|
9
10
|
import jakarta.inject.Singleton
|
|
10
11
|
|
|
11
12
|
// This is the main entry point for developing an extension for Kong.
|
|
@@ -14,41 +15,47 @@ import jakarta.inject.Singleton
|
|
|
14
15
|
// Define the structure of the input data that your extension will accept.
|
|
15
16
|
// Be sure to include example values for each field. These examples help generate
|
|
16
17
|
// sample objects in the UI, making it easier to work with the models.
|
|
18
|
+
|
|
17
19
|
@RegisterForReflection
|
|
18
20
|
data class InputData(
|
|
19
21
|
// REPLACE BELLOW WITH YOUR FIELDS
|
|
20
|
-
|
|
21
|
-
@Field(description = "An integer number", examples = ["
|
|
22
|
-
val a: Int,
|
|
23
|
-
|
|
24
|
-
@Field(description = "An integer number", examples = ["2"])
|
|
25
|
-
val b: Int,
|
|
22
|
+
@Field(description = "An integer number", examples = ["1"]) val a: Int,
|
|
23
|
+
@Field(description = "An integer number", examples = ["2"]) val b: Int,
|
|
26
24
|
)
|
|
27
25
|
|
|
28
26
|
@RegisterForReflection
|
|
29
27
|
data class OutputData(
|
|
30
28
|
// Define the structure of the output data that your extension will return.
|
|
31
29
|
// REPLACE BELLOW WITH YOUR FIELDS
|
|
32
|
-
|
|
33
|
-
@Field(description = "Result of a + b", examples = ["3"])
|
|
34
|
-
val sum_of: Int,
|
|
35
|
-
|
|
30
|
+
@Field(description = "Result of a + b", examples = ["3"]) val sumOf: Int,
|
|
36
31
|
@Field(
|
|
37
32
|
description = "A string field",
|
|
38
33
|
examples = ["This example extension returns sum of a and b"],
|
|
39
34
|
default = "null",
|
|
40
|
-
)
|
|
41
|
-
val comment: String? = null,
|
|
35
|
+
) val comment: String? = null,
|
|
42
36
|
)
|
|
43
37
|
|
|
44
|
-
val objectMapper = ObjectMapper()
|
|
45
|
-
|
|
46
38
|
@Singleton
|
|
47
39
|
class Main : KongFunction<InputData>(InputData::class.java) {
|
|
48
40
|
private val logger = AppLogger(Main::class.simpleName)
|
|
49
41
|
|
|
42
|
+
@Inject
|
|
43
|
+
internal lateinit var jsonMapper: ObjectMapper
|
|
44
|
+
|
|
50
45
|
override suspend fun handle(
|
|
51
46
|
data: InputData,
|
|
52
47
|
context: KongFunctionContext,
|
|
53
|
-
): ByteArray?
|
|
48
|
+
): ByteArray? {
|
|
49
|
+
logger.info("handle sum") {
|
|
50
|
+
it["a"] = data.a
|
|
51
|
+
it["b"] = data.b
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return jsonMapper.writeValueAsBytes(
|
|
55
|
+
OutputData(
|
|
56
|
+
sumOf = data.a + data.b,
|
|
57
|
+
comment = "sum of ${data.a} and ${data.b}",
|
|
58
|
+
),
|
|
59
|
+
)
|
|
60
|
+
}
|
|
54
61
|
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
package io.kong.
|
|
1
|
+
package io.kong.extension
|
|
2
2
|
|
|
3
3
|
import com.fasterxml.jackson.databind.ObjectMapper
|
|
4
|
-
import io.kong.
|
|
5
|
-
import io.kong.extension.Main
|
|
6
|
-
import io.kong.extension.OutputData
|
|
4
|
+
import io.kong.sdk.function.template.ExtensionTestProfile
|
|
7
5
|
import io.quarkus.test.junit.QuarkusTest
|
|
6
|
+
import io.quarkus.test.junit.TestProfile
|
|
8
7
|
import jakarta.inject.Inject
|
|
9
8
|
import kotlinx.coroutines.test.runTest
|
|
10
9
|
import org.junit.jupiter.api.Assertions.assertEquals
|
|
11
10
|
import org.junit.jupiter.api.Test
|
|
12
11
|
|
|
13
12
|
@QuarkusTest
|
|
13
|
+
@TestProfile(ExtensionTestProfile::class)
|
|
14
14
|
class Test {
|
|
15
15
|
@Inject
|
|
16
16
|
lateinit var extension: Main
|
|
17
17
|
|
|
18
18
|
@Inject
|
|
19
|
-
lateinit var
|
|
19
|
+
lateinit var jsonMapper: ObjectMapper
|
|
20
20
|
|
|
21
21
|
@Test
|
|
22
22
|
fun `when provided valid input then returns expected result`() =
|
|
@@ -24,9 +24,8 @@ class Test {
|
|
|
24
24
|
val input = InputData(a = 1, b = 2)
|
|
25
25
|
|
|
26
26
|
val bytes = extension.handle(input)
|
|
27
|
-
val output =
|
|
28
|
-
val sumOf = output.sum_of
|
|
27
|
+
val output = jsonMapper.readValue(bytes, OutputData::class.java)
|
|
29
28
|
|
|
30
|
-
assertEquals(3, sumOf)
|
|
29
|
+
assertEquals(3, output.sumOf)
|
|
31
30
|
}
|
|
32
31
|
}
|
|
@@ -6,14 +6,24 @@ const devkit_1 = require("@nx/devkit");
|
|
|
6
6
|
const path = tslib_1.__importStar(require("path"));
|
|
7
7
|
function presetGenerator(tree, options) {
|
|
8
8
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
9
|
+
const projectRoot = ".";
|
|
9
10
|
const projectName = "";
|
|
10
11
|
(0, devkit_1.addProjectConfiguration)(tree, projectName, {
|
|
11
|
-
root:
|
|
12
|
+
root: projectRoot,
|
|
12
13
|
projectType: "application",
|
|
13
14
|
});
|
|
14
15
|
options.os = process.platform;
|
|
15
16
|
(0, devkit_1.generateFiles)(tree, path.join(__dirname, `files/${options.platform}`), "", options);
|
|
16
17
|
yield (0, devkit_1.formatFiles)(tree);
|
|
18
|
+
try {
|
|
19
|
+
const gradlewPath = (0, devkit_1.joinPathFragments)(projectRoot, "gradlew");
|
|
20
|
+
if (tree.exists(gradlewPath)) {
|
|
21
|
+
tree.changePermissions(gradlewPath, "755"); // rwxr-xr-x
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (ex) {
|
|
25
|
+
console.warn("failed to make gradlew executable", ex);
|
|
26
|
+
}
|
|
17
27
|
});
|
|
18
28
|
}
|
|
19
29
|
exports.default = presetGenerator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../src/generators/preset/generator.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../src/generators/preset/generator.ts"],"names":[],"mappings":";;AAUA,0CAoBC;;AA9BD,uCAMoB;AACpB,mDAA6B;AAG7B,SAAsB,eAAe,CAAC,IAAU,EAAE,OAA8B;;QAC9E,MAAM,WAAW,GAAG,GAAG,CAAC;QACxB,MAAM,WAAW,GAAG,EAAE,CAAC;QACvB,IAAA,gCAAuB,EAAC,IAAI,EAAE,WAAW,EAAE;YACzC,IAAI,EAAE,WAAW;YACjB,WAAW,EAAE,aAAa;SAC3B,CAAC,CAAC;QAEH,OAAO,CAAC,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;QAC9B,IAAA,sBAAa,EAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QACpF,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;QAExB,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,IAAA,0BAAiB,EAAC,WAAW,EAAE,SAAS,CAAC,CAAC;YAC9D,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC7B,IAAI,CAAC,iBAAiB,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC,YAAY;YAC1D,CAAC;QACH,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,OAAO,CAAC,IAAI,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;CAAA;AAED,kBAAe,eAAe,CAAC"}
|