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

Unable to filter by type, how should I do? #1337

Open
3 tasks done
ebanDev opened this issue Jun 23, 2024 · 4 comments
Open
3 tasks done

Unable to filter by type, how should I do? #1337

ebanDev opened this issue Jun 23, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@ebanDev
Copy link

ebanDev commented Jun 23, 2024

Have you read a contributing guide?

  • I have read CONTRIBUTING.md
  • I have searched the existing issues and didn't find any that were similar
  • I have considered creating a pull request with fixes instead of a bug report and want to proceed

Current Behavior

I'm trying communicate with my desktop instance of anytype using grpc-js, here is my current code :

import grpc from '@grpc/grpc-js';
import * as loader from "@grpc/proto-loader";
import * as util from "node:util";
// import prompt from "prompt-sync";

const packageDefinition = loader.loadSync('protobuf/protos/service.proto', {
    keepCase: true,
    longs: String,
    enums: String,
    defaults: true,
    oneofs: true
});

const APP_KEY ='XXXX'
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
const grpcClient = new protoDescriptor.anytype.ClientCommands('localhost:34075', grpc.credentials.createInsecure());
const call = (call, input) => util.promisify(call).call(grpcClient, input);

//const newChallenge = await call(grpcClient.AccountLocalLinkNewChallenge, {appName: 'test'});
//const inputToken = prompt()('Enter the token: ');
//const solvedChallenge = await call(grpcClient.AccountLocalLinkSolveChallenge, {challengeId: newChallenge.challengeId, answer: inputToken});
//const sessionToken = solvedChallenge.sessionToken;
const sessionToken = await call(grpcClient.WalletCreateSession, {appKey: APP_KEY}).then((res) => res.token);

const metadata = new grpc.Metadata();
metadata.add('token', sessionToken);

grpcClient.ObjectSearchWithMeta({objectTypeFilter: "_otobjectType"}, metadata, (err, response) => {
    if (err) {
        console.error(err);
        return;
    }

    console.log(response)
})

As you can guess, for now I'm just trying to get all the avaiables Types, but this does not work and it returns all the objects. How am I supposed to filter for the objects? I tried reading the doc on anytype.model.Block.Content.Dataview.Filter but it is not clear enough for me (and ChatGPT) to write the right code.

Expected Behavior

It should send me back all the blocks of the type _otobjectType

Steps To Reproduce

  1. Install AnyType
  2. Run the code in the current behavior section

Environment

- OS: Fedora 40
- Version: OS version: linux x64 6.8.11-300.fc40.x86_64
App version: 0.41.1
Build number: build on 2024-06-13 12:23:20 +0000 UTC at #48d85bd5470c4a6aaa6f38c2f37b04e7ce2fb637
Library version: v0.34.3
Anytype Identity: A9VmBYpL2L8PDt34FHjq5uCzz4tPRUDg92XaSt8vxzbqStV6
Analytics ID: 526cf722-f919-4952-a936-a1e0503cf627
Device ID: 12D3KooWR2djuvxRo25XJLJbRiPZrCFo5U4GasGkdpe4w8FTdNi1

Anything else?

PS : I tried to filter the Type objects from the list of all the objects it returned me, but _otobjectType only corresponds to the built-in AnyType Types, I had to search a bit through the data and found that all the types I created have a fields.type.stringValue of "bafyreicyeglwtj3ihj66wgf3kx4agh2uk2u3lpzfonprl6nvnfmkmyga6q", I don't really understand why... Hope y'all will be able to help me :)

@ebanDev ebanDev added the bug Something isn't working label Jun 23, 2024
@ra3orblade
Copy link
Contributor

ra3orblade commented Jun 23, 2024

Filter by layout, it's easier that finding type id.

https://github.com/anyproto/anytype-ts/blob/main/src/ts/interface/object.ts

export enum ObjectLayout {
	Page		 = 0,
	Human		 = 1,
	Task		 = 2,
	Set			 = 3,
	Type		 = 4,
	Relation	 = 5,
	File		 = 6,
	Dashboard	 = 7,
	Image		 = 8,
	Note		 = 9,
	Space		 = 10,
	Bookmark	 = 11,
	OptionList	 = 12,
	Option		 = 13,
	Collection	 = 14,
	Audio		 = 15,
	Video		 = 16,
	Date		 = 17,
	SpaceView	 = 18,
	Participant	 = 19,
	Pdf			 = 20,
};

@ebanDev
Copy link
Author

ebanDev commented Jun 23, 2024

Thanks! your answer fixes the anything else section but I keep this issue open because the main issue isnt solved

@ra3orblade
Copy link
Contributor

Thanks! your answer fixes the anything else section but I keep this issue open because the main issue isnt solved

I'm sorry, but what is the main issue? I did not understand

@ebanDev
Copy link
Author

ebanDev commented Jun 25, 2024

Well I want to be able to filter by object type directly because for example two types can have the layout Note

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants