Skip to content

Commit

Permalink
enhance: Remove typing redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Dec 29, 2024
1 parent daff307 commit cb4fb92
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 85 deletions.
6 changes: 6 additions & 0 deletions .changeset/odd-numbers-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@data-client/endpoint': patch
'@data-client/rest': patch
---

Remove typing redundancy
13 changes: 0 additions & 13 deletions packages/endpoint/src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,19 +381,6 @@ export class Values<Choices extends Schema = any> implements SchemaClass {
): undefined;
}

export type CollectionArrayAdder<S extends PolymorphicInterface> =
S extends (
{
// ensure we are an array type
denormalize(...args: any): any[];
// get what we are an array of
schema: infer T;
}
) ?
// TODO: eventually we want to allow singular or list and infer the return based on arguments
T
: never;

export declare let CollectionRoot: CollectionConstructor;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ type CollectionOptions<Args extends any[] = DefaultArgs, Parent = any> = ({
nonFilterArgumentKeys?: ((key: string) => boolean) | string[] | RegExp;
});

type CollectionArrayAdder$1<S extends PolymorphicInterface> = S extends ({
type CollectionArrayAdder<S extends PolymorphicInterface> = S extends ({
denormalize(...args: any): any[];
schema: infer T;
}) ? T : never;
Expand Down Expand Up @@ -628,11 +628,11 @@ interface CollectionInterface<S extends PolymorphicInterface = any, Args extends
/** Schema to place at the *end* of this Collection
* @see https://dataclient.io/rest/api/Collection#push
*/
push: CollectionArrayAdder$1<S>;
push: CollectionArrayAdder<S>;
/** Schema to place at the *beginning* of this Collection
* @see https://dataclient.io/rest/api/Collection#unshift
*/
unshift: CollectionArrayAdder$1<S>;
unshift: CollectionArrayAdder<S>;
/** Schema to merge with a Values Collection
* @see https://dataclient.io/rest/api/Collection#assign
*/
Expand Down Expand Up @@ -997,19 +997,6 @@ declare class Values<Choices extends Schema = any> implements SchemaClass {
): undefined;
}

type CollectionArrayAdder<S extends PolymorphicInterface> =
S extends (
{
// ensure we are an array type
denormalize(...args: any): any[];
// get what we are an array of
schema: infer T;
}
) ?
// TODO: eventually we want to allow singular or list and infer the return based on arguments
T
: never;

declare let CollectionRoot: CollectionConstructor;

/**
Expand Down Expand Up @@ -1046,11 +1033,11 @@ type schema_d_Union<Choices extends EntityMap, SchemaAttribute extends
declare const schema_d_Union: typeof Union;
type schema_d_Values<Choices extends Schema = any> = Values<Choices>;
declare const schema_d_Values: typeof Values;
type schema_d_CollectionArrayAdder<S extends PolymorphicInterface> = CollectionArrayAdder<S>;
declare const schema_d_CollectionRoot: typeof CollectionRoot;
type schema_d_Collection<S extends any[] | PolymorphicInterface = any, Args extends any[] = DefaultArgs, Parent = any> = Collection<S, Args, Parent>;
declare const schema_d_Collection: typeof Collection;
type schema_d_EntityInterface<T = any> = EntityInterface<T>;
type schema_d_CollectionArrayAdder<S extends PolymorphicInterface> = CollectionArrayAdder<S>;
type schema_d_CollectionInterface<S extends PolymorphicInterface = any, Args extends any[] = any[], Parent = any> = CollectionInterface<S, Args, Parent>;
type schema_d_CollectionFromSchema<S extends any[] | PolymorphicInterface = any, Args extends any[] = DefaultArgs, Parent = any> = CollectionFromSchema<S, Args, Parent>;
type schema_d_CollectionConstructor = CollectionConstructor;
Expand All @@ -1076,10 +1063,10 @@ declare namespace schema_d {
schema_d_UnionRoot as UnionRoot,
schema_d_Union as Union,
schema_d_Values as Values,
schema_d_CollectionArrayAdder as CollectionArrayAdder,
schema_d_CollectionRoot as CollectionRoot,
schema_d_Collection as Collection,
schema_d_EntityInterface as EntityInterface,
schema_d_CollectionArrayAdder as CollectionArrayAdder,
schema_d_CollectionInterface as CollectionInterface,
schema_d_CollectionFromSchema as CollectionFromSchema,
schema_d_CollectionConstructor as CollectionConstructor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ type CollectionOptions<Args extends any[] = DefaultArgs, Parent = any> = ({
nonFilterArgumentKeys?: ((key: string) => boolean) | string[] | RegExp;
});

type CollectionArrayAdder$1<S extends PolymorphicInterface> = S extends ({
type CollectionArrayAdder<S extends PolymorphicInterface> = S extends ({
denormalize(...args: any): any[];
schema: infer T;
}) ? T : never;
Expand Down Expand Up @@ -628,11 +628,11 @@ interface CollectionInterface<S extends PolymorphicInterface = any, Args extends
/** Schema to place at the *end* of this Collection
* @see https://dataclient.io/rest/api/Collection#push
*/
push: CollectionArrayAdder$1<S>;
push: CollectionArrayAdder<S>;
/** Schema to place at the *beginning* of this Collection
* @see https://dataclient.io/rest/api/Collection#unshift
*/
unshift: CollectionArrayAdder$1<S>;
unshift: CollectionArrayAdder<S>;
/** Schema to merge with a Values Collection
* @see https://dataclient.io/rest/api/Collection#assign
*/
Expand Down Expand Up @@ -997,19 +997,6 @@ declare class Values<Choices extends Schema = any> implements SchemaClass {
): undefined;
}

