Skip to content

Commit 88c3fd1

Browse files
authored
feat: sdk parity (#2)
1 parent 37f8abc commit 88c3fd1

File tree

84 files changed

+1756
-363
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1756
-363
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ trim_trailing_whitespace = true
1212
[*.java]
1313
insert_final_newline = true
1414
indent_size = 4
15+
16+
[Makefile]
17+
indent_style = tab

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,8 @@ build/
6666
out/
6767
dist/
6868
example-1/
69+
monorepo
70+
featurevisor-go
71+
specs
6972

7073
.flattened-pom.xml

Makefile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
.PHONY: install build test setup-monorepo update-monorepo setup-golang-sdk update-golang-sdk setup-references update-references
2+
3+
install:
4+
mvn install
5+
6+
build:
7+
mvn compile package
8+
9+
test:
10+
mvn test
11+
12+
##
13+
# Monorepo
14+
#
15+
setup-monorepo:
16+
mkdir -p monorepo
17+
if [ ! -d "monorepo/.git" ]; then \
18+
git clone git@github.com:featurevisor/featurevisor.git monorepo; \
19+
else \
20+
(cd monorepo && git fetch origin main && git checkout main && git pull origin main); \
21+
fi
22+
make update-monorepo
23+
24+
update-monorepo:
25+
(cd monorepo && git pull origin main && make install && make build)
26+
27+
##
28+
# Golang SDK
29+
#
30+
setup-golang-sdk:
31+
mkdir -p featurevisor-go
32+
if [ ! -d "featurevisor-go/.git" ]; then \
33+
git clone git@github.com:featurevisor/featurevisor-go.git featurevisor-go; \
34+
else \
35+
(cd featurevisor-go && git fetch origin main && git checkout main && git pull origin main); \
36+
fi
37+
38+
update-golang-sdk:
39+
(cd featurevisor-go && git pull origin main)
40+
41+
##
42+
# All references
43+
#
44+
setup-references:
45+
make setup-monorepo
46+
make setup-golang-sdk
47+
48+
update-references:
49+
make update-monorepo
50+
make update-golang-sdk

README.md

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,64 @@ f.<MyCustomClass>getVariableObject(featureKey, variableKey, context);
303303

304304
f.<Map<String, Object>>getVariableJSON(featureKey, variableKey, context);
305305
f.<MyCustomClass>getVariableJSON(featureKey, variableKey, context);
306+
f.getVariableJSONNode(featureKey, variableKey, context);
306307
```
307308

309+
For strongly typed decoding, additional overloads are available:
310+
311+
```java
312+
import com.fasterxml.jackson.core.type.TypeReference;
313+
314+
// Array decoding using Class<T>
315+
List<MyItem> items = f.getVariableArray(featureKey, variableKey, context, MyItem.class);
316+
317+
// Array decoding using TypeReference
318+
List<Map<String, Object>> rows = f.getVariableArray(
319+
featureKey,
320+
variableKey,
321+
context,
322+
new TypeReference<List<Map<String, Object>>>() {}
323+
);
324+
325+
// Object decoding using Class<T>
326+
MyConfig config = f.getVariableObject(featureKey, variableKey, context, MyConfig.class);
327+
328+
// Object decoding using TypeReference
329+
Map<String, List<MyConfig>> nested = f.getVariableObject(
330+
featureKey,
331+
variableKey,
332+
context,
333+
new TypeReference<Map<String, List<MyConfig>>>() {}
334+
);
335+
```
336+
337+
Typed overloads are additive and non-breaking. If decoding fails for the requested target type, these methods return `null`.
338+
339+
For dynamic JSON values with unknown shape, use `getVariableJSONNode`:
340+
341+
```java
342+
import com.fasterxml.jackson.databind.JsonNode;
343+
344+
JsonNode node = f.getVariableJSONNode(featureKey, variableKey, context);
345+
346+
if (node != null && node.isObject()) {
347+
String nested = node.path("key").path("nested").asText(null);
348+
}
349+
```
350+
351+
If a variable schema type is `json` and the resolved value is a malformed stringified JSON, JSON parsing fails safely and these methods return `null`:
352+
353+
- `getVariable(...)`
354+
- `getVariableJSONNode(...)`
355+
- `getVariableJSON(...)`
356+
308357
## Getting all evaluations
309358

310359
You can get evaluations of all features available in the SDK instance:
311360

312361
```java
313-
import com.featurevisor.types.EvaluatedFeatures;
314-
import com.featurevisor.types.EvaluatedFeature;
362+
import com.featurevisor.sdk.EvaluatedFeatures;
363+
import com.featurevisor.sdk.EvaluatedFeature;
315364

316365
EvaluatedFeatures allEvaluations = f.getAllEvaluations(context);
317366

@@ -690,6 +739,7 @@ Similar to parent SDK, child instances also support several additional methods:
690739
- `getVariableArray`
691740
- `getVariableObject`
692741
- `getVariableJSON`
742+
- `getVariableJSONNode`
693743
- `getAllEvaluations`
694744
- `on`
695745
- `close`
@@ -717,9 +767,16 @@ $ mvn exec:java -Dexec.mainClass="com.featurevisor.cli.CLI" -Dexec.args="test --
717767
Additional options that are available:
718768

719769
```bash
720-
$ mvn exec:java -Dexec.mainClass="com.featurevisor.cli.CLI" -Dexec.args="test --projectDirectoryPath=/absolute/path/to/your/featurevisor/project --quiet --onlyFailures --keyPattern=myFeatureKey --assertionPattern=#1"
770+
$ mvn exec:java -Dexec.mainClass="com.featurevisor.cli.CLI" -Dexec.args="test --projectDirectoryPath=/absolute/path/to/your/featurevisor/project --quiet --onlyFailures --keyPattern=myFeatureKey --assertionPattern=#1 --with-tags --with-scopes --showDatafile --schemaVersion=2 --inflate=1"
721771
```
722772

773+
Scoped and tagged test behavior mirrors the JavaScript tester:
774+
775+
- `--with-tags`: builds and tests assertions against tagged datafiles.
776+
- `--with-scopes`: builds scoped datafiles and tests scoped assertions against those scoped files.
777+
- without `--with-scopes`: scoped assertions still run by merging scope context into assertion context (fallback behavior).
778+
- if both `scope` and `tag` are present in an assertion, scope datafile takes precedence.
779+
723780
### Benchmark
724781

725782
Learn more about benchmarking [here](https://featurevisor.com/docs/cli/#benchmarking).

0 commit comments

Comments
 (0)