Skip to content

Commit

Permalink
Merge pull request #1949 from undb-io/release/v1.0.0-40
Browse files Browse the repository at this point in the history
Release version v1.0.0-40
  • Loading branch information
nichenqin authored Aug 23, 2024
2 parents e9125d9 + 125571c commit 0cab901
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 22 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Changelog


## v1.0.0-40


### 🩹 Fixes

- Fix date filter ([a3aff5a](https://github.com/undb-io/undb/commit/a3aff5a))

### ❤️ Contributors

- Nichenqin ([@nichenqin](http://github.com/nichenqin))

## v1.0.0-39


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "undb",
"version": "1.0.0-39",
"version": "1.0.0-40",
"private": true,
"scripts": {
"build": "NODE_ENV=production bun --bun turbo build",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
DateIsEmpty,
ID_TYPE,
JsonContains,
LongTextEqual,
Expand Down Expand Up @@ -106,6 +107,7 @@ export class RecordQuerySpecCreatorVisitor implements IRecordVisitor {
urlEqual(s: UrlEqual): void {}
attachmentEqual(s: AttachmentEqual): void {}
attachmentEmpty(s: AttachmentEmpty): void {}
dateIsEmpty(spec: DateIsEmpty): void {}
dateEqual(spec: DateEqual): void {}
jsonEqual(spec: JsonEqual): void {}
jsonContains(spec: JsonContains): void {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DateEqual,
DateIsAfter,
DateIsBefore,
DateIsEmpty,
DateIsSameDay,
DateIsToday,
DateIsTomorrow,
Expand Down Expand Up @@ -75,6 +76,7 @@ export class RecordSpecReferenceVisitor implements IRecordVisitor {
dateIsYesterday(spec: DateIsTomorrow): void {}
dateIsBefore(spec: DateIsBefore): void {}
dateIsAfter(spec: DateIsAfter): void {}
dateIsEmpty(spec: DateIsEmpty): void {}
userEqual(spec: UserEqual): void
userEqual(spec: UserEqual): void {}
userEmpty(spec: UserEmpty): void
Expand Down
27 changes: 12 additions & 15 deletions packages/persistence/src/record/record.filter-visitor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NotImplementException } from "@undb/domain"
import {
DateIsEmpty,
JsonContains,
LongTextEqual,
SelectField,
Expand Down Expand Up @@ -90,8 +91,12 @@ export class RecordFilterVisitor extends AbstractQBVisitor<RecordDO> implements
jsonEmpty(spec: JsonEmpty): void {
this.addCond(this.eb.eb(this.getFieldId(spec), "is", null))
}
dateIsEmpty(spec: DateIsEmpty): void {
const cond = this.eb.eb(this.getFieldId(spec), "is", null)
this.addCond(cond)
}
dateEqual(spec: DateEqual): void {
this.addCond(this.eb.eb(this.getFieldId(spec), "=", spec.date?.toISOString() ?? null))
this.addCond(this.eb.eb(this.getFieldId(spec), "=", spec.date?.getTime() ?? null))
}
attachmentEqual(s: AttachmentEqual): void {
throw new Error("Method not implemented.")
Expand Down Expand Up @@ -132,35 +137,27 @@ export class RecordFilterVisitor extends AbstractQBVisitor<RecordDO> implements
this.addCond(cond)
}
dateIsBefore(spec: DateIsBefore): void {
const cond = this.eb.eb(this.getFieldId(spec), "<", startOfDay(spec.date).toISOString())
const cond = this.eb.eb(this.getFieldId(spec), "<", startOfDay(spec.date).getTime())
this.addCond(cond)
}
dateIsAfter(spec: DateIsAfter): void {
const cond = this.eb.eb(this.getFieldId(spec), ">", endOfDay(spec.date).toISOString())
const cond = this.eb.eb(this.getFieldId(spec), ">", endOfDay(spec.date).getTime())
this.addCond(cond)
}
dateIsTomorrow(spec: DateIsTomorrow): void {
const cond = this.eb.between(this.getFieldId(spec), startOfTomorrow().toISOString(), endOfTomorrow().toISOString())
const cond = this.eb.between(this.getFieldId(spec), startOfTomorrow().getTime(), endOfTomorrow().getTime())
this.addCond(cond)
}
dateIsYesterday(spec: DateIsTomorrow): void {
const cond = this.eb.between(
this.getFieldId(spec),
startOfYesterday().toISOString(),
endOfYesterday().toISOString(),
)
const cond = this.eb.between(this.getFieldId(spec), startOfYesterday().getTime(), endOfYesterday().getTime())
this.addCond(cond)
}
dateIsToday(spec: DateIsToday): void {
const cond = this.eb.between(this.getFieldId(spec), startOfToday().toISOString(), endOfToday().toISOString())
const cond = this.eb.between(this.getFieldId(spec), startOfToday().getTime(), endOfToday().getTime())
this.addCond(cond)
}
dateIsSameDate(spec: DateIsSameDay): void {
const cond = this.eb.between(
this.getFieldId(spec),
startOfDay(spec.date).toISOString(),
endOfDay(spec.date).toISOString(),
)
const cond = this.eb.between(this.getFieldId(spec), startOfDay(spec.date).getTime(), endOfDay(spec.date).getTime())
this.addCond(cond)
}
idEqual(spec: IdEqual): void {
Expand Down
4 changes: 4 additions & 0 deletions packages/persistence/src/record/record.mutate-visitor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getCurrentUserId, mustGetCurrentSpaceId } from "@undb/context/server"
import type { ISpecification, ISpecVisitor } from "@undb/domain"
import {
DateIsEmpty,
ID_TYPE,
JsonContains,
LongTextEqual,
Expand Down Expand Up @@ -81,6 +82,9 @@ export class RecordMutateVisitor extends AbstractQBMutationVisitor implements IR
jsonEmpty(spec: JsonEmpty): void {
this.setData(spec.fieldId.value, null)
}
dateIsEmpty(spec: DateIsEmpty): void {
this.setData(spec.fieldId.value, null)
}
dateEqual(spec: DateEqual): void {
this.setData(spec.fieldId.value, spec.date?.getTime() ?? null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { FieldId } from "../../field-id.vo"
import {
DateIsAfter,
DateIsBefore,
DateIsEmpty,
DateIsSameDay,
DateIsToday,
DateIsTomorrow,
Expand Down Expand Up @@ -54,6 +55,9 @@ export function createAbstractDateFieldCondition<ItemType extends z.ZodTypeAny>(
z.object({ op: z.literal("is_not_before"), value: dateValue }).merge(base),
z.object({ op: z.literal("is_after"), value: dateValue }).merge(base),
z.object({ op: z.literal("is_not_after"), value: dateValue }).merge(base),

z.object({ op: z.literal("is_empty"), value: z.undefined() }).merge(base),
z.object({ op: z.literal("is_not_empty"), value: z.undefined() }).merge(base),
])
}

Expand All @@ -80,3 +84,5 @@ export const createAbstractDateConditionMather = (
.with({ op: "is_after_tomorrow" }, () => new DateIsAfter(endOfTomorrow(), fieldId))
.with({ op: "is_after_yesterday" }, () => new DateIsAfter(endOfYesterday(), fieldId))
.with({ op: "is_not_after" }, ({ value }) => new DateIsAfter(new Date(value), fieldId).not())
.with({ op: "is_empty" }, () => new DateIsEmpty(fieldId))
.with({ op: "is_not_empty" }, () => new DateIsEmpty(fieldId).not())
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isToday } from "date-fns/isToday"
import type { IRecordVisitor, RecordDO } from "../../../../records"
import { RecordComositeSpecification } from "../../../../records/record/record.composite-specification"
import type { FieldId } from "../../field-id.vo"
import { startOfToday } from "date-fns/startOfToday"
import { DateFieldValue } from "../date-field"

export class DateIsSameDay extends RecordComositeSpecification {
constructor(
Expand Down Expand Up @@ -120,3 +120,17 @@ export class DateIsAfter extends RecordComositeSpecification {
return Ok(undefined)
}
}

export class DateIsEmpty extends RecordComositeSpecification {
isSatisfiedBy(t: RecordDO): boolean {
throw new Error("Method not implemented.")
}
mutate(t: RecordDO): Result<RecordDO, string> {
t.values.setValue(this.fieldId, new DateFieldValue(null))
return Ok(t)
}
accept(v: IRecordVisitor): Result<void, string> {
v.dateIsEmpty(this)
return Ok(undefined)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { DateIsEmpty } from "../abstractions/abstract-date-value.specification"
import type { IAbstractDateFieldValueVisitor } from "../abstractions/abstract-date-value.visitor"
import type { DateEqual } from "./date-field.specification"

export interface IDateFieldValueVisitor extends IAbstractDateFieldValueVisitor {
dateEqual(spec: DateEqual): void
dateIsEmpty(spec: DateIsEmpty): void
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class StringContains extends RecordComositeSpecification {
}
isSatisfiedBy(t: RecordDO): boolean {
const value = t.getValue(this.fieldId)
return value.mapOr(false, (v) => v instanceof StringFieldValue && v.value.includes(this.value))
return value.mapOr(false, (v) => v instanceof StringFieldValue && !!v.value?.includes(this.value))
}
mutate(t: RecordDO): Result<RecordDO, string> {
throw new Error("Method not implemented.")
Expand All @@ -54,7 +54,7 @@ export class StringStartsWith extends RecordComositeSpecification {
}
isSatisfiedBy(t: RecordDO): boolean {
const value = t.getValue(this.fieldId)
return value.mapOr(false, (v) => v instanceof StringFieldValue && v.value.startsWith(this.value))
return value.mapOr(false, (v) => v instanceof StringFieldValue && !!v.value?.startsWith(this.value))
}
mutate(t: RecordDO): Result<RecordDO, string> {
throw new Error("Method not implemented.")
Expand All @@ -74,7 +74,7 @@ export class StringEndsWith extends RecordComositeSpecification {
}
isSatisfiedBy(t: RecordDO): boolean {
const value = t.getValue(this.fieldId)
return value.mapOr(false, (v) => v instanceof StringFieldValue && v.value.endsWith(this.value))
return value.mapOr(false, (v) => v instanceof StringFieldValue && !!v.value?.endsWith(this.value))
}
mutate(t: RecordDO): Result<RecordDO, string> {
throw new Error("Method not implemented.")
Expand Down Expand Up @@ -111,7 +111,7 @@ export class StringMin extends RecordComositeSpecification {
}
isSatisfiedBy(t: RecordDO): boolean {
const value = t.getValue(this.fieldId)
return value.mapOr(false, (v) => v instanceof StringFieldValue && v.value.length >= this.min)
return value.mapOr(false, (v) => v instanceof StringFieldValue && (v.value?.length ?? 0) >= this.min)
}
mutate(t: RecordDO): Result<RecordDO, string> {
throw new Error("Method not implemented.")
Expand All @@ -131,7 +131,7 @@ export class StringMax extends RecordComositeSpecification {
}
isSatisfiedBy(t: RecordDO): boolean {
const value = t.getValue(this.fieldId)
return value.mapOr(false, (v) => v instanceof StringFieldValue && v.value.length <= this.max)
return value.mapOr(false, (v) => v instanceof StringFieldValue && (v.value?.length ?? 0) <= this.max)
}
mutate(t: RecordDO): Result<RecordDO, string> {
throw new Error("Method not implemented.")
Expand Down

0 comments on commit 0cab901

Please sign in to comment.