Skip to content

Commit 6dee35f

Browse files
authored
Merge pull request #280 from gadget-inc/autocomponents-prep
Autocomponents prep
2 parents 82495aa + 7c72c7e commit 6dee35f

File tree

12 files changed

+58
-50
lines changed

12 files changed

+58
-50
lines changed

packages/api-client-core/spec/TestSchema.ts

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { AvailableSelection } from "../src/types.js";
2+
13
export type NestedThing = {
24
bool: boolean;
35
string: string;
@@ -45,34 +47,4 @@ export type TestSchema = {
4547
};
4648
};
4749

48-
export type AvailableTestSchemaSelection = {
49-
num?: boolean | null | undefined;
50-
str?: boolean | null | undefined;
51-
obj?: {
52-
test?: boolean | null | undefined;
53-
bool?: boolean | null | undefined;
54-
};
55-
optionalObj?: {
56-
test?: boolean | null | undefined;
57-
bool?: boolean | null | undefined;
58-
};
59-
list?: {
60-
title: boolean | null | undefined;
61-
};
62-
optionalList?: {
63-
title: boolean | null | undefined;
64-
};
65-
nested?: NestedThing;
66-
someConnection?: {
67-
edges?: {
68-
node?: {
69-
id: boolean | null | undefined;
70-
state: boolean | null | undefined;
71-
};
72-
};
73-
pageInfo?: {
74-
hasNextPage?: boolean | null | undefined;
75-
hasPreviousPage?: boolean | null | undefined;
76-
};
77-
};
78-
};
50+
export type AvailableTestSchemaSelection = AvailableSelection<TestSchema>;

packages/api-client-core/src/ModelManager.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@ import type { GadgetConnection } from "./GadgetConnection.js";
22
import type { GadgetRecord } from "./GadgetRecord.js";
33
import type { GadgetRecordList } from "./GadgetRecordList.js";
44

5+
export type AnyModelFinderMetadata = {
6+
operationName: string;
7+
modelApiIdentifier: string;
8+
defaultSelection: Record<string, any>;
9+
selectionType: any;
10+
optionsType: any;
11+
schemaType: any | null;
12+
};
13+
514
/**
615
* Object representing one model's API in a high level way
716
* This is a generic interface. Concrete ones are generated by Gadget, */
817
export interface AnyModelManager {
918
connection: GadgetConnection;
10-
findOne(id: string, options: any): Promise<GadgetRecord<any>>;
11-
maybeFindOne(id: string, options: any): Promise<GadgetRecord<any> | null>;
12-
findMany(options: any): Promise<GadgetRecordList<any>>;
13-
findFirst(options: any): Promise<GadgetRecord<any>>;
19+
findOne: ((id: string, options: any) => Promise<GadgetRecord<any>>) & AnyModelFinderMetadata;
20+
findMany: ((options: any) => Promise<GadgetRecordList<any>>) & AnyModelFinderMetadata;
21+
findFirst: ((options: any) => Promise<GadgetRecord<any>>) & AnyModelFinderMetadata;
1422
maybeFindFirst(options: any): Promise<GadgetRecord<any> | null>;
23+
maybeFindOne(id: string, options: any): Promise<GadgetRecord<any> | null>;
1524
}

packages/api-client-core/src/types.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,3 +697,30 @@ export type PaginateOptions = {
697697
last?: number | null;
698698
select?: AnySelection | InternalFieldSelection | null;
699699
};
700+
701+
/**
702+
* Convert a schema type into the type that a selection of it must extend
703+
*
704+
* Example Schema:
705+
*
706+
* {
707+
* foo: boolean;
708+
* bar?: string;
709+
* nested?: {
710+
* count: number
711+
* }
712+
* }
713+
*
714+
* Example available selection:
715+
*
716+
* {
717+
* foo?: boolean | null | undefined;
718+
* bar?: boolean | null | undefined;
719+
* nested?: {
720+
* count: boolean | null | undefined
721+
* }
722+
* }
723+
*/
724+
export type AvailableSelection<Schema> = Schema extends string | number | bigint | null | undefined
725+
? boolean | null | undefined
726+
: { [key in keyof Schema]?: AvailableSelection<Schema[key]> };

