fix(typert): address remote gateway review
This commit is contained in:
@@ -7,6 +7,17 @@
|
||||
import { Service, type Context } from 'cordis'
|
||||
import type { TypeRTContextMap } from './types.ts'
|
||||
|
||||
const TYPERT_REMOTE_SEGMENT_PATTERN = /^[A-Za-z0-9_$.-]+$/
|
||||
|
||||
/**
|
||||
* Test one generated Remote name against the Connection endpoint grammar.
|
||||
* @param value - namespace, method, lookup, or Context segment.
|
||||
* @returns whether the value can cross the shared RPC carrier unchanged.
|
||||
*/
|
||||
export function isTypeRTRemoteSegment(value: string): boolean {
|
||||
return TYPERT_REMOTE_SEGMENT_PATTERN.test(value)
|
||||
}
|
||||
|
||||
export type {
|
||||
InvocationDescriptor,
|
||||
InvocationParameterDescriptor,
|
||||
@@ -236,7 +247,7 @@ function sameInvocation(left: RemoteInvocationMarker, right: RemoteInvocationMar
|
||||
}
|
||||
|
||||
function validateName(subject: string, value: string): void {
|
||||
if (value.length === 0 || value.includes('/')) {
|
||||
throw new TypeError(`type-meta: ${subject} must be nonempty and must not contain "/"`)
|
||||
if (!isTypeRTRemoteSegment(value)) {
|
||||
throw new TypeError(`type-meta: ${subject} must contain only RPC endpoint segment characters`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +162,8 @@ describe('type-meta Remote declarations', () => {
|
||||
const method: (this: object) => void = function (this: object): void {}
|
||||
expect(() => { (Remote as unknown as (value: typeof method) => void)(method) }).toThrow('context is missing')
|
||||
expect(() => Remote('bad/name')).toThrow('export name')
|
||||
expect(() => Remote('bad#name')).toThrow('export name')
|
||||
expect(() => Remote('bad name')).toThrow('export name')
|
||||
expect(() => RemoteContext('' as 'metaFixture')).toThrow('Context key')
|
||||
expect(() => RemoteContext('metaFixture', 'bad/name')).toThrow('export name')
|
||||
|
||||
@@ -203,6 +205,7 @@ describe('type-meta Remote declarations', () => {
|
||||
it('rejects ambiguous binding names', () => {
|
||||
expect(() => bindTypeRTGateway({}, '')).toThrow('service key')
|
||||
expect(() => bindTypeRTGateway({}, 'goals', { namespace: 'api/goals' })).toThrow('namespace')
|
||||
expect(() => bindTypeRTGateway({}, 'goals', { namespace: 'api goals' })).toThrow('namespace')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user