Skip to content

Commit 64a9b88

Browse files
Remove JsonValidator export (#25381)
## Description Remove obsolete JsonValidator Alpha API in tree. ## Breaking Changes Users must migrate as described in changeset.
1 parent 3e68160 commit 64a9b88

40 files changed

+129
-157
lines changed

.changeset/proud-candles-bake.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"fluid-framework": minor
3+
"@fluidframework/tree": minor
4+
"__section": tree
5+
---
6+
Remove JsonValidator
7+
8+
The `@alpha` API `JsonValidator` has been removed: its replacement `FormatValidator` must now be used.
9+
10+
As part of this:
11+
- `typeboxValidator` has been replaced with `FormatValidatorBasic`.
12+
- `noopValidator` has been replaced with `FormatValidatorNoOp`.

examples/apps/tree-cli-app/src/test/schema.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
comparePersistedSchema,
1010
extractPersistedSchema,
1111
FluidClientVersion,
12-
typeboxValidator,
12+
FormatValidatorBasic,
1313
type ForestOptions,
1414
type ICodecOptions,
1515
type ImplicitFieldSchema,
@@ -128,7 +128,7 @@ describe("schema", () => {
128128
});
129129

130130
describe("historical schema can be upgraded to current schema", () => {
131-
const options: ForestOptions & ICodecOptions = { jsonValidator: typeboxValidator };
131+
const options: ForestOptions & ICodecOptions = { jsonValidator: FormatValidatorBasic };
132132

133133
for (let documentIndex = 0; documentIndex < historicalSchema.length; documentIndex++) {
134134
for (let viewIndex = 0; viewIndex < historicalSchema.length; viewIndex++) {

examples/apps/tree-cli-app/src/utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
extractPersistedSchema,
2222
FluidClientVersion,
2323
independentInitializedView,
24-
typeboxValidator,
24+
FormatValidatorBasic,
2525
type ForestOptions,
2626
type ICodecOptions,
2727
type JsonCompatible,
@@ -72,7 +72,9 @@ export function loadDocument(source: string | undefined): List {
7272
});
7373
}
7474
case "compressed": {
75-
return TreeAlpha.importCompressed(List, fileData, { jsonValidator: typeboxValidator });
75+
return TreeAlpha.importCompressed(List, fileData, {
76+
jsonValidator: FormatValidatorBasic,
77+
});
7678
}
7779
case "snapshot": {
7880
// TODO: This should probably do a validating parse of the data (probably using type box) rather than just casting it.
@@ -249,7 +251,7 @@ export function rejectHandles(key: string, value: unknown): unknown {
249251
return value;
250252
}
251253

252-
const options: ForestOptions & ICodecOptions = { jsonValidator: typeboxValidator };
254+
const options: ForestOptions & ICodecOptions = { jsonValidator: FormatValidatorBasic };
253255

254256
const File = Type.Object({
255257
tree: Type.Unsafe<JsonCompatible<IFluidHandle>>(),

packages/dds/tree/api-report/tree.alpha.api.md

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ export type HandleConverter<TCustom> = (data: IFluidHandle) => TCustom;
314314

315315
// @alpha @input
316316
export interface ICodecOptions {
317-
readonly jsonValidator: JsonValidator | FormatValidator;
317+
readonly jsonValidator: FormatValidator;
318318
}
319319

320320
// @alpha
@@ -552,11 +552,6 @@ export type JsonTreeSchema = JsonFieldSchema & {
552552
readonly $defs: Record<JsonSchemaId, JsonNodeSchema>;
553553
};
554554

555-
// @alpha @input
556-
export interface JsonValidator {
557-
compile<Schema extends TSchema>(schema: Schema): SchemaValidationFunction<Schema>;
558-
}
559-
560555
// @alpha @input
561556
export enum KeyEncodingOptions {
562557
allStoredKeys = "allStoredKeys",
@@ -655,9 +650,6 @@ export interface NodeSchemaOptionsAlpha<out TCustomMetadata = unknown> extends N
655650
readonly persistedMetadata?: JsonCompatibleReadOnlyObject | undefined;
656651
}
657652

658-
// @alpha
659-
export const noopValidator: JsonValidator;
660-
661653
// @alpha @sealed
662654
export interface NormalizedAnnotatedAllowedTypes extends AnnotatedAllowedTypes<TreeNodeSchema> {
663655
}
@@ -916,11 +908,6 @@ export class SchemaUpgrade {
916908
protected _typeCheck: MakeNominal;
917909
}
918910

919-
// @alpha @input
920-
export interface SchemaValidationFunction<Schema extends TSchema> {
921-
check(data: unknown): data is Static<Schema>;
922-
}
923-
924911
// @public @system
925912
type ScopedSchemaName<TScope extends string | undefined, TName extends number | string> = TScope extends undefined ? `${TName}` : `${TScope}.${TName}`;
926913

@@ -1573,9 +1560,6 @@ export interface TreeViewEvents {
15731560
schemaChanged(): void;
15741561
}
15751562

1576-
// @alpha
1577-
export const typeboxValidator: JsonValidator;
1578-
15791563
// @public @deprecated @system
15801564
const typeNameSymbol: unique symbol;
15811565

packages/dds/tree/src/codec/codec.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type { Static, TAnySchema, TSchema } from "@sinclair/typebox";
1010

1111
import type { ChangeEncodingContext } from "../core/index.js";
1212
import type { JsonCompatibleReadOnly } from "../util/index.js";
13-
import { noopValidator } from "./noopValidator.js";
1413

1514
/**
1615
* Translates decoded data to encoded data.
@@ -37,7 +36,6 @@ export interface IDecoder<TDecoded, TEncoded, TContext> {
3736
/**
3837
* Validates data complies with some particular schema.
3938
* Implementations are typically created by a {@link JsonValidator}.
40-
* @alpha @input
4139
*/
4240
export interface SchemaValidationFunction<Schema extends TSchema> {
4341
/**
@@ -66,6 +64,15 @@ export interface SchemaValidationFunction<Schema extends TSchema> {
6664
*/
6765
export interface FormatValidator extends ErasedType<"FormatValidator"> {}
6866

67+
/**
68+
* A {@link JsonValidator} implementation which performs no validation and accepts all data as valid.
69+
* @privateRemarks Having this as an option unifies opting out of validation with selection of
70+
* validators, simplifying code performing validation.
71+
*/
72+
const noopValidator: JsonValidator = {
73+
compile: <Schema extends TSchema>() => ({ check: (data): data is Static<Schema> => true }),
74+
};
75+
6976
/**
7077
* A {@link FormatValidator} which does no validation.
7178
* @alpha
@@ -122,11 +129,10 @@ export interface ICodecOptions {
122129
* SharedTree users are still encouraged to use a non-trivial validator (i.e. not `FormatValidatorNoOp`)
123130
* whenever reasonable: it gives better fail-fast behavior when unexpected encoded data is found,
124131
* which reduces the risk of unrecoverable data corruption.
125-
*
126-
* Use of {@link JsonValidator} here is deprecated and will be removed:
127-
* it is recommended to use {@link FormatValidator} instead.
132+
* @privateRemarks
133+
* This property should probably be renamed to `validator` before stabilizing the API.
128134
*/
129-
readonly jsonValidator: JsonValidator | FormatValidator;
135+
readonly jsonValidator: FormatValidator;
130136
}
131137

132138
/**

packages/dds/tree/src/codec/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export {
3131
type DiscriminatedUnionLibrary,
3232
unionOptions,
3333
} from "./discriminatedUnions.js";
34-
export { noopValidator } from "./noopValidator.js";
3534
export {
3635
Versioned,
3736
makeVersionedCodec,

packages/dds/tree/src/codec/noopValidator.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/dds/tree/src/core/tree/detachedFieldIndex.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import type { IIdCompressor } from "@fluidframework/id-compressor";
99
import {
1010
type CodecWriteOptions,
1111
FluidClientVersion,
12+
FormatValidatorNoOp,
1213
type IJsonCodec,
13-
noopValidator,
1414
} from "../../codec/index.js";
1515
import {
1616
type IdAllocator,
@@ -83,7 +83,7 @@ export class DetachedFieldIndex {
8383
options?: CodecWriteOptions,
8484
) {
8585
this.options = options ?? {
86-
jsonValidator: noopValidator,
86+
jsonValidator: FormatValidatorNoOp,
8787
oldestCompatibleClient: FluidClientVersion.v2_0,
8888
};
8989
this.codec = makeDetachedFieldIndexCodec(revisionTagCodec, this.options, idCompressor);

packages/dds/tree/src/external-utilities/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
* Licensed under the MIT License.
44
*/
55

6-
export { typeboxValidator, FormatValidatorBasic } from "./typeboxValidator.js";
6+
export { FormatValidatorBasic } from "./typeboxValidator.js";

packages/dds/tree/src/external-utilities/typeboxValidator.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ import { toFormatValidator, type JsonValidator } from "../codec/index.js";
1818
* (i.e. a JSON validator is only included in an application's bundle if that application references it).
1919
*
2020
* Defining this validator in its own file also helps to ensure it is tree-shakeable.
21-
*
22-
* @alpha
2321
*/
24-
export const typeboxValidator: JsonValidator = {
22+
const typeboxValidator: JsonValidator = {
2523
compile: <Schema extends TSchema>(schema: Schema) => {
2624
const compiledFormat = TypeCompiler.Compile(schema);
2725
return {

0 commit comments

Comments
 (0)