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

Refactor: Package api #402

Open
wants to merge 9 commits into
base: bug/refactor_bullshit_code
Choose a base branch
from
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ circuit-cache/
#private
npm-token
.npmrc
package-lock.json
package-lock.json
public/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"clean": "find $(pwd) -name 'node_modules' -type d -exec rm -rf {} \\; || true && find $(pwd) -name 'build' -type d -exec rm -rf {} \\; || true",
"build": "yarn workspaces run build",
"clean-build": "yarn clean && yarn && yarn build",
"generate-docs": "spectaql spectaql-config.yml"
"gen:doc": "spectaql spectaql-config.yml"
},
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610",
"devDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
"license": "Apache-2.0",
"description": "",
"dependencies": {
"@apollo/client": "^3.10.6",
"@zkdb/common": "^0.1.1"
"@apollo/client": "^3.12.4",
"@zkdb/common": "^0.1.1",
"react": "^19.0.0"
},
"peerDependencies": {
"graphql": "^16.10.0"
Expand Down
1 change: 0 additions & 1 deletion packages/api/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export default {
plugins: [
alias({
entries: [
{ find: "@", replacement: "src" },
{ find: "@authentication", replacement: "src/authentication" },
{ find: "@graphql", replacement: "src/graphql" },
{ find: "@utils", replacement: "src/utils" },
Expand Down
12 changes: 0 additions & 12 deletions packages/api/src/graphql/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ import { collection } from "./collection";
import { collectionIndex } from "./collection-index";
import { database } from "./database";
import { document } from "./document";
import { environment } from "./environment";
import { group } from "./group";
import { merkle } from "./merkle";
import { metadata } from "./metadata";
import { ownership } from "./ownership";
import { permission } from "./permission";
import { proof } from "./proof";
import { rollup } from "./rollup";
import { transaction } from "./transaction";
Expand All @@ -30,14 +26,10 @@ export interface IApiClient<T = any> {
doc: ReturnType<typeof document>;
user: ReturnType<typeof user>;
group: ReturnType<typeof group>;
ownership: ReturnType<typeof ownership>;
permission: ReturnType<typeof permission>;
merkle: ReturnType<typeof merkle>;
proof: ReturnType<typeof proof>;
transaction: ReturnType<typeof transaction>;
rollup: ReturnType<typeof rollup>;
environment: ReturnType<typeof environment>;
metadata: ReturnType<typeof metadata>;
}

export class ApiClient<T = any> {
Expand Down Expand Up @@ -118,14 +110,10 @@ export class ApiClient<T = any> {
doc: document(api.apollo),
user: user(api.apollo),
group: group(api.apollo),
ownership: ownership(api.apollo),
permission: permission(api.apollo),
merkle: merkle(api.apollo),
proof: proof(api.apollo),
transaction: transaction(api.apollo),
rollup: rollup(api.apollo),
environment: environment(api.apollo),
metadata: metadata(api.#client),
};
}
}
140 changes: 72 additions & 68 deletions packages/api/src/graphql/collection-index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { gql } from "@apollo/client";
import {
TIndexCreateRequest,
TIndexCreateResponse,
TIndexDropReponse,
TIndexDropRequest,
TIndexExistReponse,
TIndexExistRequest,
TIndexListRequest,
TIndexListResponse,
Expand All @@ -12,73 +15,74 @@ import {
TApolloClient,
} from "./common";

const COLLECTION_INDEX_CREATE = gql`
mutation IndexCreate(
$databaseName: String!
$collectionName: String!
$index: [IndexInput!]!
) {
indexCreate(
databaseName: $databaseName
collectionName: $collectionName
index: $index
)
}
`;

const COLLECTION_INDEX_DELETE = gql`
mutation IndexDrop(
$databaseName: String!
$collectionName: String!
$indexName: String!
) {
indexDrop(
databaseName: $databaseName
collectionName: $collectionName
indexName: $indexName
)
}
`;

const COLLECTION_INDEX_EXIST = gql`
query IndexExist(
$databaseName: String!
$collectionName: String!
$indexName: String!
) {
indexExist(
databaseName: $databaseName
collectionName: $collectionName
indexName: $indexName
)
}
`;

const COLLECTION_INDEX_LIST = gql`
query IndexList($databaseName: String!, $collectionName: String!) {
indexList(databaseName: $databaseName, collectionName: $collectionName)
}
`;

export const collectionIndex = <T>(client: TApolloClient<T>) => ({
create: createMutateFunction<
boolean,
TIndexCreateRequest,
{ indexCreate: boolean }
>(client, COLLECTION_INDEX_CREATE, (data) => data.indexCreate),
drop: createMutateFunction<
boolean,
TIndexDropRequest,
{ indexDrop: boolean }
>(client, COLLECTION_INDEX_DELETE, (data) => data.indexDrop),
exist: createQueryFunction<
boolean,
TIndexExistRequest,
{ indexExist: boolean }
>(client, COLLECTION_INDEX_EXIST, (data) => data.indexExist),
list: createQueryFunction<
string[],
TIndexListRequest,
{ indexList: TIndexListResponse }
>(client, COLLECTION_INDEX_LIST, (data) => data.indexList),
indexCreate: createMutateFunction<TIndexCreateRequest, TIndexCreateResponse>(
client,
gql`
mutation indexCreate(
$databaseName: String!
$collectionName: String!
$index: JSON!
) {
indexCreate(
databaseName: $databaseName
collectionName: $collectionName
index: $index
)
}
`,
(data) => data.indexCreate
),
indexDrop: createMutateFunction<TIndexDropRequest, TIndexDropReponse>(
client,
gql`
mutation indexDrop(
$databaseName: String!
$collectionName: String!
$indexName: String!
) {
indexDrop(
databaseName: $databaseName
collectionName: $collectionName
indexName: $indexName
)
}
`,
(data) => data.indexDrop
),
indexExist: createQueryFunction<TIndexExistRequest, TIndexExistReponse>(
client,
gql`
query indexExist(
$databaseName: String!
$collectionName: String!
$indexName: String!
) {
indexExist(
databaseName: $databaseName
collectionName: $collectionName
indexName: $indexName
)
}
`,
(data) => data.indexExist
),
indexList: createQueryFunction<TIndexListRequest, TIndexListResponse>(
client,
gql`
query indexList($databaseName: String!, $collectionName: String!) {
indexList(
databaseName: $databaseName
collectionName: $collectionName
) {
indexName
size
access
property
createdAt
}
}
`,
(data) => data.indexList
),
});
Loading