-
Notifications
You must be signed in to change notification settings - Fork 541
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
Move Json domain from test to internal #23043
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cb302e1
Export Json domain as alpha
CraigMacomber b290fd9
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
CraigMacomber 82787cc
Remove unintended changes from move
CraigMacomber cdeaf7c
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
CraigMacomber 2e68c73
Mostly Fix merge
CraigMacomber eed648e
Fix recursive array workaround
CraigMacomber 87d4020
Seal schema classes
CraigMacomber 6df8dc2
fix lint
CraigMacomber 62907d7
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
CraigMacomber abc688c
use type instead of const for FixRecursiveArraySchema
CraigMacomber 3c78e63
fix test
CraigMacomber 6ae8b59
Update packages/dds/tree/src/jsonDomainSchema.ts
CraigMacomber 68e1645
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
CraigMacomber 0fafe76
Move to internal
CraigMacomber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import { | ||
SchemaFactory, | ||
type AllowedTypes, | ||
type FixRecursiveArraySchema, | ||
type TreeNodeFromImplicitAllowedTypes, | ||
type ValidateRecursiveSchema, | ||
} from "./simple-tree/index.js"; | ||
|
||
const sf = new SchemaFactory("com.fluidframework.json"); | ||
|
||
/** | ||
* {@link AllowedTypes} for primitives types allowed in JSON. | ||
* @alpha | ||
*/ | ||
export const JsonPrimitive = [ | ||
sf.null, | ||
sf.boolean, | ||
sf.number, | ||
sf.string, | ||
] as const satisfies AllowedTypes; | ||
|
||
/** | ||
* @alpha | ||
*/ | ||
export type JsonPrimitive = TreeNodeFromImplicitAllowedTypes<typeof JsonPrimitive>; | ||
|
||
/** | ||
* {@link AllowedTypes} for any content allowed in the JSON domain. | ||
* @example | ||
* ```typescript | ||
* const tree = TreeAlpha.importConcise(JsonUnion, { example: { nested: true }, value: 5 }); | ||
* ``` | ||
* @alpha | ||
*/ | ||
export const JsonUnion = [() => JsonObject, () => JsonArray, ...JsonPrimitive] as const; | ||
|
||
/** | ||
* @alpha | ||
*/ | ||
export type JsonUnion = TreeNodeFromImplicitAllowedTypes<typeof JsonUnion>; | ||
|
||
/** | ||
* Do not use. Exists only as a workaround for {@link https://github.com/microsoft/TypeScript/issues/59550} and {@link https://github.com/microsoft/rushstack/issues/4429}. | ||
* @system @alpha | ||
*/ | ||
export const _APIExtractorWorkaroundJsonObjectBase = sf.mapRecursive("object", JsonUnion); | ||
|
||
/** | ||
* Arbitrary JSON object as a {@link TreeNode}. | ||
* @remarks | ||
* API of the tree node is more aligned with an es6 map than a JS object using its properties like a map. | ||
* @example | ||
* ```typescript | ||
* // Due to TypeScript restrictions on recursive types, the constructor and be somewhat limiting. | ||
* const fromArray = new JsonObject([["a", 0]]); | ||
* // Using `importConcise` can work better for JSON data: | ||
* const imported = TreeAlpha.importConcise(JsonObject, { a: 0 }); | ||
* // Node API is like a Map: | ||
* const value = imported.get("a"); | ||
* ``` | ||
* @alpha | ||
*/ | ||
export class JsonObject extends _APIExtractorWorkaroundJsonObjectBase {} | ||
{ | ||
type _check = ValidateRecursiveSchema<typeof JsonObject>; | ||
} | ||
|
||
/** | ||
* D.ts bug workaround, see {@link FixRecursiveArraySchema}. | ||
* @privateRemarks | ||
* Normally this would reference JsonArray, but when combining this workaround with the other workaround, this has to reference the base type. | ||
* Testing for this has to be in a separate package, and is thus part of experimental/framework/tree-react-api/src/test/importer.spec.ts. | ||
* @system @alpha | ||
*/ | ||
export declare const _RecursiveArrayWorkaroundJsonArray: FixRecursiveArraySchema< | ||
typeof _APIExtractorWorkaroundJsonArrayBase | ||
>; | ||
|
||
/** | ||
* Do not use. Exists only as a workaround for {@link https://github.com/microsoft/TypeScript/issues/59550} and {@link https://github.com/microsoft/rushstack/issues/4429}. | ||
* @system @alpha | ||
*/ | ||
export const _APIExtractorWorkaroundJsonArrayBase = sf.arrayRecursive("array", JsonUnion); | ||
|
||
/** | ||
* Arbitrary JSON object as a {@link TreeNode}. | ||
* @remarks | ||
* This can be worked around by using {@link TreeAlpha.importConcise}. | ||
* @example | ||
* ```typescript | ||
* // Due to TypeScript restrictions on recursive types, the constructor and be somewhat limiting. | ||
CraigMacomber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* const usingConstructor = new JsonArray(["a", 0, new JsonArray([1])]); | ||
* // Using `importConcise` can work better for JSON data: | ||
* const imported = TreeAlpha.importConcise(JsonArray, ["a", 0, [1]]); | ||
* // Node API is like an Array: | ||
* const outer: JsonUnion = imported[0]; | ||
* assert(Tree.is(outer, JsonArray)); | ||
* const inner = outer[0]; | ||
* ``` | ||
* @alpha | ||
*/ | ||
export class JsonArray extends _APIExtractorWorkaroundJsonArrayBase {} | ||
{ | ||
type _check = ValidateRecursiveSchema<typeof JsonArray>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My vote would be to call this
Json
orJsonTree
. The term "Union", while correct, is more mechanical than it is semantic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think having a top level package export called Json is a great idea. JS already has JSON, and our package has lots of Json related stuff other than this. JsonTree also seems questionable as VerboseTree and ConciseTree are both Json tree formats, and this is nothing like them. If changing this, I'd lean in the direction of making it more explicitly not named like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to be more careful / explicit with the naming, we could possibly do something like
JsonDomainTree
. I agree thatJsonUnion
doesn't really convey the semantics we want here.But of the existing suggestions, I like
JsonTree
the best personally.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think JsonDomain really does it either. Its perfectly reasonable to think of VerboseTree and ConciseTree as projections of trees into the JSON domain. This format on the other hand isn't even a JSON style object since it uses maps for objects.
Maybe
JsonAsTree
for JsonUnion, and JsonObjectAsTree for JsonObject?Another approach would be to go with a namespace. Since everything in it needs the same release tag, I think we can make that work. In that case maybe JsonDomain, with a big doc comment on the namespace, would work, then the members could have short names like Object, Union/Tree, Array, etc.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think namespaces will break re-exports in
fluid-framework
😕microsoft/rushstack#4807
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, well, maybe not, since we're generating our own rollups now. I'm not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I do like namespaces for things like this.
JsonAsTree
also seems reasonable to me.