Skip to content

createContributionDetailsRecord should follow pattern for $type and createdAt #134

@aspiers

Description

@aspiers

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's see the full createContributionDetailsRecord method including the validate call
sed -n '1293,1320p' packages/sdk-core/src/repository/HypercertOperationsImpl.ts

Repository: hypercerts-org/hypercerts-sdk

Length of output: 1137


🏁 Script executed:

# Check the validate function definition to understand its behavior
rg -n "validate.*function|validate.*=.*\(" packages/sdk-core/src -A 5 | head -50

Repository: hypercerts-org/hypercerts-sdk

Length of output: 476


🏁 Script executed:

# Look for CreateContributionDetailsParams type definition
rg -n "CreateContributionDetailsParams|createContributionDetailsRecord" packages/sdk-core/src --type=ts -B 2 -A 2

Repository: hypercerts-org/hypercerts-sdk

Length of output: 3988


🏁 Script executed:

# Check the addContributorInformation method to verify the consistency claim (line 1593)
sed -n '1585,1615p' packages/sdk-core/src/repository/HypercertOperationsImpl.ts

Repository: hypercerts-org/hypercerts-sdk

Length of output: 1152


🏁 Script executed:

# Check the CreateContributionDetailsParams type definition to see its full structure
sed -n '50,70p' packages/sdk-core/src/repository/interfaces.ts

Repository: hypercerts-org/hypercerts-sdk

Length of output: 545


🏁 Script executed:

# Look for the validate function definition to understand its behavior with unknown fields
rg -n "export.*validate|const validate.*=" packages/sdk-core/src -B 2 -A 10 | grep -A 10 "function validate"

Repository: hypercerts-org/hypercerts-sdk

Length of output: 2720


🏁 Script executed:

# Check if there are any Zod schemas or validation schemas for ContributionDetails
rg -n "ContributionDetailsSchema|CONTRIBUTION_DETAILS.*schema" packages/sdk-core/src --type=ts -B 2 -A 5

Repository: hypercerts-org/hypercerts-sdk

Length of output: 55


🏁 Script executed:

# Look at how the method handles $type and createdAt - check if nullish coalescing is used
sed -n '1293,1330p' packages/sdk-core/src/repository/HypercertOperationsImpl.ts

Repository: hypercerts-org/hypercerts-sdk

Length of output: 1321


🏁 Script executed:

# Find the validate function that's being called at line 1312
rg -n "^export.*validate|^function validate" packages/sdk-core/src --type=ts -A 15 | head -80

Repository: hypercerts-org/hypercerts-sdk

Length of output: 3834


🏁 Script executed:

# Search for validate function imports in HypercertOperationsImpl.ts
head -50 packages/sdk-core/src/repository/HypercertOperationsImpl.ts | grep -i "import.*validate"

Repository: hypercerts-org/hypercerts-sdk

Length of output: 124


🏁 Script executed:

# Check if validate is from lexicons module
rg -n "validate" packages/sdk-core/src/lexicons -B 2 -A 10 | grep -A 10 "export.*validate"

Repository: hypercerts-org/hypercerts-sdk

Length of output: 1829


🏁 Script executed:

# Check if there's documentation about `@hypercerts-org/lexicon` in package.json or README
cat packages/sdk-core/package.json | grep -A 2 "@hypercerts-org/lexicon"

Repository: hypercerts-org/hypercerts-sdk

Length of output: 179


🏁 Script executed:

# Look for how validate is used elsewhere in the codebase to understand its behavior
rg "validate\(" packages/sdk-core/src --type=ts -B 2 -A 2 | head -100

Repository: hypercerts-org/hypercerts-sdk

Length of output: 9387


🏁 Script executed:

# Check the method signature of addContributorInformation to see if it also uses index signature
rg -n "addContributorInformation" packages/sdk-core/src/repository/HypercertOperationsImpl.ts -A 15 | head -40

