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

feat: c version #306

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/sdk/src/__example__/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// EXAMPLE FOR NOW

import * as torii from "@dojoengine/torii-client";
import { init } from "..";
import { SchemaType } from "../types";

Expand Down
16 changes: 9 additions & 7 deletions packages/sdk/src/__tests__/convertQueryToClause.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { describe, expect, it } from "vitest";

import { MockSchemaType, schema } from "../__example__/index";
import { convertQueryToClause } from "../convertQuerytoClause";
import { QueryType } from "../types";
import { QueryType, SchemaType } from "../types";

describe("convertQueryToClause", () => {
it("should convert a single model query with conditions", () => {
Expand All @@ -27,7 +27,7 @@ describe("convertQueryToClause", () => {

expect(result).toEqual({
Composite: {
operator: "And",
operator: "Or",
clauses: [
{
Member: {
Expand Down Expand Up @@ -81,7 +81,7 @@ describe("convertQueryToClause", () => {

expect(result).toEqual({
Composite: {
operator: "And",
operator: "Or",
clauses: [
{
Member: {
Expand Down Expand Up @@ -110,10 +110,10 @@ describe("convertQueryToClause", () => {
player: {
$: {
where: {
AND: [
And: [
{ score: { $gt: 100 } },
{
OR: [
Or: [
{ name: { $eq: "Alice" } },
{ name: { $eq: "Bob" } },
],
Expand All @@ -125,7 +125,7 @@ describe("convertQueryToClause", () => {
item: {
$: {
where: {
AND: [{ durability: { $lt: 50 } }],
And: [{ durability: { $lt: 50 } }],
},
},
},
Expand All @@ -134,10 +134,12 @@ describe("convertQueryToClause", () => {

const result = convertQueryToClause(query, schema);

console.log("result", result);

Comment on lines +137 to +138
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove debug console.log statement

Debug logging statements should be removed before merging to production.

-        console.log("result", result);
-
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.log("result", result);

// Updated expectation to match the actual output
expect(result).toEqual({
Composite: {
operator: "And",
operator: "Or",
clauses: [
{
Member: {
Expand Down
7 changes: 4 additions & 3 deletions packages/sdk/src/convertQuerytoClause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function convertQueryToClause<T extends SchemaType>(
if (clauses.length > 1) {
return {
Composite: {
operator: "And",
operator: "Or",
clauses: clauses,
},
};
Expand Down Expand Up @@ -158,8 +158,8 @@ function buildWhereClause(
): torii.Clause | undefined {
// Define logical operator mapping
const logicalOperators: Record<string, torii.LogicalOperator> = {
AND: "And",
OR: "Or",
And: "And",
Or: "Or",
};

// Check for logical operators first
Expand Down Expand Up @@ -299,6 +299,7 @@ function convertToPrimitive(value: any): torii.MemberValue {
* @throws {Error} - If the operator is unsupported.
*/
function convertOperator(operator: string): torii.ComparisonOperator {
console.log(operator);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove or improve debug logging.

The console.log statement appears to be debugging code that was accidentally committed. If logging is needed, consider:

  1. Using a proper logging framework with level control
  2. Adding more context about what's being logged
  3. Moving it to debug/trace level

Remove the debug logging:

-    console.log(operator);

Or improve it with better context:

-    console.log(operator);
+    logger.debug(`Converting query operator: ${operator}`);

Committable suggestion was skipped due to low confidence.

switch (operator) {
case "$eq":
return "Eq";
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/getEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function getEntities<T extends SchemaType>(
limit: limit,
offset: cursor,
clause,
dont_include_hashed_keys: query.entityIds ? false : true,
dont_include_hashed_keys: false,
};

try {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/getEventMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function getEventMessages<T extends SchemaType>(
limit: limit,
offset: cursor,
clause,
dont_include_hashed_keys: true,
dont_include_hashed_keys: false,
};

try {
Expand Down
18 changes: 12 additions & 6 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,13 @@ export type QueryOptions = {
/**
* Logical operators for combining multiple conditions
*/
export type LogicalOperator = "AND" | "OR";

/**
* Recursively defines the conditions for the `where` clause.
*/
export type WhereCondition<TModel> =
| {
[key in LogicalOperator]?: Array<WhereCondition<TModel>>;
[key in torii.LogicalOperator]?: Array<WhereCondition<TModel>>;
}
| {
[P in keyof TModel]?: {
Expand Down Expand Up @@ -156,12 +155,14 @@ export type SubscriptionQueryType<T extends SchemaType> = {
};
};

export type BaseQueryType = {
entityIds?: string[];
};

/**
* QueryType for queries, using QueryWhereOptions
* Query type with model conditions
*/
export type QueryType<T extends SchemaType> = {
entityIds?: string[];
} & {
export type ModelQueryType<T extends SchemaType> = {
[K in keyof T]?: {
[L in keyof T[K]]?:
| AtLeastOne<{
Expand All @@ -171,6 +172,11 @@ export type QueryType<T extends SchemaType> = {
};
};

/**
* Combined QueryType using union of base and model types
*/
export type QueryType<T extends SchemaType> = BaseQueryType | ModelQueryType<T>;

/**
* Result of a query
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/torii-wasm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
set -ex

# Clone the repository
git clone --depth 1 --branch grpc-update https://github.com/dojoengine/dojo.c dojo.c
git clone --depth 1 https://github.com/dojoengine/dojo.c dojo.c
cd dojo.c

# Build for web (browser)
Expand Down
Loading