Skip to content
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

tree: Allow array from map and map from array #22036

Merged
merged 8 commits into from
Jul 26, 2024

Conversation

CraigMacomber
Copy link
Contributor

@CraigMacomber CraigMacomber commented Jul 26, 2024

Description

Allow constructing ArrayNodes from Maps and MapNodes from arrays when unambiguous.

Also removes some no longer needed shallow copies in the map and array constructors .

See changeset for details.

Reviewer Guidance

The review process is outlined on this wiki page.

@CraigMacomber CraigMacomber requested review from a team as code owners July 26, 2024 17:42
Copy link

changeset-bot bot commented Jul 26, 2024

🦋 Changeset detected

Latest commit: cb30d7f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 157 packages
Name Type
@fluidframework/tree Major
fluid-framework Major
@fluid-example/tree-comparison Major
@fluid-example/bubblebench-shared-tree Major
@fluid-internal/tablebench Major
@fluid-example/inventory-app Major
@fluid-example/bundle-size-tests Major
@fluid-example/tree-shim Major
@fluid-experimental/property-shared-tree-interop Major
@fluid-experimental/tree Major
@fluid-experimental/tree-react-api Major
@fluidframework/fluid-telemetry Major
@fluidframework/azure-client Major
@fluidframework/azure-end-to-end-tests Major
@fluid-internal/functional-tests Major
@fluid-private/test-end-to-end-tests Major
@fluidframework/devtools-core Major
@fluid-example/devtools-example Major
@fluid-example/presence-tracker Major
@fluid-example/app-integration-external-controller Major
@fluid-example/shared-tree-demo Major
@fluid-example/bubblebench-common Major
@fluid-example/bubblebench-experimental-tree Major
@fluid-internal/devtools-browser-extension Major
@fluid-internal/devtools-view Major
@fluidframework/devtools Major
@fluid-example/bubblebench-baseline Major
@fluid-example/bubblebench-ot Major
@fluid-example/attributable-map Major
@fluid-example/collaborative-textarea Major
@fluid-example/contact-collection Major
@fluid-example/data-object-grid Major
@fluid-example/task-selection Major
@fluid-example/odspsnapshotfetch-perftestapp Major
@fluid-example/app-insights-logger Major
@fluid-example/canvas Major
@fluid-example/clicker Major
@fluid-example/codemirror Major
@fluid-example/diceroller Major
@fluid-example/monaco Major
@fluid-example/multiview-constellation-model Major
@fluid-example/multiview-constellation-view Major
@fluid-example/multiview-container Major
@fluid-example/multiview-coordinate-model Major
@fluid-example/multiview-coordinate-interface Major
@fluid-example/multiview-plot-coordinate-view Major
@fluid-example/multiview-slider-coordinate-view Major
@fluid-example/multiview-triangle-view Major
@fluid-example/prosemirror Major
@fluid-example/smde Major
@fluid-example/table-document Major
@fluid-example/todo Major
@fluid-example/webflow Major
@fluid-example/app-integration-external-data Major
@fluid-example/example-utils Major
@fluid-example/webpack-fluid-loader Major
@fluid-example/app-integration-live-schema-upgrade Major
@fluid-example/version-migration-same-container Major
@fluid-example/app-integration-schema-upgrade Major
@fluid-example/app-integration-container-views Major
@fluid-example/app-integration-external-views Major
@fluid-example/view-framework-sampler Major
@fluid-example/property-inspector Major
@fluid-example/schemas Major
@fluid-experimental/azure-scenario-runner Major
@fluid-experimental/property-binder Major
@fluid-experimental/property-changeset Major
@fluid-experimental/property-common Major
@fluid-experimental/property-dds Major
@fluid-experimental/property-inspector-table Major
@fluid-experimental/property-properties Major
@fluid-experimental/property-proxy Major
@fluid-experimental/property-query Major
@fluid-experimental/attributable-map Major
@fluid-experimental/ot Major
@fluid-experimental/sharejs-json1 Major
@fluid-experimental/sequence-deprecated Major
@fluid-experimental/data-objects Major
@fluid-experimental/last-edited Major
@fluid-experimental/ink Major
@fluid-experimental/pact-map Major
@fluid-experimental/attributor Major
@fluid-experimental/data-object-base Major
@fluid-experimental/dds-interceptions Major
@fluid-experimental/oldest-client-observer Major
@fluid-experimental/odsp-end-to-end-tests Major
@fluid-internal/platform-dependent Major
@fluid-internal/client-utils Major
@fluid-internal/local-server-tests Major
@fluid-internal/mocha-test-setup Major
@fluid-internal/test-snapshots Major
@fluid-internal/test-app-insights-logger Major
@fluid-internal/test-driver-definitions Major
@fluid-internal/test-service-load Major
@fluid-internal/replay-tool Major
@fluid-private/test-dds-utils Major
@fluid-private/test-loader-utils Major
@fluid-private/stochastic-test-utils Major
@fluid-private/test-drivers Major
@fluid-private/test-pairwise-generator Major
@fluid-private/test-version-utils Major
@fluid-private/changelog-generator-wrapper Major
@fluid-tools/fetch-tool Major
@fluid-tools/markdown-magic Major
@fluidframework/azure-local-service Major
@fluidframework/azure-service-utils Major
@fluidframework/container-definitions Major
@fluidframework/core-interfaces Major
@fluidframework/core-utils Major
@fluidframework/driver-definitions Major
@fluidframework/cell Major
@fluidframework/counter Major
@fluidframework/map Major
@fluidframework/matrix Major
@fluidframework/merge-tree Major
@fluidframework/ordered-collection Major
@fluidframework/register-collection Major
@fluidframework/sequence Major
@fluidframework/shared-object-base Major
@fluidframework/shared-summary-block Major
@fluidframework/task-manager Major
@fluidframework/debugger Major
@fluidframework/driver-base Major
@fluidframework/driver-web-cache Major
@fluidframework/file-driver Major
@fluidframework/local-driver Major
@fluidframework/odsp-driver-definitions Major
@fluidframework/odsp-driver Major
@fluidframework/odsp-urlresolver Major
@fluidframework/replay-driver Major
@fluidframework/routerlicious-driver Major
@fluidframework/routerlicious-urlresolver Major
@fluidframework/tinylicious-driver Major
@fluidframework/agent-scheduler Major
@fluidframework/aqueduct Major
@fluidframework/app-insights-logger Major
@fluidframework/fluid-static Major
@fluidframework/request-handler Major
@fluidframework/synthesize Major
@fluidframework/undo-redo Major
@fluidframework/container-loader Major
@fluidframework/driver-utils Major
@fluidframework/container-runtime-definitions Major
@fluidframework/container-runtime Major
@fluidframework/datastore-definitions Major
@fluidframework/datastore Major
@fluidframework/id-compressor Major
@fluidframework/runtime-definitions Major
@fluidframework/runtime-utils Major
@fluidframework/test-runtime-utils Major
@fluidframework/odsp-client Major
@fluidframework/tinylicious-client Major
@fluidframework/test-utils Major
@fluidframework/fluid-runner Major
@fluidframework/odsp-doclib-utils Major
@fluidframework/telemetry-utils Major
@fluidframework/tool-utils Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added area: dds Issues related to distributed data structures area: dds: tree changeset-present base: main PRs targeted against main branch labels Jul 26, 2024
.changeset/moody-toys-dance.md Outdated Show resolved Hide resolved
.changeset/moody-toys-dance.md Outdated Show resolved Hide resolved
it should work, even if those iterables are themselves arrays or maps.
To avoid this being a breaking change, a priority systems was introduced.
ArrayNodes will only be implicitly constructable from JavaScript Map objects in contexts where no MapNodes are allowed.
Similarly MapNodes will only be implicitly constructable from JavaScript Array objects in contexts where no ArrayNodes are allowed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we improve upon this even more in the future? You could have e.g. Map<string, string> | Array<string>, and we would be able to tell the difference between the two for an input like [string] (array) or [[string, string]] (map), so long as the array isn't empty. Or, is that too subtle of an edge case that it will confuse users, and it's better to simply keep the dividing line as it is? I'm inclined to think that it's too subtle, but I'm curious what you think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. You can't tell as [string, string][] from a number[] in the case where they are empty, so in general we can't do that general improvement always, but we can do some cases of it (ex: all non-empty cases) in the future, and doing so will be a non-breaking change since it would convert cases which were ambiguous to working, and cases which had type errors on the children to type errors on the parent. Both those changes will be allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the kind of change you mention (being more picky, causing error higher up the tree and less ambiguity) is generally safe, where the change I made here (allowing more options) is prone to causing new ambiguity issues which is what needed the extra care and priority thing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good observation, that makes sense. Thank you.

