Skip to content
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
56 changes: 28 additions & 28 deletions src/components/databrowser/components/search/schema-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ describe("Schema Parser", () => {
expect(result).toEqual({
success: true,
schema: {
price: "F64",
count: "U64",
score: { type: "I64", from: "val" },
price: { type: "F64", fast: true },
count: { type: "U64", fast: true },
score: { type: "I64", fast: true, from: "val" },
},
})
})
Expand Down Expand Up @@ -114,7 +114,7 @@ describe("Schema Parser", () => {
schema: {
"user.name": "TEXT",
"user.address.city": "TEXT",
"user.address.zip": "U64",
"user.address.zip": { type: "U64", fast: true },
},
})
})
Expand All @@ -132,7 +132,7 @@ describe("Schema Parser", () => {
success: true,
schema: {
name: "TEXT",
age: "F64",
age: { type: "F64", fast: true },
active: "BOOL",
},
})
Expand Down Expand Up @@ -176,7 +176,7 @@ describe("Schema Parser - Edge Cases", () => {
success: true,
schema: {
"field.with.dots": "TEXT",
"another.dotted.field": "F64",
"another.dotted.field": { type: "F64", fast: true },
},
})
})
Expand Down Expand Up @@ -210,7 +210,7 @@ describe("Schema Parser - Edge Cases", () => {
success: true,
schema: {
item: { type: "TEXT", from: "items(0)" },
nested: { type: "F64", from: "data[key]" },
nested: { type: "F64", fast: true, from: "data[key]" },
},
})
})
Expand Down Expand Up @@ -247,7 +247,7 @@ describe("Schema Parser - Edge Cases", () => {
success: true,
schema: {
name: "TEXT",
age: "U64",
age: { type: "U64", fast: true },
},
})
})
Expand All @@ -259,7 +259,7 @@ describe("Schema Parser - Edge Cases", () => {
success: true,
schema: {
a: "TEXT",
b: "F64",
b: { type: "F64", fast: true },
c: "BOOL",
},
})
Expand Down Expand Up @@ -314,7 +314,7 @@ describe("Schema Parser - Edge Cases", () => {
expect(result).toEqual({
success: true,
schema: {
id: "U64",
id: { type: "U64", fast: true },
"user.name": "TEXT",
"user.email": "TEXT",
active: "BOOL",
Expand All @@ -337,7 +337,7 @@ describe("Schema Parser - Edge Cases", () => {
success: true,
schema: {
名前: "TEXT",
données: "F64",
données: { type: "F64", fast: true },
"emoji_🎉": "BOOL",
},
})
Expand All @@ -357,7 +357,7 @@ describe("Schema Parser - Edge Cases", () => {
success: true,
schema: {
"s.string()": "TEXT",
"s.number()": "F64",
"s.number()": { type: "F64", fast: true },
"s.boolean()": "BOOL",
".string()": "TEXT",
},
Expand Down Expand Up @@ -423,11 +423,11 @@ describe("Schema Parser - Edge Cases", () => {
expect(result).toEqual({
success: true,
schema: {
f64: "F64",
u64: "U64",
i64: "I64",
default: "F64",
aliased: { type: "F64", from: "source" },
f64: { type: "F64", fast: true },
u64: { type: "U64", fast: true },
i64: { type: "I64", fast: true },
default: { type: "F64", fast: true },
aliased: { type: "F64", fast: true, from: "source" },
},
})
})
Expand Down Expand Up @@ -478,7 +478,7 @@ describe("Schema Parser - Edge Cases", () => {
success: true,
schema: {
name: "TEXT",
age: "F64",
age: { type: "F64", fast: true },
},
})
})
Expand All @@ -495,7 +495,7 @@ describe("Schema Parser - Edge Cases", () => {
success: true,
schema: {
name: "TEXT",
age: "F64",
age: { type: "F64", fast: true },
},
})
})
Expand All @@ -514,7 +514,7 @@ describe("Schema Parser - Edge Cases", () => {
expect(result).toEqual({
success: true,
schema: {
id: "U64",
id: { type: "U64", fast: true },
name: "TEXT",
},
})
Expand Down Expand Up @@ -567,7 +567,7 @@ describe("Schema Parser - Additional Edge Cases", () => {
success: true,
schema: {
name: "TEXT",
age: "F64",
age: { type: "F64", fast: true },
},
})
})
Expand All @@ -580,7 +580,7 @@ describe("Schema Parser - Additional Edge Cases", () => {
success: true,
schema: {
name: "TEXT",
age: "F64",
age: { type: "F64", fast: true },
},
})
})
Expand All @@ -598,7 +598,7 @@ describe("Schema Parser - Additional Edge Cases", () => {
success: true,
schema: {
name: "TEXT",
age: "F64",
age: { type: "F64", fast: true },
},
})
})
Expand All @@ -615,7 +615,7 @@ describe("Schema Parser - Additional Edge Cases", () => {
success: true,
schema: {
"field with spaces": "TEXT",
"another spaced field": "F64",
"another spaced field": { type: "F64", fast: true },
},
})
})
Expand Down Expand Up @@ -700,7 +700,7 @@ describe("Schema Parser - Additional Edge Cases", () => {
expect(result).toEqual({
success: true,
schema: {
_id: "U64",
_id: { type: "U64", fast: true },
__typename: "TEXT",
_private_field: "BOOL",
},
Expand Down Expand Up @@ -778,7 +778,7 @@ describe("Schema Parser - Malformed Inputs", () => {
// Should skip invalid entries and parse valid ones
expect(result.success).toBe(true)
if (result.success) {
expect(result.schema.age).toBe("F64")
expect(result.schema.age).toEqual({ type: "F64", fast: true })
}
})

Expand All @@ -793,7 +793,7 @@ describe("Schema Parser - Malformed Inputs", () => {
expect(result.success).toBe(true)
if (result.success) {
expect(result.schema.name).toBe("TEXT")
expect(result.schema.age).toBe("F64")
expect(result.schema.age).toEqual({ type: "F64", fast: true })
}
})

Expand Down Expand Up @@ -825,7 +825,7 @@ describe("Schema Parser - Malformed Inputs", () => {
success: true,
schema: {
string: "TEXT",
number: "F64",
number: { type: "F64", fast: true },
boolean: "BOOL",
date: "DATE",
object: "TEXT",
Expand Down
10 changes: 6 additions & 4 deletions src/components/databrowser/components/search/schema-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,17 @@ function parseFieldBuilder(str: string, fieldName: string): FieldValue | undefin
}
}

// s.number() or s.number("F64") - numbers only support .from(), not .fast()
// s.number() or s.number("F64") - numerics always include fast: true
if (str.startsWith("s.number(")) {
const typeMatch = str.match(/s\.number\(\s*["']?(U64|I64|F64)?["']?\s*\)/)
const numType = typeMatch?.[1] || "F64"
const fromValue = extractFromValue(str)

if (fromValue === undefined) return numType

return { type: numType, from: fromValue }
return {
type: numType,
fast: true,
...(fromValue !== undefined && { from: fromValue }),
}
}

// s.boolean()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("Schema Parser - Round Trip", () => {
test("round-trips simple schema", () => {
const original = {
name: "TEXT",
age: "F64",
age: { type: "F64", fast: true },
active: "BOOL",
}
const editorValue = schemaToEditorValue(original)
Expand All @@ -22,7 +22,7 @@ describe("Schema Parser - Round Trip", () => {
const original = {
"user.name": "TEXT",
"user.address.city": "TEXT",
"user.address.zip": "U64",
"user.address.zip": { type: "U64", fast: true },
}
const editorValue = schemaToEditorValue(original)
const result = parseSchemaFromEditorValue(editorValue)
Expand All @@ -40,10 +40,10 @@ describe("Schema Parser - Round Trip", () => {
boolFast: { type: "BOOL", fast: true },
date: "DATE",
dateFast: { type: "DATE", fast: true },
f64: "F64",
f64From: { type: "F64", from: "source" },
u64: "U64",
i64: "I64",
f64: { type: "F64", fast: true },
f64From: { type: "F64", fast: true, from: "source" },
u64: { type: "U64", fast: true },
i64: { type: "I64", fast: true },
}
const editorValue = schemaToEditorValue(original)
const result = parseSchemaFromEditorValue(editorValue)
Expand All @@ -56,7 +56,7 @@ describe("Schema Parser - Round Trip", () => {
test("round-trips schema with from() fields", () => {
const original = {
name: { type: "TEXT", from: "fullName" },
count: { type: "U64", from: "total" },
count: { type: "U64", fast: true, from: "total" },
active: { type: "BOOL", fast: true, from: "isActive" },
}
const editorValue = schemaToEditorValue(original)
Expand All @@ -80,7 +80,7 @@ describe("Schema Parser - Round Trip", () => {
test("round-trips deeply nested schema", () => {
const original = {
"a.b.c.d.e": "TEXT",
"a.b.c.d.f": "F64",
"a.b.c.d.f": { type: "F64", fast: true },
"a.b.x": "BOOL",
}
const editorValue = schemaToEditorValue(original)
Expand Down
Loading