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

Make isFluidHandle public #22029

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/smart-toys-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"fluid-framework": minor
"@fluidframework/runtime-utils": minor
---

Add `isFluidHandle` to check if an object is an `IFluidHandle`.

`isFluidHandle` is now exported and can be used to detect which objects are `IFluidHandle`s.
Since `IFluidHandle` often needs special handling (for example when serializing since its not JSON compatible),
having a dedicated detection function for it is handy.
Doing this detection was possible previously using the `tree` package's schema system via `Tree.is(value, new SchemaFactory("").handle)`,
but can now be done with just `isFluidHandle(value)`.
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ export interface IServiceAudienceEvents<M extends IMember> extends IEvent {
(event: "memberRemoved", listener: MemberChangedListener<M>): void;
}

// @public
export function isFluidHandle(value: unknown): value is IFluidHandle;

// @public
export type IsListener<TListener> = TListener extends (...args: any[]) => void ? true : false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,9 @@ export interface IServiceAudienceEvents<M extends IMember> extends IEvent {
(event: "memberRemoved", listener: MemberChangedListener<M>): void;
}

// @public
export function isFluidHandle(value: unknown): value is IFluidHandle;

// @alpha @sealed
export interface ISharedDirectory extends ISharedObject<ISharedDirectoryEvents & IDirectoryEvents>, Omit<IDirectory, "on" | "once" | "off"> {
// (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ export interface IServiceAudienceEvents<M extends IMember> extends IEvent {
(event: "memberRemoved", listener: MemberChangedListener<M>): void;
}

// @public
export function isFluidHandle(value: unknown): value is IFluidHandle;

// @public
export type IsListener<TListener> = TListener extends (...args: any[]) => void ? true : false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ export interface IServiceAudienceEvents<M extends IMember> extends IEvent {
(event: "memberRemoved", listener: MemberChangedListener<M>): void;
}

// @public
export function isFluidHandle(value: unknown): value is IFluidHandle;

// @public
export type IsListener<TListener> = TListener extends (...args: any[]) => void ? true : false;

Expand Down
1 change: 1 addition & 0 deletions packages/framework/fluid-framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"@fluidframework/driver-definitions": "workspace:~",
"@fluidframework/fluid-static": "workspace:~",
"@fluidframework/map": "workspace:~",
"@fluidframework/runtime-utils": "workspace:~",
"@fluidframework/sequence": "workspace:~",
"@fluidframework/shared-object-base": "workspace:~",
"@fluidframework/tree": "workspace:~"
Expand Down
2 changes: 2 additions & 0 deletions packages/framework/fluid-framework/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export type {
FluidObjectProviderKeys, // Used by FluidObject
} from "@fluidframework/core-interfaces";

export type { isFluidHandle } from "@fluidframework/runtime-utils";
Copy link
Member

Choose a reason for hiding this comment

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

This is a new export source for fluid-framework. @Josmithr do we need to make other config changes to ensure the docs are built correctly?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope :) API-Extractor in this package is configured to bundle all @fluidframework packages automatically (assuming they are correctly declared as a direct dependency, which this now is).

Copy link
Contributor

Choose a reason for hiding this comment

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

In this case you can tell because the actual declaration ends up in the API reports in this package, rather than appearing as a re-export from an external package.


// Let the tree package manage its own API surface, we will simply reflect it here.
// Note: this only surfaces the `@public` API items from the tree package. If the `@beta` and `@alpha` items are
// desired, they can be added by re-exporting from one of the package's aliased export paths instead (e.g. `tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

```ts

// @public
export function isFluidHandle(value: unknown): value is IFluidHandle;

// (No @packageDocumentation comment for this package)

```
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export abstract class FluidHandleBase<T> implements IFluidHandleInternal<T> {
abstract readonly isAttached: boolean;
}

// @public
export function isFluidHandle(value: unknown): value is IFluidHandle;

// @alpha
export class RequestParser implements IRequest {
protected constructor(request: Readonly<IRequest>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

```ts

// @public
export function isFluidHandle(value: unknown): value is IFluidHandle;

// (No @packageDocumentation comment for this package)

```
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

```ts

// @public
export function isFluidHandle(value: unknown): value is IFluidHandle;

// (No @packageDocumentation comment for this package)

```
4 changes: 2 additions & 2 deletions packages/runtime/runtime-utils/src/handles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export const isSerializedHandle = (value: any): value is ISerializedHandle =>
const enableBackwardsCompatibility = true;

/**
* Check if a value is an IFluidHandle.
* Check if a value is an {@link @fluidframework/core-interfaces#IFluidHandle}.
* @remarks
* Objects which have a field named `IFluidHandle` can in some cases produce a false positive.
* @internal
* @public
*/
export function isFluidHandle(value: unknown): value is IFluidHandle {
// `in` gives a type error on non-objects and null, so filter them out
Expand Down
127 changes: 3 additions & 124 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading