anyproto / anytype-heart

Shared library for Anytype clients
https://anytype.io
Other
229 stars 46 forks source link

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

Open ebanDev opened 2 months ago

ebanDev commented 2 months ago

Have you read a contributing guide?

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 :)

ra3orblade commented 2 months ago

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 commented 2 months ago

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

ra3orblade commented 2 months ago

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 commented 2 months ago

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