diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/index.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/index.ts index 1ba6af44c..cbf4b2a86 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/index.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/index.ts @@ -1 +1,2 @@ +export * from './name/index.ts' export * from './validation/index.ts' diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts index 44834c153..ff17469ea 100644 --- a/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/Name.ts @@ -1,24 +1,13 @@ import { assertEx } from '@xylabs/assert' import { isHash } from '@xylabs/hex' import type { Promisable } from '@xylabs/promise' -import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' import type { Payload } from '@xyo-network/payload-model' import type { DomainFields, TopLevelDomain } from '@xyo-network/xns-record-payload-plugins' import { DomainSchema } from '@xyo-network/xns-record-payload-plugins' import { XnsNamePublicValidators } from '../validation/index.ts' - -export type ValidSourceTypes = 'xnsName' | 'hash' | null - -// Escaping special regex characters in the disallowed keys -const escapeRegex = (str: string) => str.replaceAll(/[$()*+.?[\\\]^{|}]/g, String.raw`\$&`) - -// Escaping and then creating the regex -const disallowedCharsPattern = Object.keys(DisallowedModuleIdentifierCharacters) - .map(escapeRegex) - .join('') -// Creating the final regex -const REMOVE_DISALLOWED_CHARS = new RegExp(`[${disallowedCharsPattern}]`, 'g') +import { REMOVE_DISALLOWED_CHARS } from './lib/index.ts' +import type { ValidSourceTypes } from './types/index.ts' export class XnsNameHelper { static ValidTLDs = ['.xyo'] as const diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/index.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/index.ts new file mode 100644 index 000000000..df431fb1d --- /dev/null +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/index.ts @@ -0,0 +1,2 @@ +export * from './Name.ts' +export * from './types/index.ts' diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/RegexHelpers.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/RegexHelpers.ts new file mode 100644 index 000000000..eecc10619 --- /dev/null +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/RegexHelpers.ts @@ -0,0 +1,12 @@ +import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' + +// Escaping special regex characters in the disallowed keys +export const escapeRegex = (str: string) => str.replaceAll(/[$()*+.?[\\\]^{|}]/g, String.raw`\$&`) + +// Escaping and then creating the regex +export const disallowedCharsPattern = Object.keys(DisallowedModuleIdentifierCharacters) + .map(escapeRegex) + .join('') + +// Creating the final regex +export const REMOVE_DISALLOWED_CHARS = new RegExp(`[${disallowedCharsPattern}]`, 'g') diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts new file mode 100644 index 000000000..06ec6c94f --- /dev/null +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts @@ -0,0 +1 @@ +export * from './RegexHelpers.ts' diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/types/ValidSources.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/types/ValidSources.ts new file mode 100644 index 000000000..f969aff60 --- /dev/null +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/types/ValidSources.ts @@ -0,0 +1 @@ +export type ValidSourceTypes = 'xnsName' | 'hash' | null diff --git a/packages/payloadset/packages/xns/plugins/record/src/validation/name/types/index.ts b/packages/payloadset/packages/xns/plugins/record/src/validation/name/types/index.ts new file mode 100644 index 000000000..eed3d7d98 --- /dev/null +++ b/packages/payloadset/packages/xns/plugins/record/src/validation/name/types/index.ts @@ -0,0 +1 @@ +export * from './ValidSources.ts'