chore(8.0): final pre-RC1 sweep — API consistency, named errors, orphans, zero-cast codebase
This commit is contained in:
parent
970e08c466
commit
1f7e365a4e
237 changed files with 1951 additions and 49413 deletions
|
|
@ -265,7 +265,7 @@ export abstract class IntegrationBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Query relations using Brainy getRelations()
|
||||
* Query relations using Brainy related()
|
||||
*/
|
||||
protected async queryRelations(params?: {
|
||||
from?: string
|
||||
|
|
@ -278,7 +278,7 @@ export abstract class IntegrationBase {
|
|||
throw new Error('Integration not initialized')
|
||||
}
|
||||
|
||||
return this.context.brain.getRelations(params)
|
||||
return this.context.brain.related(params)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -82,7 +82,12 @@ export interface IntegrationResponse {
|
|||
export class IntegrationHub {
|
||||
private integrations: Map<IntegrationType, IntegrationBase> = new Map()
|
||||
private config: Required<IntegrationHubConfig>
|
||||
private _endpoints: Record<IntegrationType, string> = {} as any
|
||||
/**
|
||||
* Endpoint paths keyed by integration type. Starts empty and gains one key
|
||||
* per integration enabled in initialize() — disabled integrations have no
|
||||
* entry, hence the sparse-record assertion on the initializer.
|
||||
*/
|
||||
private _endpoints: Record<IntegrationType, string> = {} as Record<IntegrationType, string>
|
||||
|
||||
/**
|
||||
* Create and initialize the Integration Hub
|
||||
|
|
@ -168,7 +173,7 @@ export class IntegrationHub {
|
|||
|
||||
private getBasePath(type: IntegrationType): string {
|
||||
const basePath = this.config.basePath
|
||||
const cfg = this.config.config?.[type] as any
|
||||
const cfg = this.config.config?.[type]
|
||||
|
||||
switch (type) {
|
||||
case 'odata':
|
||||
|
|
@ -222,7 +227,13 @@ export class IntegrationHub {
|
|||
if (path.startsWith(basePath) || path === basePath) {
|
||||
const integration = this.integrations.get(type as IntegrationType)
|
||||
if (integration && 'handleRequest' in integration) {
|
||||
const handler = integration as any
|
||||
// The `in` guard proved the integration exposes an HTTP handler.
|
||||
// Each integration declares its own structurally-compatible
|
||||
// request/response shapes (e.g. the OData request/response pair),
|
||||
// so the hub dispatches through this minimal common signature.
|
||||
const handler = integration as IntegrationBase & {
|
||||
handleRequest(request: IntegrationRequest): Promise<IntegrationResponse>
|
||||
}
|
||||
const relativePath = path.slice(basePath.length) || '/'
|
||||
|
||||
return handler.handleRequest({
|
||||
|
|
|
|||
|
|
@ -76,20 +76,29 @@ export const INTEGRATION_CATALOG: Record<IntegrationType, IntegrationInfo> = {
|
|||
* Detect current runtime environment
|
||||
*/
|
||||
export function detectEnvironment(): RuntimeEnvironment {
|
||||
// Runtime-detection boundary: these globals exist only in specific runtimes
|
||||
// (Deno, Bun, Cloudflare Workers), so they aren't on TypeScript's view of
|
||||
// globalThis — probe them through an optional-keyed view.
|
||||
const runtimeGlobals = globalThis as typeof globalThis & {
|
||||
Deno?: unknown
|
||||
Bun?: unknown
|
||||
HTMLRewriter?: unknown
|
||||
}
|
||||
|
||||
// Deno
|
||||
if (typeof (globalThis as any).Deno !== 'undefined') {
|
||||
if (typeof runtimeGlobals.Deno !== 'undefined') {
|
||||
return 'deno'
|
||||
}
|
||||
|
||||
// Bun
|
||||
if (typeof (globalThis as any).Bun !== 'undefined') {
|
||||
if (typeof runtimeGlobals.Bun !== 'undefined') {
|
||||
return 'bun'
|
||||
}
|
||||
|
||||
// Cloudflare Workers
|
||||
if (
|
||||
typeof (globalThis as any).caches !== 'undefined' &&
|
||||
typeof (globalThis as any).HTMLRewriter !== 'undefined'
|
||||
typeof runtimeGlobals.caches !== 'undefined' &&
|
||||
typeof runtimeGlobals.HTMLRewriter !== 'undefined'
|
||||
) {
|
||||
return 'cloudflare'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import { Entity, Relation } from '../../types/brainy.types.js'
|
||||
import { NounType } from '../../types/graphTypes.js'
|
||||
import {
|
||||
TabularRow,
|
||||
RelationTabularRow,
|
||||
|
|
@ -462,9 +463,11 @@ export class TabularExporter {
|
|||
private rowToEntity(row: Record<string, any>): Partial<Entity> {
|
||||
const entity: Partial<Entity> = {}
|
||||
|
||||
// Map standard columns
|
||||
// Map standard columns. Imported rows are an untrusted boundary — the
|
||||
// Type cell is taken at its word here; Brainy validates the NounType
|
||||
// vocabulary when the partial entity is written.
|
||||
if (row.Id) entity.id = row.Id
|
||||
if (row.Type) entity.type = row.Type as any
|
||||
if (row.Type) entity.type = row.Type as NounType
|
||||
if (row.Service) entity.service = row.Service
|
||||
if (row.Confidence) entity.confidence = parseFloat(row.Confidence)
|
||||
if (row.Weight) entity.weight = parseFloat(row.Weight)
|
||||
|
|
|
|||
Reference in a new issue