-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.0.0, including structure interpreter API #1
base: main
Are you sure you want to change the base?
Conversation
…ack to comment if missing
…tack structure support
I discovered an issue. Annotations on simple things like strings will "leak" to same-typed fields later on in the structure. I've tracked this down to the schema not being copied after calling |
Could have sworn I'd fixed all those cases when I change up how JsonSchemaInterpreter worked the last time to handle reusable stuff; must have missed that usage. Thanks! |
Another issue I've found is that The converter I created for new ParametricKeyedValue<>() {
@Override
public <T> @NotNull App<JsonSchemaInterpreter.Holder.Mu, App<Const.Mu<Integer>, T>> convert(
@NotNull App<Const.Mu<Range<@NotNull Integer>>, T> parameter
) {
final var range = Const.unbox(parameter);
final var result = JsonSchemaInterpreter.INTEGER.get();
result.addProperty("minimum", range.min());
result.addProperty("maximum", range.max());
return new JsonSchemaInterpreter.Holder<>(result);
}
} |
One thing I noticed is that the places that deal with definitions use |
I have found that |
Hmm. Yeah not sure the |
Here's a repro. The first final var codec = RecordCodecBuilder.<List<String>>create(
instance -> instance.group(
Codec.STRING.listOf().fieldOf("example").forGetter(Function.identity())
).apply(instance, Function.identity())
);
final var structure = Structure.<List<String>>record(i -> {
final var example = i.add("example", Structure.STRING.listOf(), Function.identity());
return container -> example.apply(container);
});
final var json = JsonParser.parseString("{\"example\": [\"abc\", 123, \"def\"]}");
final var expected = Optional.of(List.of("abc", "def"));
assertEquals(expected, codec.parse(JsonOps.INSTANCE, json).resultOrPartial());
assertEquals(
expected,
CodecInterpreter.create()
.interpret(structure)
.getOrThrow()
.parse(JsonOps.INSTANCE, json)
.resultOrPartial()
); |
Alright I see what you mean; I'll look into support for partials. |
Side note, just in case someone wants to print a |
Oof yeah thanks |
Alright, 1.21.2 is a thing now so I'm going to try to get more work on this done soon -- I have a lot of work to do IRL, so there may be a bit of a delay. |
A new system for expressing data structures in a way that can be "interpreted" to various formats -- that is,
Codec
s,StreamCodec
s, JSON schema, (eventually) config screens, etc.Made of the following components:
Structure<A>
, represents a structure for representing anA
Interpreter<T>
, mapsStructure<A> -> T<A>
(representing the type function throughK1
/App
)Structures can represent:
Structure#listOf
Structure#record
andRecordStructure.Builder
. Record builders can be combined, so long as keys are unique, similar toMapCodec
s, and follow a similar design asKeyedRecordCodecBuilder
.flatXmap
/xmap
ed structures, through the appropriate methods onStructure
keyed
structures, which represent anInterpreter
-specific implementation, linked to a given instance-comparableKey
-- think primitivesannotate
d structures, which provide data anInterpreter
may use to modify the complete structure -- think comments.Current interpreters include:
Codec
s throughCodecInterpreter
MapCodec
s throughMapCodecInterpreter
, which delegates to aCodecInterpreter
for all nested non-map stuffStreamCodec
s throughStreamCodecInterpreter
JsonSchemaInterpreter
ConfigScreenInterpreter
IdentityInterpreter
TODO items:
ItemStack
key-dispatched mapsHolder
skeyed
structures for things that take in some parameters and produce anInterpreter
-specific object -- see, resource keys or the like.Mu
, and akeyed
structure can include stuff keyed on that to fall back to, if interpreters don't have something.Either
codecs or similar formsFor an example of usage, see https://github.com/lukebemishprojects/codecextras/blob/feature/structures/src/test/java/dev/lukebemish/codecextras/test/structured/TestStructured.java