packages/react/spec/components/auth/SignedIn.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "@testing-library/jest-dom";
22
import { render } from "@testing-library/react";
33
import React from "react";
4-
import { SignedIn } from "../../../src/components/auth/SignedIn.js";
4+
import { SignedIn } from "../../../src/auth/SignedIn.js";
55
import { superAuthApi } from "../../apis.js";
66
import { MockClientWrapper } from "../../testWrappers.js";
77
import { expectMockDeletedUser, expectMockSignedInUser, expectMockSignedOutUser } from "../../utils.js";

packages/react/spec/components/auth/SignedInOrRedirect.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "@testing-library/jest-dom";
22
import { render } from "@testing-library/react";
33
import React from "react";
4-
import { SignedInOrRedirect } from "../../../src/components/auth/SignedInOrRedirect.js";
4+
import { SignedInOrRedirect } from "../../../src/auth/SignedInOrRedirect.js";
55
import { superAuthApi } from "../../apis.js";
66
import { MockClientWrapper } from "../../testWrappers.js";
77
import { expectMockDeletedUser, expectMockSignedInUser, expectMockSignedOutUser } from "../../utils.js";

packages/react/spec/components/auth/SignedOut.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "@testing-library/jest-dom";
22
import { render } from "@testing-library/react";
33
import React from "react";
4-
import { SignedOut } from "../../../src/components/auth/SignedOut.js";
4+
import { SignedOut } from "../../../src/auth/SignedOut.js";
55
import { superAuthApi } from "../../apis.js";
66
import { MockClientWrapper } from "../../testWrappers.js";
77
import { expectMockDeletedUser, expectMockSignedInUser, expectMockSignedOutUser } from "../../utils.js";

packages/react/spec/components/auth/SignedOutOrRedirect.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "@testing-library/jest-dom";
22
import { render } from "@testing-library/react";
33
import React from "react";
4-
import { SignedOutOrRedirect } from "../../../src/components/auth/SignedOutOrRedirect.js";
4+
import { SignedOutOrRedirect } from "../../../src/auth/SignedOutOrRedirect.js";
55
import { superAuthApi } from "../../apis.js";
66
import { MockClientWrapper } from "../../testWrappers.js";
77
import { expectMockSignedInUser, expectMockSignedOutUser } from "../../utils.js";

packages/react/src/components/auth/SignedIn.tsx renamed to packages/react/src/auth/SignedIn.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ReactNode } from "react";
22
import React from "react";
3-
import { useAuth } from "../../auth/useAuth.js";
4-
import { isSessionSignedIn } from "../../auth/utils.js";
3+
import { useAuth } from "./useAuth.js";
4+
import { isSessionSignedIn } from "./utils.js";
55

66
/**
77
* Renders its `children` if the current `Session` is signed in (has an associated `User`), otherwise renders nothing.

packages/react/src/components/auth/SignedInOrRedirect.tsx renamed to packages/react/src/auth/SignedInOrRedirect.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ReactNode } from "react";
22
import React, { useContext, useEffect, useState } from "react";
3-
import { GadgetConfigurationContext } from "../../GadgetProvider.js";
4-
import { useAuth } from "../../auth/useAuth.js";
3+
import { GadgetConfigurationContext } from "../GadgetProvider.js";
4+
import { useAuth } from "./useAuth.js";
55

66
/**
77
* Renders its `children` if the current `Session` is signed in, otherwise redirects the browser to the `signInPath` configured in the `Provider`. Uses `window.location.assign` to perform the redirect.

packages/react/src/components/auth/SignedOut.tsx renamed to packages/react/src/auth/SignedOut.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ReactNode } from "react";
22
import React from "react";
3-
import { useAuth } from "../../auth/useAuth.js";
4-
import { isSessionSignedOut } from "../../auth/utils.js";
3+
import { useAuth } from "./useAuth.js";
4+
import { isSessionSignedOut } from "./utils.js";
55

66
/**
77
* Renders its `children` if the current `Session` is signed out (no associated `User`), otherwise renders nothing.

0 commit comments

Comments
 (0)