Skip to content

Commit

Permalink
Remove notstrict (#883)
Browse files Browse the repository at this point in the history
* remove notstrict

* alias

* add fix

* Remove comment

* add changeset'
  • Loading branch information
ssanjay1 authored Oct 18, 2024
1 parent 79fecf4 commit 749cf69
Show file tree
Hide file tree
Showing 37 changed files with 244 additions and 434 deletions.
7 changes: 7 additions & 0 deletions .changeset/kind-penguins-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@osdk/generator": patch
"@osdk/client": patch
"@osdk/api": patch
---

Remove experimental non null for now.
7 changes: 2 additions & 5 deletions etc/api.report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -629,15 +629,14 @@ export interface OntologyMetadata<_NEVER_USED_KEPT_FOR_BACKCOMPAT = any> {
// Warning: (ae-forgotten-export) The symbol "ExtractPropsKeysFromOldPropsStyle" needs to be exported by the entry point index.d.ts
//
// @public
export type Osdk<Q extends ObjectOrInterfaceDefinition, OPTIONS extends string = never, P extends PropertyKeys<Q> = PropertyKeys<Q>> = IsNever<OPTIONS> extends true ? Osdk.Instance<Q, never, P> : IsAny<OPTIONS> extends true ? Osdk.Instance<Q, never, P> : (IsNever<Exclude<OPTIONS, "$notStrict" | "$rid">>) extends true ? Osdk.Instance<Q, OPTIONS & ("$notStrict" | "$rid"), P> : Osdk.Instance<Q, ("$notStrict" extends OPTIONS ? "$notStrict" : never) | ("$rid" extends OPTIONS ? "$rid" : never), ExtractPropsKeysFromOldPropsStyle<Q, OPTIONS>>;
export type Osdk<Q extends ObjectOrInterfaceDefinition, OPTIONS extends string = never, P extends PropertyKeys<Q> = PropertyKeys<Q>> = IsNever<OPTIONS> extends true ? Osdk.Instance<Q, never, P> : IsAny<OPTIONS> extends true ? Osdk.Instance<Q, never, P> : (IsNever<Exclude<OPTIONS, "$rid">>) extends true ? Osdk.Instance<Q, OPTIONS & "$rid", P> : Osdk.Instance<Q, ("$rid" extends OPTIONS ? "$rid" : never), ExtractPropsKeysFromOldPropsStyle<Q, OPTIONS>>;

// @public (undocumented)
export namespace Osdk {
// Warning: (ae-forgotten-export) The symbol "GetProps" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "GetPropsKeys" needs to be exported by the entry point index.d.ts
//
// (undocumented)
export type Instance<Q extends ObjectOrInterfaceDefinition, OPTIONS extends never | "$notStrict" | "$rid" = never, P extends PropertyKeys<Q> = PropertyKeys<Q>> = OsdkBase<Q> & Pick<GetProps<Q, OPTIONS>, GetPropsKeys<Q, P>> & {
export type Instance<Q extends ObjectOrInterfaceDefinition, OPTIONS extends never | "$rid" = never, P extends PropertyKeys<Q> = PropertyKeys<Q>> = OsdkBase<Q> & Pick<CompileTimeMetadata<Q>["props"], GetPropsKeys<Q, P>> & {
readonly $link: Q extends {
linksType?: any;
} ? Q["linksType"] : Q extends ObjectTypeDefinition ? OsdkObjectLinksObject<Q> : never;
Expand Down Expand Up @@ -825,8 +824,6 @@ export type Result<V> = OkResult<V> | ErrorResult;

// @public (undocumented)
export interface SelectArg<Q extends ObjectOrInterfaceDefinition, L extends PropertyKeys<Q> = PropertyKeys<Q>, R extends boolean = false, S extends NullabilityAdherence = NullabilityAdherence.Default> {
// (undocumented)
$__EXPERIMENTAL_strictNonNull?: S;
// (undocumented)
$includeRid?: R;
// (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,25 @@ export namespace Employee {
}

export interface Props {
readonly class: $PropType['string'] | undefined;
readonly employeeId: $PropType['integer'] | undefined;
readonly employeeStatus: $PropType['numericTimeseries'] | undefined;
readonly fullName: $PropType['string'] | undefined;
readonly office: $PropType['integer'] | undefined;
readonly startDate: $PropType['datetime'] | undefined;
}
export interface StrictProps {
readonly class: $PropType['string'] | undefined;
readonly employeeId: $PropType['integer'];
readonly employeeStatus: $PropType['numericTimeseries'] | undefined;
readonly fullName: $PropType['string'] | undefined;
readonly office: $PropType['integer'] | undefined;
readonly startDate: $PropType['datetime'] | undefined;
}
export type StrictProps = Props;

export interface ObjectSet extends $ObjectSet<Employee, Employee.ObjectSet> {}

export type OsdkInstance<
OPTIONS extends never | '$notStrict' | '$rid' = never,
OPTIONS extends never | '$rid' = never,
K extends keyof Employee.Props = keyof Employee.Props,
> = $Osdk.Instance<Employee, OPTIONS, K>;

/** @deprecated use OsdkInstance */
export type OsdkObject<
OPTIONS extends never | '$notStrict' | '$rid' = never,
OPTIONS extends never | '$rid' = never,
K extends keyof Employee.Props = keyof Employee.Props,
> = OsdkInstance<OPTIONS, K>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,25 @@ export namespace Office {
export type Links = {};

export interface Props {
readonly entrance: $PropType['geopoint'] | undefined;
readonly meetingRoomCapacities: $PropType['integer'][] | undefined;
readonly meetingRooms: $PropType['string'][] | undefined;
readonly name: $PropType['string'] | undefined;
readonly occupiedArea: $PropType['geoshape'] | undefined;
readonly officeId: $PropType['string'] | undefined;
}
export interface StrictProps {
readonly entrance: $PropType['geopoint'] | undefined;
readonly meetingRoomCapacities: $PropType['integer'][] | undefined;
readonly meetingRooms: $PropType['string'][] | undefined;
readonly name: $PropType['string'] | undefined;
readonly occupiedArea: $PropType['geoshape'] | undefined;
readonly officeId: $PropType['string'];
}
export type StrictProps = Props;

export interface ObjectSet extends $ObjectSet<Office, Office.ObjectSet> {}

export type OsdkInstance<
OPTIONS extends never | '$notStrict' | '$rid' = never,
OPTIONS extends never | '$rid' = never,
K extends keyof Office.Props = keyof Office.Props,
> = $Osdk.Instance<Office, OPTIONS, K>;

/** @deprecated use OsdkInstance */
export type OsdkObject<
OPTIONS extends never | '$notStrict' | '$rid' = never,
OPTIONS extends never | '$rid' = never,
K extends keyof Office.Props = keyof Office.Props,
> = OsdkInstance<OPTIONS, K>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,22 @@ export namespace Todo {
export type Links = {};

export interface Props {
readonly id: $PropType['string'] | undefined;
readonly isComplete: $PropType['boolean'] | undefined;
readonly title: $PropType['string'] | undefined;
}
export interface StrictProps {
readonly id: $PropType['string'];
readonly isComplete: $PropType['boolean'] | undefined;
readonly title: $PropType['string'] | undefined;
}
export type StrictProps = Props;

export interface ObjectSet extends $ObjectSet<Todo, Todo.ObjectSet> {}

export type OsdkInstance<
OPTIONS extends never | '$notStrict' | '$rid' = never,
OPTIONS extends never | '$rid' = never,
K extends keyof Todo.Props = keyof Todo.Props,
> = $Osdk.Instance<Todo, OPTIONS, K>;

/** @deprecated use OsdkInstance */
export type OsdkObject<
OPTIONS extends never | '$notStrict' | '$rid' = never,
OPTIONS extends never | '$rid' = never,
K extends keyof Todo.Props = keyof Todo.Props,
> = OsdkInstance<OPTIONS, K>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,21 @@ export namespace equipment {
export type Links = {};

export interface Props {
readonly equipmentId: $PropType['string'] | undefined;
readonly type: $PropType['string'] | undefined;
}
export interface StrictProps {
readonly equipmentId: $PropType['string'];
readonly type: $PropType['string'] | undefined;
}
export type StrictProps = Props;

export interface ObjectSet extends $ObjectSet<equipment, equipment.ObjectSet> {}

export type OsdkInstance<
OPTIONS extends never | '$notStrict' | '$rid' = never,
OPTIONS extends never | '$rid' = never,
K extends keyof equipment.Props = keyof equipment.Props,
> = $Osdk.Instance<equipment, OPTIONS, K>;

/** @deprecated use OsdkInstance */
export type OsdkObject<
OPTIONS extends never | '$notStrict' | '$rid' = never,
OPTIONS extends never | '$rid' = never,
K extends keyof equipment.Props = keyof equipment.Props,
> = OsdkInstance<OPTIONS, K>;
}
Expand Down
49 changes: 26 additions & 23 deletions packages/api/src/OsdkObjectFrom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ describe("ExtractOptions", () => {
.toEqualTypeOf<never>();
});

it("does add add $notStrict for false", () => {
it("does not add $notStrict for false", () => {
expectTypeOf<ExtractOptions<any, false>>()
.toEqualTypeOf<"$notStrict">();
.toEqualTypeOf<never>();
});

it("does not add $notStrict for throw", () => {
Expand Down Expand Up @@ -140,9 +140,9 @@ describe("ExtractOptions", () => {
Osdk.Instance<quickAndDirty, never>
>();

// ensure its the strict type
// ensure its the normal props
expectTypeOf<Pick<toCheck, "name" | "foo">>().toEqualTypeOf<
quickAndDirty["__DefinitionMetadata"]["strictProps"]
quickAndDirty["__DefinitionMetadata"]["props"]
>();
});

Expand All @@ -151,9 +151,9 @@ describe("ExtractOptions", () => {
expectTypeOf<toCheck>().toEqualTypeOf<
Osdk.Instance<quickAndDirty, never>
>();
// ensure its the strict type
// ensure its the normal props
expectTypeOf<Pick<toCheck, "name" | "foo">>().toEqualTypeOf<
quickAndDirty["__DefinitionMetadata"]["strictProps"]
quickAndDirty["__DefinitionMetadata"]["props"]
>();
});

Expand All @@ -162,15 +162,18 @@ describe("ExtractOptions", () => {
expectTypeOf<toCheck>().branded.toEqualTypeOf<
Osdk.Instance<quickAndDirty, never>
>();
// ensure its the strict type
// ensure its the normal props
expectTypeOf<Pick<toCheck, "name" | "foo">>().toEqualTypeOf<
quickAndDirty["__DefinitionMetadata"]["strictProps"]
quickAndDirty["__DefinitionMetadata"]["props"]
>();
});

it("uses not strict if requested", () => {
it("Cannot use $notStrict", () => {
// @ts-expect-error
type toCheck = Osdk.Instance<quickAndDirty, "$notStrict">;

expectTypeOf<toCheck>().branded
// @ts-expect-error
.toEqualTypeOf<Osdk.Instance<quickAndDirty, "$notStrict">>();
// ensure its not the strict type
expectTypeOf<Pick<toCheck, "name" | "foo">>().toEqualTypeOf<
Expand Down Expand Up @@ -210,9 +213,9 @@ describe("ExtractOptions", () => {
// expect no rid
expectTypeOf<keyof toCheck & "$rid">().toEqualTypeOf<never>();

// ensure its the strict type
// ensure its the normal props
expectTypeOf<Pick<toCheck, "name" | "foo">>().toEqualTypeOf<
quickAndDirty["__DefinitionMetadata"]["strictProps"]
quickAndDirty["__DefinitionMetadata"]["props"]
>();
});

Expand All @@ -225,9 +228,9 @@ describe("ExtractOptions", () => {
// expect rid
expectTypeOf<keyof toCheck & "$rid">().toEqualTypeOf<"$rid">();

// ensure its the strict type
// ensure its the normal props
expectTypeOf<Pick<toCheck, "name" | "foo">>().toEqualTypeOf<
quickAndDirty["__DefinitionMetadata"]["strictProps"]
quickAndDirty["__DefinitionMetadata"]["props"]
>();
});

Expand Down Expand Up @@ -255,9 +258,9 @@ describe("ExtractOptions", () => {
// expect rid
expectTypeOf<keyof toCheck & "$rid">().toEqualTypeOf<"$rid">();

// ensure its the strict type
// ensure its the normal props
expectTypeOf<Pick<toCheck, "name" | "foo">>().toEqualTypeOf<
quickAndDirty["__DefinitionMetadata"]["strictProps"]
quickAndDirty["__DefinitionMetadata"]["props"]
>();
});

Expand All @@ -270,9 +273,9 @@ describe("ExtractOptions", () => {
// expect no rid
expectTypeOf<keyof toCheck & "$rid">().toEqualTypeOf<never>();

// ensure its the strict type
// ensure its the normal props
expectTypeOf<Pick<toCheck, "name" | "foo">>().toEqualTypeOf<
quickAndDirty["__DefinitionMetadata"]["strictProps"]
quickAndDirty["__DefinitionMetadata"]["props"]
>();
});

Expand All @@ -281,9 +284,9 @@ describe("ExtractOptions", () => {
expectTypeOf<toCheck>().toEqualTypeOf<
Osdk.Instance<quickAndDirty, never>
>();
// ensure its the strict type
// ensure its the normal props
expectTypeOf<Pick<toCheck, "name" | "foo">>().toEqualTypeOf<
quickAndDirty["__DefinitionMetadata"]["strictProps"]
quickAndDirty["__DefinitionMetadata"]["props"]
>();

// expect no rid
Expand All @@ -295,19 +298,19 @@ describe("ExtractOptions", () => {
expectTypeOf<toCheck>().branded.toEqualTypeOf<
Osdk.Instance<quickAndDirty, never>
>();
// ensure its the strict type
// ensure its the normal props
expectTypeOf<Pick<toCheck, "name" | "foo">>().toEqualTypeOf<
quickAndDirty["__DefinitionMetadata"]["strictProps"]
quickAndDirty["__DefinitionMetadata"]["props"]
>();

// expect no rid
expectTypeOf<keyof toCheck & "$rid">().toEqualTypeOf<never>();
});

it("uses not strict if requested", () => {
it("Does not use $notStrict if requested with old type", () => {
type toCheck = Osdk<quickAndDirty, "$notStrict">;
expectTypeOf<toCheck>().branded
.toEqualTypeOf<Osdk.Instance<quickAndDirty, "$notStrict">>();
.toEqualTypeOf<Osdk.Instance<quickAndDirty, never>>();
// ensure its not the strict type
expectTypeOf<Pick<toCheck, "name" | "foo">>().toEqualTypeOf<
quickAndDirty["__DefinitionMetadata"]["props"]
Expand Down
21 changes: 6 additions & 15 deletions packages/api/src/OsdkObjectFrom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,6 @@ export type GetPropsKeys<
: IsAny<P> extends true ? PropertyKeys<Q>
: P;

export type GetProps<
Q extends ObjectOrInterfaceDefinition,
OPTIONS extends never | "$notStrict" | "$rid" = never,
> = IsNever<OPTIONS> extends true ? CompileTimeMetadata<Q>["strictProps"]
: IsAny<OPTIONS> extends true ? CompileTimeMetadata<Q>["strictProps"]
: (OPTIONS extends "$notStrict" ? CompileTimeMetadata<Q>["props"]
: CompileTimeMetadata<Q>["strictProps"]);

/**
* Use `Osdk.Instance` or `YourType.OsdkInstance`
*/
Expand All @@ -178,26 +170,25 @@ export type Osdk<
IsNever<OPTIONS> extends true ? Osdk.Instance<Q, never, P>
: IsAny<OPTIONS> extends true ? Osdk.Instance<Q, never, P>
// Options only includes the two allowed in the new style
: (IsNever<Exclude<OPTIONS, "$notStrict" | "$rid">>) extends true
? Osdk.Instance<Q, OPTIONS & ("$notStrict" | "$rid"), P>
: (IsNever<Exclude<OPTIONS, "$rid">>) extends true
? Osdk.Instance<Q, OPTIONS & "$rid", P>
// else we are in the old style which was just Q and OPTIONS
// and OPTIONS was $things + prop names
: Osdk.Instance<
Q,
| ("$notStrict" extends OPTIONS ? "$notStrict" : never)
| ("$rid" extends OPTIONS ? "$rid" : never),
("$rid" extends OPTIONS ? "$rid" : never),
ExtractPropsKeysFromOldPropsStyle<Q, OPTIONS>
>;

export namespace Osdk {
export type Instance<
Q extends ObjectOrInterfaceDefinition,
OPTIONS extends never | "$notStrict" | "$rid" = never,
OPTIONS extends never | "$rid" = never,
P extends PropertyKeys<Q> = PropertyKeys<Q>,
> =
& OsdkBase<Q>
& Pick<
GetProps<Q, OPTIONS>,
CompileTimeMetadata<Q>["props"],
GetPropsKeys<Q, P>
>
& {
Expand Down Expand Up @@ -247,4 +238,4 @@ export type ExtractRidOption<R extends boolean> = // comment for readability
export type ExtractOptions<
R extends boolean,
S extends NullabilityAdherence = NullabilityAdherence.Default,
> = ExtractStrictOption<S> | ExtractRidOption<R>;
> = ExtractRidOption<R>;
1 change: 0 additions & 1 deletion packages/api/src/object/FetchPageArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export interface SelectArg<
> {
$select?: readonly L[];
$includeRid?: R;
$__EXPERIMENTAL_strictNonNull?: S;
}

export interface OrderByArg<
Expand Down
11 changes: 5 additions & 6 deletions packages/client/src/object/convertWireToOsdkObjects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,25 +515,24 @@ describe("Osdk.Instance", () => {
});

it("is assignable to Osdk<> with $notStrict", () => {
const instance: Osdk.Instance<Employee, "$notStrict"> = {} as any;
const instance: Osdk.Instance<Employee> = {} as any;
const osdk: Osdk<Employee, "$notStrict"> = instance;
const osdk2: Osdk<Employee, "$notStrict" | "$all"> = instance;
});

it("is assignable from Osdk<> with $notStrict", () => {
const osdk: Osdk<Employee, "$notStrict"> = {} as any;
const osdk2: Osdk<Employee, "$notStrict" | "$all"> = osdk;
const instance: Osdk.Instance<Employee, "$notStrict"> = osdk;
const instance2: Osdk.Instance<Employee, "$notStrict"> = osdk2;
const instance: Osdk.Instance<Employee> = osdk;
const instance2: Osdk.Instance<Employee> = osdk2;
});

it("object with any for props is assignable to its normal self", () => {
const foo: readonly Osdk.Instance<Employee, "$notStrict", any>[] =
{} as any;
const foo: readonly Osdk.Instance<Employee, never, any>[] = {} as any;

const bar: readonly Osdk.Instance<
Employee,
"$notStrict",
never,
PropertyKeys<Employee>
>[] = foo;
});
Expand Down
Loading

0 comments on commit 749cf69

Please sign in to comment.