Skip to content

Commit 967e898

Browse files
author
jchadwick-buf
authored
Refactor the API for v1 (#226)
It's a bit ugly but seems like our best option since Java doesn't have any concept of `internal` packages. This mirrors the Go protovalidate package structure changes we did in bufbuild/protovalidate-go#173. The primary goal of this PR is to reduce the surface area of incidental public API. We don't want to expose our internal logic since it is very likely to be refactored in incompatible ways, but many things in the `internal` package are currently publicly accessible.
1 parent 229c084 commit 967e898

36 files changed

+57
-116
lines changed
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package build.buf.protovalidate.internal.evaluator;
15+
package build.buf.protovalidate;
1616

1717
import build.buf.protovalidate.exceptions.ExecutionException;
18-
import build.buf.protovalidate.internal.errors.ConstraintViolation;
19-
import build.buf.protovalidate.internal.errors.FieldPathUtils;
2018
import build.buf.validate.AnyRules;
2119
import build.buf.validate.FieldConstraints;
2220
import build.buf.validate.FieldPath;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package build.buf.protovalidate.internal.expression;
15+
package build.buf.protovalidate;
1616

1717
import build.buf.protovalidate.exceptions.CompilationException;
1818
import com.google.api.expr.v1alpha1.Type;
1919
import org.projectnessie.cel.Ast;
2020
import org.projectnessie.cel.Env;
2121

2222
/** {@link AstExpression} is a compiled CEL {@link Ast}. */
23-
public class AstExpression {
23+
class AstExpression {
2424
/** The compiled CEL AST. */
2525
public final Ast ast;
2626

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package build.buf.protovalidate.internal.evaluator;
15+
package build.buf.protovalidate;
1616

1717
import build.buf.protovalidate.exceptions.ExecutionException;
18-
import build.buf.protovalidate.internal.errors.ConstraintViolation;
19-
import build.buf.protovalidate.internal.errors.FieldPathUtils;
20-
import build.buf.protovalidate.internal.expression.CompiledProgram;
21-
import build.buf.protovalidate.internal.expression.Variable;
2218
import java.util.ArrayList;
2319
import java.util.List;
2420
import javax.annotation.Nullable;
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package build.buf.protovalidate.internal.expression;
15+
package build.buf.protovalidate;
1616

1717
import build.buf.protovalidate.exceptions.ExecutionException;
18-
import build.buf.protovalidate.internal.errors.ConstraintViolation;
19-
import build.buf.protovalidate.internal.evaluator.Value;
2018
import build.buf.validate.FieldPath;
2119
import javax.annotation.Nullable;
2220
import org.projectnessie.cel.Program;
@@ -27,7 +25,7 @@
2725
* {@link CompiledProgram} is a parsed and type-checked {@link Program} along with the source {@link
2826
* Expression}.
2927
*/
30-
public class CompiledProgram {
28+
class CompiledProgram {
3129
/** A compiled CEL program that can be evaluated against a set of variable bindings. */
3230
private final Program program;
3331

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package build.buf.protovalidate.internal.constraints;
15+
package build.buf.protovalidate;
1616

17-
import build.buf.protovalidate.Config;
1817
import build.buf.protovalidate.exceptions.CompilationException;
19-
import build.buf.protovalidate.internal.errors.FieldPathUtils;
20-
import build.buf.protovalidate.internal.evaluator.ObjectValue;
21-
import build.buf.protovalidate.internal.evaluator.Value;
22-
import build.buf.protovalidate.internal.expression.AstExpression;
23-
import build.buf.protovalidate.internal.expression.CompiledProgram;
24-
import build.buf.protovalidate.internal.expression.Expression;
25-
import build.buf.protovalidate.internal.expression.Variable;
2618
import build.buf.validate.FieldConstraints;
2719
import build.buf.validate.FieldPath;
2820
import build.buf.validate.ValidateProto;
@@ -52,7 +44,7 @@
5244
import org.projectnessie.cel.interpreter.Activation;
5345

5446
/** A build-through cache for computed standard constraints. */
55-
public class ConstraintCache {
47+
class ConstraintCache {
5648
private static class CelRule {
5749
public final AstExpression astExpression;
5850
public final FieldDescriptor field;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package build.buf.protovalidate.internal.evaluator;
15+
package build.buf.protovalidate;
1616

1717
import build.buf.protovalidate.exceptions.CompilationException;
1818
import build.buf.validate.FieldConstraints;
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package build.buf.protovalidate.internal.errors;
15+
package build.buf.protovalidate;
1616

17-
import build.buf.protovalidate.Violation;
18-
import build.buf.protovalidate.internal.evaluator.Value;
1917
import build.buf.validate.FieldPath;
2018
import build.buf.validate.FieldPathElement;
2119
import com.google.protobuf.Descriptors;
@@ -31,7 +29,7 @@
3129
* {@link ConstraintViolation} contains all of the collected information about an individual
3230
* constraint violation.
3331
*/
34-
public class ConstraintViolation implements Violation {
32+
class ConstraintViolation implements Violation {
3533
/** Static value to return when there are no violations. */
3634
public static final List<Builder> NO_VIOLATIONS = new ArrayList<>();
3735

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package build.buf.protovalidate.internal.evaluator;
15+
package build.buf.protovalidate;
1616

17-
import build.buf.protovalidate.internal.errors.FieldPathUtils;
1817
import build.buf.validate.FieldPath;
1918
import build.buf.validate.FieldPathElement;
2019
import java.util.ArrayList;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package build.buf.protovalidate.internal.celext;
15+
package build.buf.protovalidate;
1616

1717
import com.google.api.expr.v1alpha1.Decl;
1818
import java.util.ArrayList;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package build.buf.protovalidate.internal.celext;
15+
package build.buf.protovalidate;
1616

1717
import com.google.common.base.Ascii;
1818
import com.google.common.base.Splitter;

0 commit comments

Comments
 (0)