/**
* Indicates a compatibility level for inferring a schema to apply to insertable data.
* @remarks
* Only the highest compatibility options are used.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Only the highest compatibility options are used.
* Only the highest quality compatibility options are used. Here at `getPossibleTypes` we pride ourselves on bringing the freshest options direct to you for a fraction of the cogs of our competitors. We stand by our enums - if you are dissatisfied* in any way, your `allowedTypes` and `data` will be returned to you free of charge and unmutated. [* Satisfaction only guaranteed after TS 4.9](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-9.html#the-satisfies-operator)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your explanation is inaccurate. The quality here is relative, so when low is the highest quality available, we still use it, which could invalidate such a guarantee.

/**
* Not compatible. Constructor typing indicates incompatibility.
*/
None = 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "lower compatibility levels" that might be added in the future would be "between" None and Low, right? Should we adjust the numeric enum values to reflect that, so there is room to add the future values? E.g.

None = 0, Lower = 253, Low = 254, Normal = 255

Or maybe we can use 0.5 for Lower, lol.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can always change these values in the future (this is not a public const enum: its neither public nor const), not to mention there are a lot of numbers between 0 and 1.

@msfluid-bot
Copy link
Collaborator

msfluid-bot commented Jul 26, 2024

@fluid-example/bundle-size-tests: +1023 Bytes
Metric NameBaseline SizeCompare SizeSize Diff
aqueduct.js 457.99 KB 458.02 KB +35 Bytes
azureClient.js 555.23 KB 555.28 KB +49 Bytes
connectionState.js 680 Bytes 680 Bytes No change
containerRuntime.js 258.67 KB 258.68 KB +14 Bytes
fluidFramework.js 408.64 KB 409.03 KB +403 Bytes
loader.js 134.04 KB 134.05 KB +14 Bytes
map.js 42.13 KB 42.14 KB +7 Bytes
matrix.js 146.41 KB 146.42 KB +7 Bytes
odspClient.js 523.37 KB 523.42 KB +49 Bytes
odspDriver.js 97.55 KB 97.57 KB +21 Bytes
odspPrefetchSnapshot.js 42.61 KB 42.62 KB +14 Bytes
sharedString.js 163.13 KB 163.14 KB +7 Bytes
sharedTree.js 399.15 KB 399.54 KB +396 Bytes
Total Size 3.3 MB 3.3 MB +1023 Bytes

Baseline commit: 5797dc1

Generated by 🚫 dangerJS against cb30d7f

@CraigMacomber CraigMacomber enabled auto-merge (squash) July 26, 2024 20:04
@CraigMacomber CraigMacomber disabled auto-merge July 26, 2024 22:00
Copy link
Contributor

@alexvy86 alexvy86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changeset is great, just pending a fix for a missing triple-backtick.

@CraigMacomber CraigMacomber enabled auto-merge (squash) July 26, 2024 22:09
@CraigMacomber CraigMacomber merged commit 25e74f9 into microsoft:main Jul 26, 2024
30 checks passed
@CraigMacomber CraigMacomber deleted the fromIterable branch July 26, 2024 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: dds: tree area: dds Issues related to distributed data structures base: main PRs targeted against main branch changeset-present
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants