Skip to content

Fix TypeScript compilation errors across core, metadata, and objectql packages#542

Merged
hotlong merged 3 commits intomainfrom
copilot/update-analytics-dashboard
Feb 8, 2026
Merged

Fix TypeScript compilation errors across core, metadata, and objectql packages#542
hotlong merged 3 commits intomainfrom
copilot/update-analytics-dashboard

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 8, 2026

CI build failed due to multiple TypeScript type errors across three packages. This PR fixes all compilation errors to restore the build.

Changes

1. @objectstack/core - Security Type Imports

  • Updated imports in packages/core/src/security/security-scanner.ts to use correct type names
  • Changed SecurityVulnerabilityKernelSecurityVulnerability
  • Changed SecurityScanResultKernelSecurityScanResult
  • Updated all type annotations throughout the file (8 occurrences total)
// Before
import type { 
  SecurityVulnerability,
  SecurityScanResult
} from '@objectstack/spec/kernel';

// After
import type { 
  KernelSecurityVulnerability,
  KernelSecurityScanResult
} from '@objectstack/spec/kernel';

2. @objectstack/metadata - Date to String Conversions

  • Fixed memory-loader.ts - Convert Date to ISO string for mtime field
  • Fixed remote-loader.ts - Convert Date to ISO string for mtime field
  • Fixed metadata-manager.ts - Added type assertion for generic return type

The MetadataStats.mtime field is defined as z.string().datetime() in the spec, requiring ISO string format.

3. @objectstack/objectql - HookContext Type Casting

  • Fixed engine.ts - Added explicit type casting for HookContext.input fields (9 locations)
  • HookContext.input is typed as z.record(z.string(), z.unknown()) for flexibility, requiring runtime type assertions

Testing

  • ✅ All 19 packages build successfully
  • ✅ All 3073 tests pass across 97 test files
  • ✅ Zero TypeScript compilation errors
  • ✅ No runtime errors introduced

The changes are minimal and surgical, focusing only on fixing type compatibility issues without altering any business logic or runtime behavior.

Original prompt

引用: https://github.com/objectstack-ai/spec/actions/runs/21785035032/job/62855021869


💡 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.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectstack-studio Ready Ready Preview, Comment Feb 8, 2026 2:41am
spec Ready Ready Preview, Comment Feb 8, 2026 2:41am

Request Review

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Update analytics dashboard for improved usability Fix incorrect type imports in security-scanner.ts Feb 8, 2026
Copilot AI requested a review from hotlong February 8, 2026 01:49
@github-actions github-actions Bot added the size/s label Feb 8, 2026
@hotlong
Copy link
Copy Markdown
Collaborator

hotlong commented Feb 8, 2026

@copilot fix all ci build and test

… packages

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 8, 2026

@copilot fix all ci build and test

Fixed all CI build and test errors across the repository:

  1. @objectstack/core - Fixed TypeScript import errors for security types (commit 45fc055)
  2. @objectstack/metadata - Fixed Date to string conversions and type casting (commit 4b34cc3)
  3. @objectstack/objectql - Fixed HookContext type casting issues (commit 4b34cc3)

Build Status: ✅ All 19 packages build successfully
Test Status: ✅ All 3073 tests pass (97 test files)

Latest commit: 4b34cc3

Copilot AI changed the title Fix incorrect type imports in security-scanner.ts Fix TypeScript compilation errors across core, metadata, and objectql packages Feb 8, 2026
@hotlong hotlong marked this pull request as ready for review February 8, 2026 03:02
Copilot AI review requested due to automatic review settings February 8, 2026 03:02
@hotlong hotlong merged commit 6170cf7 into main Feb 8, 2026
5 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Restores green CI by addressing TypeScript compilation errors across @objectstack/core, @objectstack/metadata, and @objectstack/objectql while keeping behavior changes minimal.

Changes:

  • Updated @objectstack/core security scanner type imports to the correct KernelSecurity* names.
  • Ensured metadata mtime stats are ISO strings (per spec) and adjusted a generic return type in MetadataManager.
  • Added explicit casts in ObjectQL engine where HookContext.input is Record<string, unknown>.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
packages/objectql/src/engine.ts Adds casts around HookContext.input usage to satisfy driver method signatures.
packages/metadata/src/metadata-manager.ts Adds a generic type assertion on returned loader data.
packages/metadata/src/loaders/remote-loader.ts Converts mtime to ISO string for spec compliance.
packages/metadata/src/loaders/memory-loader.ts Converts mtime to ISO string for spec compliance.
packages/core/src/security/security-scanner.ts Renames imported spec types to KernelSecurityVulnerability/KernelSecurityScanResult.

Comment on lines +532 to 537
result = await driver.update(object, hookContext.input.id as string, hookContext.input.data, hookContext.input.options as any);
} else if (options?.multi && driver.updateMany) {
// Bulk update by Query
const ast = this.toQueryAST(object, { filter: options.filter });
result = await driver.updateMany(object, ast, hookContext.input.data, hookContext.input.options);
result = await driver.updateMany(object, ast, hookContext.input.data, hookContext.input.options as any);
} else {
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

Update hooks are conventionally passed the payload in context.input.doc (per @objectstack/spec), but this implementation uses context.input.data. This makes it easy for hook authors to use the wrong key and have their changes ignored. Consider standardizing on doc (or supporting doc ?? data when reading).

Copilot uses AI. Check for mistakes.
let result;
if (hookContext.input.id) {
result = await driver.delete(object, hookContext.input.id, hookContext.input.options);
result = await driver.delete(object, hookContext.input.id as string, hookContext.input.options as any);
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

hookContext.input.id is asserted to string here, but driver IDs are typed as any (and may be numbers/UUID objects depending on the driver). The as string assertion can mislead callers/maintainers and hides mismatches. Prefer leaving it as unknown narrowed/cast to the driver’s expected id type (typically any), or validate/coerce explicitly if a string ID is required.

Suggested change
result = await driver.delete(object, hookContext.input.id as string, hookContext.input.options as any);
// Pass ID through without falsely asserting it is a string; drivers accept any ID type.
result = await driver.delete(object, hookContext.input.id as any, hookContext.input.options as any);

Copilot uses AI. Check for mistakes.
Comment on lines 105 to 108
size: Number(response.headers.get('content-length') || 0),
mtime: new Date(response.headers.get('last-modified') || Date.now()),
mtime: new Date(response.headers.get('last-modified') || Date.now()).toISOString(),
format: 'json',
};
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

new Date(response.headers.get('last-modified') || Date.now()).toISOString() will throw a RangeError if last-modified is present but not parseable as a date. Consider guarding against invalid dates (e.g., check Number.isNaN(date.getTime()) and omit mtime or fall back to new Date().toISOString()).

Copilot uses AI. Check for mistakes.
if (hookContext.input.id) {
// Single update by ID
result = await driver.update(object, hookContext.input.id, hookContext.input.data, hookContext.input.options);
result = await driver.update(object, hookContext.input.id as string, hookContext.input.data, hookContext.input.options as any);
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

hookContext.input.id is asserted to string when passed to driver.update, but the driver contract accepts id: any and some drivers may use non-string IDs. Prefer avoiding the as string assertion here (or explicitly coercing/validating if ObjectQL requires string IDs).

Suggested change
result = await driver.update(object, hookContext.input.id as string, hookContext.input.data, hookContext.input.options as any);
result = await driver.update(object, hookContext.input.id, hookContext.input.data, hookContext.input.options as any);

Copilot uses AI. Check for mistakes.
Comment on lines +440 to +446
const result = await driver.find(object, hookContext.input.ast as QueryAST, hookContext.input.options as any);

hookContext.event = 'afterFind';
hookContext.result = result;
await this.triggerHooks('afterFind', hookContext);

return hookContext.result;
return hookContext.result as any[];
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

HookContext in @objectstack/spec documents find input as { query, options }, but this code reads hookContext.input.ast. That means beforeFind hooks written against the spec (e.g. mutating context.input.query) won’t affect the executed query. Consider standardizing on input.query (or supporting both query and legacy ast when reading from the context) before calling the driver.

Copilot uses AI. Check for mistakes.
Comment on lines +483 to 490
result = await driver.bulkCreate(object, hookContext.input.data as any[], hookContext.input.options as any);
} else {
// Fallback loop
result = await Promise.all(hookContext.input.data.map((item: any) => driver.create(object, item, hookContext.input.options)));
result = await Promise.all((hookContext.input.data as any[]).map((item: any) => driver.create(object, item, hookContext.input.options as any)));
}
} else {
result = await driver.create(object, hookContext.input.data, hookContext.input.options);
result = await driver.create(object, hookContext.input.data, hookContext.input.options as any);
}
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

The spec’s HookContext convention for inserts is input.doc, but this code relies on hookContext.input.data. Hooks expecting context.input.doc won’t be able to validate/transform the inserted document. Consider switching to doc (or reading doc ?? data for backward compatibility) throughout the insert flow.

Copilot uses AI. Check for mistakes.
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.

3 participants