type CollectionArrayAdder<S extends PolymorphicInterface> =
S extends (
{
// ensure we are an array type
denormalize(...args: any): any[];
// get what we are an array of
schema: infer T;
}
) ?
// TODO: eventually we want to allow singular or list and infer the return based on arguments
T
: never;

declare let CollectionRoot: CollectionConstructor;

/**
Expand Down Expand Up @@ -1046,11 +1033,11 @@ type schema_d_Union<Choices extends EntityMap, SchemaAttribute extends
declare const schema_d_Union: typeof Union;
type schema_d_Values<Choices extends Schema = any> = Values<Choices>;
declare const schema_d_Values: typeof Values;
type schema_d_CollectionArrayAdder<S extends PolymorphicInterface> = CollectionArrayAdder<S>;
declare const schema_d_CollectionRoot: typeof CollectionRoot;
type schema_d_Collection<S extends any[] | PolymorphicInterface = any, Args extends any[] = DefaultArgs, Parent = any> = Collection<S, Args, Parent>;
declare const schema_d_Collection: typeof Collection;
type schema_d_EntityInterface<T = any> = EntityInterface<T>;
type schema_d_CollectionArrayAdder<S extends PolymorphicInterface> = CollectionArrayAdder<S>;
type schema_d_CollectionInterface<S extends PolymorphicInterface = any, Args extends any[] = any[], Parent = any> = CollectionInterface<S, Args, Parent>;
type schema_d_CollectionFromSchema<S extends any[] | PolymorphicInterface = any, Args extends any[] = DefaultArgs, Parent = any> = CollectionFromSchema<S, Args, Parent>;
type schema_d_CollectionConstructor = CollectionConstructor;
Expand All @@ -1076,10 +1063,10 @@ declare namespace schema_d {
schema_d_UnionRoot as UnionRoot,
schema_d_Union as Union,
schema_d_Values as Values,
schema_d_CollectionArrayAdder as CollectionArrayAdder,
schema_d_CollectionRoot as CollectionRoot,
schema_d_Collection as Collection,
schema_d_EntityInterface as EntityInterface,
schema_d_CollectionArrayAdder as CollectionArrayAdder,
schema_d_CollectionInterface as CollectionInterface,
schema_d_CollectionFromSchema as CollectionFromSchema,
schema_d_CollectionConstructor as CollectionConstructor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ type CollectionOptions<Args extends any[] = DefaultArgs, Parent = any> = ({
nonFilterArgumentKeys?: ((key: string) => boolean) | string[] | RegExp;
});

type CollectionArrayAdder$1<S extends PolymorphicInterface> = S extends ({
type CollectionArrayAdder<S extends PolymorphicInterface> = S extends ({
denormalize(...args: any): any[];
schema: infer T;
}) ? T : never;
Expand Down Expand Up @@ -626,11 +626,11 @@ interface CollectionInterface<S extends PolymorphicInterface = any, Args extends
/** Schema to place at the *end* of this Collection
* @see https://dataclient.io/rest/api/Collection#push
*/
push: CollectionArrayAdder$1<S>;
push: CollectionArrayAdder<S>;
/** Schema to place at the *beginning* of this Collection
* @see https://dataclient.io/rest/api/Collection#unshift
*/
unshift: CollectionArrayAdder$1<S>;
unshift: CollectionArrayAdder<S>;
/** Schema to merge with a Values Collection
* @see https://dataclient.io/rest/api/Collection#assign
*/
Expand Down Expand Up @@ -995,19 +995,6 @@ declare class Values<Choices extends Schema = any> implements SchemaClass {
): undefined;
}

type CollectionArrayAdder<S extends PolymorphicInterface> =
S extends (
{
// ensure we are an array type
denormalize(...args: any): any[];
// get what we are an array of
schema: infer T;
}
) ?
// TODO: eventually we want to allow singular or list and infer the return based on arguments
T
: never;

declare let CollectionRoot: CollectionConstructor;

