-
Notifications
You must be signed in to change notification settings - Fork 86
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: add date datatype #1906
feat: add date datatype #1906
Conversation
📝 Walkthrough📝 WalkthroughWalkthroughThe changes involve an update to the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant ApiObject
Client->>ApiObject: Create new ApiObject
ApiObject->>ApiObject: Add properties (including Date and null)
Client->>ApiObject: Retrieve ApiObject
ApiObject-->>Client: Return ApiObject with Date and null properties
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #1906 +/- ##
========================================
Coverage 57.47% 57.47%
========================================
Files 485 485
Lines 16495 16495
Branches 3304 3313 +9
========================================
Hits 9481 9481
+ Misses 5745 5734 -11
- Partials 1269 1280 +11 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
packages/analytics-js-service-worker/src/types.ts (2)
Line range hint
3-7
: Update interface documentation to include Date type.The interface documentation should be updated to mention Date type support and include usage examples.
/** * Represents a generic object in the APIs * Use for parameters like context, traits etc. + * + * @example + * { + * createdAt: new Date(), + * dates: [new Date('2023-01-01'), new Date('2023-12-31')] + * } */
15-16
: Consider adding runtime type validation.Since
ApiObject
can now include Date objects, consider adding runtime type validation to ensure proper Date object handling and prevent invalid date values.This could be implemented as a utility function:
function isValidDateValue(value: unknown): boolean { return value instanceof Date && !isNaN(value.getTime()); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
packages/analytics-js-service-worker/src/types.ts
(1 hunks)
🔇 Additional comments (2)
packages/analytics-js-service-worker/src/types.ts (2)
15-16
: LGTM! Non-breaking type enhancement.
The addition of the Date type is a valid enhancement that maintains backward compatibility.
15-16
: Verify Date object handling across browsers.
Since this PR introduces Date object support and cross-browser testing is required, ensure proper Date object serialization and handling, especially for IE11 compatibility.
✅ Verification successful
Let me gather more specific information about Date handling in the service worker context and the analytics package.
Date handling is properly implemented and cross-browser compatible
The codebase shows robust Date object handling:
- Uses standard
toISOString()
for serialization in the service worker - Implements proper timestamp formatting utilities in
analytics-js-common
- Handles Date objects consistently across all analytics operations
- No IE11-specific code is needed as IE11 is no longer supported by modern browsers and service workers
The implementation is safe and follows best practices for Date handling in a service worker context.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for Date object handling and serialization in the codebase
echo "Checking for Date object serialization..."
rg -l "JSON\.stringify.*Date|new Date\("
echo "Checking for browser-specific Date handling..."
rg -l "toISOString|getTime|toJSON.*Date"
Length of output: 5374
Script:
#!/bin/bash
# Check how Date objects are handled in the service worker and analytics packages
echo "Checking service worker Date handling..."
rg -A 5 "Date" packages/analytics-js-service-worker/
echo "Checking analytics common utilities Date handling..."
rg -A 5 "Date" packages/analytics-js-common/src/utilities/
Length of output: 15707
size-limit report 📦
|
|
PR Description
Allow date data type in apiObject interface.
Linear task (optional)
Linear task link
Cross Browser Tests
Please confirm you have tested for the following browsers:
Sanity Suite
Security
Summary by CodeRabbit
ApiObject
interface to supportDate
andnull
values, allowing for more complex data representations.These changes improve the flexibility and capability of data handling within the application.