Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 25, 2025

  • Analyze current implementation of random() methods in AbstractType and subclasses
  • Create src/random/ folder structure
  • Extract random logic from each type class into separate functions
  • Create main router function with switch statement to dispatch to correct random generator
  • Update AbstractType to use the router function instead
  • Remove random() methods from all subclasses
  • Run tests to ensure existing functionality is preserved
  • Update any imports or dependencies as needed

Current status: Successfully created the random generators folder with individual functions for each type and a main router function. Updated AbstractType to use the new system. All tests are passing.

Next: Remove the individual random() methods from concrete type classes.

Fixes #11.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits July 25, 2025 23:53
Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
@streamich
Copy link
Collaborator

Copilot, please resume the task.

Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 26, 2025

Copilot, please resume the task.

Task completed! I've successfully removed all individual random() methods from the concrete type classes (ObjectType, TupleType, OrType, StringType, NumberType, and RefType). All functionality now routes through AbstractType's random() method using the new generator system. Removed 83 lines total, cleaned up unused imports, and all tests are passing. Commit: e98dd06

Copilot finished work on behalf of streamich July 26, 2025 08:08
@streamich streamich marked this pull request as ready for review July 26, 2025 08:30
Copy link
Collaborator

@streamich streamich left a comment

Choose a reason for hiding this comment

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

Add unit tests for the src/random/ module:

  • Create a "fixtures" file with few JSON Type schemas. According to src/schema/ rules.
  • Put the fixtures file in src/__tests__/ for reuse by all modules.
  • Use the schema fixtures to generate random values.
  • Validate that the produced values pass JSON Type value validation routine.

@@ -0,0 +1,14 @@
import type {ArrayType} from '../type/classes/ArrayType';

export function randomArray(type: ArrayType<any>): unknown[] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • Put all individual type random generator functions into a single module.
  • Use ArrowFunction: export const arr = () => ...
  • Use short names for exports, such as "arr", instead of "randomArr".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented! Consolidated all individual type random generator functions into a single generators.ts module using arrow functions with short names like arr, str, num, etc. Removed all individual generator files and updated the main router. Commit: 7156590

import type {TypeExportContext} from '../../system/TypeExportContext';
import type {Validators} from './types';
import type * as jtd from '../../jtd/types';
import {generateRandom} from '../../random/generator';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just call the main export as "random", instead of "generateRandom".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Renamed the main export from generateRandom to random in both the generator module and AbstractType import/usage. Commit: 7156590

Copilot AI and others added 2 commits July 26, 2025 08:59
- Rename generateRandom to random in main export
- Consolidate all individual type random generators into single module with arrow functions and short names
- Update generator.ts to use consolidated generators
- Remove individual generator files
- All tests passing

Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
- Create fixtures file with JSON Type schemas for reuse across modules
- Add 20 comprehensive tests for individual generators and main router
- Test validates generated values pass JSON Type validation
- Test edge cases, constraints, and complex nested structures
- Test deterministic behavior with controlled randomness
- All 497 tests passing

Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 26, 2025

Add unit tests for the src/random/ module:

  • Create a "fixtures" file with few JSON Type schemas. According to src/schema/ rules.
    ...

Complete! Added comprehensive unit tests for the src/random/ module:

  • Created src/__tests__/fixtures.ts with JSON Type schema fixtures according to src/schema/ rules
  • Added 20 tests covering all individual generators and main router function
  • Tests validate that generated random values pass JSON Type validation routine
  • Includes edge cases, constraints, and complex nested structures
  • Added deterministic testing with controlled randomness

All 497 tests passing. Commit: c64769b

Copilot AI requested a review from streamich July 26, 2025 09:07
Copilot finished work on behalf of streamich July 26, 2025 09:07
Copy link
Collaborator

@streamich streamich left a comment

Choose a reason for hiding this comment

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

Resolve merge conflicts with the latest master.

Verify that tests, linter, and formatter pass.

Copilot AI and others added 2 commits July 26, 2025 13:29
…tor methods and random functionality

Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 26, 2025

Resolve merge conflicts with the latest master.

Verify that tests, linter, and formatter pass.

Merge conflicts resolved! Successfully merged with latest master while preserving all functionality - capacity estimator methods from master are kept and the refactored random system remains intact. All tests, linting, and formatting pass. Commit: 8589e57

Copilot AI requested a review from streamich July 26, 2025 13:40
Copilot finished work on behalf of streamich July 26, 2025 13:40
Copy link
Collaborator

@streamich streamich left a comment

Choose a reason for hiding this comment

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

Remove codegenCapacityEstimator() method from all types but abstract type.

Make sure Prettier passes.

Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 26, 2025

Remove codegenCapacityEstimator() method from all types but abstract type.

Make sure Prettier passes.

Done! Removed codegenCapacityEstimator() method from all concrete type classes (StringType, NumberType, ObjectType, ArrayType, BooleanType, AnyType, BinaryType, ConstType, TupleType, MapType, OrType, RefType) while keeping the centralized implementation in AbstractType. All tests passing and Prettier formatting is clean. Commit: f1fa515

Copilot AI requested a review from streamich July 26, 2025 16:35
Copilot finished work on behalf of streamich July 26, 2025 16:35
@streamich streamich merged commit e9b943a into master Jul 26, 2025
2 checks passed
@streamich streamich deleted the copilot/fix-11 branch July 26, 2025 22:59
@github-actions
Copy link

🎉 This PR is included in version 1.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor type random() methods

2 participants