/**
Expand Down Expand Up @@ -1044,11 +1031,11 @@ type schema_d_Union<Choices extends EntityMap, SchemaAttribute extends
declare const schema_d_Union: typeof Union;
type schema_d_Values<Choices extends Schema = any> = Values<Choices>;
declare const schema_d_Values: typeof Values;
type schema_d_CollectionArrayAdder<S extends PolymorphicInterface> = CollectionArrayAdder<S>;
declare const schema_d_CollectionRoot: typeof CollectionRoot;
type schema_d_Collection<S extends any[] | PolymorphicInterface = any, Args extends any[] = DefaultArgs, Parent = any> = Collection<S, Args, Parent>;
declare const schema_d_Collection: typeof Collection;
type schema_d_EntityInterface<T = any> = EntityInterface<T>;
type schema_d_CollectionArrayAdder<S extends PolymorphicInterface> = CollectionArrayAdder<S>;
type schema_d_CollectionInterface<S extends PolymorphicInterface = any, Args extends any[] = any[], Parent = any> = CollectionInterface<S, Args, Parent>;
type schema_d_CollectionFromSchema<S extends any[] | PolymorphicInterface = any, Args extends any[] = DefaultArgs, Parent = any> = CollectionFromSchema<S, Args, Parent>;
type schema_d_CollectionConstructor = CollectionConstructor;
Expand All @@ -1074,10 +1061,10 @@ declare namespace schema_d {
schema_d_UnionRoot as UnionRoot,
schema_d_Union as Union,
schema_d_Values as Values,
schema_d_CollectionArrayAdder as CollectionArrayAdder,
schema_d_CollectionRoot as CollectionRoot,
schema_d_Collection as Collection,
schema_d_EntityInterface as EntityInterface,
schema_d_CollectionArrayAdder as CollectionArrayAdder,
schema_d_CollectionInterface as CollectionInterface,
schema_d_CollectionFromSchema as CollectionFromSchema,
schema_d_CollectionConstructor as CollectionConstructor,
Expand Down
23 changes: 5 additions & 18 deletions website/src/components/Playground/editor-types/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ type CollectionOptions<Args extends any[] = DefaultArgs, Parent = any> = ({
nonFilterArgumentKeys?: ((key: string) => boolean) | string[] | RegExp;
});

type CollectionArrayAdder$1<S extends PolymorphicInterface> = S extends ({
type CollectionArrayAdder<S extends PolymorphicInterface> = S extends ({
denormalize(...args: any): any[];
schema: infer T;
}) ? T : never;
Expand Down Expand Up @@ -630,11 +630,11 @@ interface CollectionInterface<S extends PolymorphicInterface = any, Args extends
/** Schema to place at the *end* of this Collection
* @see https://dataclient.io/rest/api/Collection#push
*/
push: CollectionArrayAdder$1<S>;
push: CollectionArrayAdder<S>;
/** Schema to place at the *beginning* of this Collection
* @see https://dataclient.io/rest/api/Collection#unshift
*/
unshift: CollectionArrayAdder$1<S>;
unshift: CollectionArrayAdder<S>;
/** Schema to merge with a Values Collection
* @see https://dataclient.io/rest/api/Collection#assign
*/
Expand Down Expand Up @@ -999,19 +999,6 @@ declare class Values<Choices extends Schema = any> implements SchemaClass {
): undefined;
}

type CollectionArrayAdder<S extends PolymorphicInterface> =
S extends (
{
// ensure we are an array type
denormalize(...args: any): any[];
// get what we are an array of
schema: infer T;
}
) ?
// TODO: eventually we want to allow singular or list and infer the return based on arguments
T
: never;

declare let CollectionRoot: CollectionConstructor;

/**
Expand Down Expand Up @@ -1048,11 +1035,11 @@ type schema_d_Union<Choices extends EntityMap, SchemaAttribute extends
declare const schema_d_Union: typeof Union;
type schema_d_Values<Choices extends Schema = any> = Values<Choices>;
declare const schema_d_Values: typeof Values;
type schema_d_CollectionArrayAdder<S extends PolymorphicInterface> = CollectionArrayAdder<S>;
declare const schema_d_CollectionRoot: typeof CollectionRoot;
type schema_d_Collection<S extends any[] | PolymorphicInterface = any, Args extends any[] = DefaultArgs, Parent = any> = Collection<S, Args, Parent>;
declare const schema_d_Collection: typeof Collection;
type schema_d_EntityInterface<T = any> = EntityInterface<T>;
type schema_d_CollectionArrayAdder<S extends PolymorphicInterface> = CollectionArrayAdder<S>;
type schema_d_CollectionInterface<S extends PolymorphicInterface = any, Args extends any[] = any[], Parent = any> = CollectionInterface<S, Args, Parent>;
type schema_d_CollectionFromSchema<S extends any[] | PolymorphicInterface = any, Args extends any[] = DefaultArgs, Parent = any> = CollectionFromSchema<S, Args, Parent>;
type schema_d_CollectionConstructor = CollectionConstructor;
Expand All @@ -1078,10 +1065,10 @@ declare namespace schema_d {
schema_d_UnionRoot as UnionRoot,
schema_d_Union as Union,
schema_d_Values as Values,
schema_d_CollectionArrayAdder as CollectionArrayAdder,
schema_d_CollectionRoot as CollectionRoot,
schema_d_Collection as Collection,
schema_d_EntityInterface as EntityInterface,
schema_d_CollectionArrayAdder as CollectionArrayAdder,
schema_d_CollectionInterface as CollectionInterface,
schema_d_CollectionFromSchema as CollectionFromSchema,
schema_d_CollectionConstructor as CollectionConstructor,
Expand Down

0 comments on commit cb4fb92

Please sign in to comment.