Repository: hypercerts-org/hypercerts-sdk

Length of output: 1826


🏁 Script executed:

# Check if the method should accept CreateContributionDetailsParams instead of inline object
grep -n "CreateContributionDetailsParams" packages/sdk-core/src/repository/interfaces.ts -A 30 | head -50

Repository: hypercerts-org/hypercerts-sdk

Length of output: 1611


🏁 Script executed:

# Check if CreateContributionDetailsParams is being used correctly in the method call
# Look at the method signature vs the interface
grep -n "CreateContributionDetailsParams" packages/sdk-core/src/repository/interfaces.ts -B 5 -A 15 | head -40

Repository: hypercerts-org/hypercerts-sdk

Length of output: 1459


🏁 Script executed:

# Look at addContributorInformation to see if it uses CreatedAt or $type parameters
sed -n '1578,1625p' packages/sdk-core/src/repository/HypercertOperationsImpl.ts

Repository: hypercerts-org/hypercerts-sdk

Length of output: 1818


🏁 Script executed:

# Check if the validate function's 4th parameter (false) relates to strict mode
rg -n "validate.*false\|validate.*strict" packages/sdk-core/src --type=ts -B 2 -A 2 | head -50

Repository: hypercerts-org/hypercerts-sdk

Length of output: 55


🏁 Script executed:

# Check if CreateContributionDetailsParams should include optional $type and createdAt fields
grep -n "$type\|createdAt" packages/sdk-core/src/repository/interfaces.ts -B 2 -A 2

Repository: hypercerts-org/hypercerts-sdk

Length of output: 44488


🏁 Script executed:

# Check how buildAttachmentRecord implements the nullish coalescing pattern mentioned in learnings
rg -n "buildAttachmentRecord" packages/sdk-core/src/repository/HypercertOperationsImpl.ts -A 20

Repository: hypercerts-org/hypercerts-sdk

Length of output: 1934


🏁 Script executed:

# Look for other helper methods to see if they use the nullish coalescing pattern
rg -n "createLocationRecord|buildAttachmentRecord" packages/sdk-core/src -A 10 --type=ts

Repository: hypercerts-org/hypercerts-sdk

Length of output: 6879


Update createContributionDetailsRecord to preserve caller-supplied $type and createdAt values using nullish coalescing.

The method should follow the pattern established in buildAttachmentRecord (lines 1104-1105): accept optional $type and createdAt parameters and use nullish coalescing to preserve caller-supplied values, defaulting only when missing. Add these optional fields to the CreateContributionDetailsParams type definition and update the method to:

const { role, contributionDescription, startDate, endDate, $type, createdAt, ...extraProps } = params;
const finalCreatedAt = createdAt ?? new Date().toISOString();
const contributionRecord: HypercertContributionDetails = {
  $type: $type ?? HYPERCERT_COLLECTIONS.CONTRIBUTION_DETAILS,
  role,
  createdAt: finalCreatedAt,
  contributionDescription,
  startDate,
  endDate,
  ...extraProps,
};

This aligns with the nullish coalescing pattern used in buildAttachmentRecord and the coding guideline requiring optional $type and createdAt fields in all CreateXxxParams types.

🤖 Prompt for AI Agents
In `@packages/sdk-core/src/repository/HypercertOperationsImpl.ts` around lines
1293 - 1310, The createContributionDetailsRecord function currently always
overwrites $type and createdAt; update it to accept optional $type and createdAt
in the CreateContributionDetailsParams type and use nullish coalescing like
buildAttachmentRecord: destructure params to include $type and createdAt,
compute finalCreatedAt = createdAt ?? new Date().toISOString(), and set
contributionRecord.$type = $type ?? HYPERCERT_COLLECTIONS.CONTRIBUTION_DETAILS
and contributionRecord.createdAt = finalCreatedAt while preserving
...extraProps.

Originally posted by @coderabbitai[bot] in #130 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions