@xyo-network/payload-model 5.1.5 → 5.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -137,4 +137,17 @@ export declare function WithStorageMetaZod<T extends typeof PayloadZod>(valueZod
|
|
|
137
137
|
__schema: true;
|
|
138
138
|
}, string>>]>;
|
|
139
139
|
}, z.core.$strip>;
|
|
140
|
+
export declare const PayloadZodStrict: z.ZodObject<{
|
|
141
|
+
schema: z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodString, z.ZodTransform<string & {
|
|
142
|
+
__schema: true;
|
|
143
|
+
}, string>>]>;
|
|
144
|
+
}, z.core.$strict>;
|
|
145
|
+
export type PayloadZodStrict = typeof PayloadZodStrict;
|
|
146
|
+
export declare const PayloadZodLoose: PayloadZodStrict;
|
|
147
|
+
export declare const PayloadZodStrictOfSchema: <S extends string>(schema: S) => z.ZodObject<{
|
|
148
|
+
schema: z.ZodLiteral<S>;
|
|
149
|
+
}, z.core.$strict>;
|
|
150
|
+
export declare const PayloadZodLooseOfSchema: <S extends string>(schema: S) => z.ZodObject<{
|
|
151
|
+
schema: z.ZodLiteral<S>;
|
|
152
|
+
}, z.core.$strict>;
|
|
140
153
|
//# sourceMappingURL=PayloadZod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PayloadZod.d.ts","sourceRoot":"","sources":["../../src/PayloadZod.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAKxB,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAIzB,CAAA;AAEF,eAAO,MAAM,UAAU;;;;iBAAkC,CAAA;AACzD,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAA0C,CAAA;AAEhF,eAAO,MAAM,aAAa;;;;qCAAgC,CAAA;AAC1D,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;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,gBAAgB;;;;kBAAwC,CAAA;AACrE,MAAM,MAAM,gBAAgB,GAAG,OAAO,gBAAgB,CAAA;AACtD,eAAO,MAAM,eAAe,EAAE,gBAAuD,CAAA;AAErF,eAAO,MAAM,wBAAwB,GAAI,CAAC,SAAS,MAAM,EAAE,QAAQ,CAAC;;kBAA2D,CAAA;AAC/H,eAAO,MAAM,uBAAuB,GAAI,CAAC,SAAS,MAAM,EAAE,QAAQ,CAAC;;kBAA0D,CAAA"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -298,6 +298,10 @@ var AnyPayloadWithStorageMetaZod = AnyPayloadZod.extend(StorageMetaZod.shape);
|
|
|
298
298
|
function WithStorageMetaZod(valueZod) {
|
|
299
299
|
return StorageMetaZod.extend(valueZod.shape);
|
|
300
300
|
}
|
|
301
|
+
var PayloadZodStrict = z3.strictObject({ schema: SchemaZod });
|
|
302
|
+
var PayloadZodLoose = z3.looseObject({ schema: SchemaZod });
|
|
303
|
+
var PayloadZodStrictOfSchema = (schema) => PayloadZodStrict.extend({ schema: z3.literal(schema) });
|
|
304
|
+
var PayloadZodLooseOfSchema = (schema) => PayloadZodLoose.extend({ schema: z3.literal(schema) });
|
|
301
305
|
export {
|
|
302
306
|
AnyPayloadWithStorageMetaZod,
|
|
303
307
|
AnyPayloadZod,
|
|
@@ -311,6 +315,10 @@ export {
|
|
|
311
315
|
PayloadSetSchema,
|
|
312
316
|
PayloadWithStorageMetaZod,
|
|
313
317
|
PayloadZod,
|
|
318
|
+
PayloadZodLoose,
|
|
319
|
+
PayloadZodLooseOfSchema,
|
|
320
|
+
PayloadZodStrict,
|
|
321
|
+
PayloadZodStrictOfSchema,
|
|
314
322
|
QualifiedSequenceConstants,
|
|
315
323
|
QualifiedSequenceFromStringZod,
|
|
316
324
|
QualifiedSequenceToStringZod,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadOfZodType.ts","../../src/PayloadBundle.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/PayloadZod.ts","../../src/Schema.ts","../../src/StorageMeta/DataHash.ts","../../src/StorageMeta/Hash.ts","../../src/StorageMeta/Sequence.ts","../../src/StorageMeta/sequence/Parser.ts","../../src/StorageMeta/sequence/Sequence.ts","../../src/StorageMeta/sequence/Comparer.ts","../../src/StorageMeta/sequence/SequenceZod.ts","../../src/StorageMeta/StorageMeta.ts"],"sourcesContent":["import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport type { Payload } from './Payload.ts'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof (value as Payload).schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload\n = <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.ts'\nimport type { Payload, WithSources } from './Payload.ts'\n\nexport function isPayloadOfSchemaType<T extends Payload | never = never>(schema: T['schema']) {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload | never = never>(schema: T['schema']) => {\n return (x?: unknown | null): x is WithSources<T> =>\n isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.$sources != undefined && Array.isArray(x.$sources)\n}\n\nexport const notPayloadOfSchemaType = <T extends Payload | never = never>(schema: T['schema']) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n\n// test types -- keep for future validation, but comment out\n\n/*\ntype TestSchema = 'network.xyo.test'\nconst TestSchema: TestSchema = 'network.xyo.test'\n\ntype Test = Payload<{ field: string }, TestSchema>\n\nconst testPayload: Test = { field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType<Payload>(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n*/\n","import type { Hash } from '@xylabs/hex'\nimport type { JsonValue } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.ts'\nimport type { Payload } from './Payload.ts'\nimport type { Schema } from './Schema.ts'\n\nexport const ModuleErrorSchema = 'network.xyo.error.module' as const\nexport type ModuleErrorSchema = typeof ModuleErrorSchema\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash | Schema\n schema: ModuleErrorSchema\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isDefined } from '@xylabs/typeof'\nimport type { ZodObject } from 'zod'\n\nimport { isAnyPayload } from './isPayload.ts'\nimport type { Payload } from './Payload.ts'\n\n/**\n * Checks if a value is a payload of a specific Zod type.\n * @param zodSchema The Zod schema to validate against\n * @param schema The schema string to match against the payload. Optional in\n * case you want to validate any payload matching the Zod schema or in case\n * schema is part of the Zod schema.\n * @returns A function that checks if a value is a payload of the specified Zod type\n */\nexport function isPayloadOfZodType<\n T extends Payload | never = never,\n S extends ZodObject = ZodObject,\n>(zodSchema: S, schema?: T['schema']) {\n return (x?: unknown | null): x is T => {\n if (!isAnyPayload(x)) return false\n if (isDefined(schema) && x.schema !== schema) return false\n const { schema: _, ...data } = x\n return zodSchema.safeParse(data).success\n }\n}\n","import type { Hash } from '@xylabs/hex'\nimport { AsObjectFactory } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.ts'\nimport type { Payload } from './Payload.ts'\n\n// payload that wraps a complete boundwitness with its payloads for use in systems such as submission queues\nexport const PayloadBundleSchema = 'network.xyo.payload.bundle' as const\nexport type PayloadBundleSchema = typeof PayloadBundleSchema\n\nexport interface PayloadBundleFields<T extends Payload = Payload> {\n payloads: T[]\n root: Hash\n}\n\nexport type PayloadBundle = Payload<PayloadBundleFields, PayloadBundleSchema>\n\nexport const isPayloadBundle = isPayloadOfSchemaType<PayloadBundle>(PayloadBundleSchema)\n\nexport const asPayloadBundle = AsObjectFactory.create(isPayloadBundle)\nexport const asOptionalPayloadBundle = AsObjectFactory.createOptional(isPayloadBundle)\n","export const PayloadSetSchema = 'network.xyo.payload.set' as const\nexport type PayloadSetSchema = typeof PayloadSetSchema\n","import { HashToJsonZod } from '@xylabs/hex'\nimport * as z from 'zod'\n\nimport { SchemaZod } from './Schema.ts'\nimport { SequenceToStringZod } from './StorageMeta/index.ts'\n\nexport const StorageMetaZod = z.object({\n _hash: HashToJsonZod,\n _dataHash: HashToJsonZod,\n _sequence: SequenceToStringZod,\n})\n\nexport const PayloadZod = z.object({ schema: SchemaZod })\nexport const PayloadWithStorageMetaZod = PayloadZod.extend(StorageMetaZod.shape)\n\nexport const AnyPayloadZod = PayloadZod.catchall(z.json())\nexport const AnyPayloadWithStorageMetaZod = AnyPayloadZod.extend(StorageMetaZod.shape)\n\nexport type PayloadWithStorageMeta = z.infer<typeof PayloadWithStorageMetaZod>\n\nexport type AnyPayload = z.infer<typeof AnyPayloadZod>\nexport type AnyPayloadWithStorageMeta = z.infer<typeof AnyPayloadWithStorageMetaZod>\n\nexport function WithStorageMetaZod<T extends typeof PayloadZod>(valueZod: T) {\n return StorageMetaZod.extend(valueZod.shape)\n}\n","import type { EmptyObject } from '@xylabs/object'\nimport { AsTypeFactory } from '@xylabs/object'\nimport * as z from 'zod'\n\nexport const SchemaRegEx = /^(?:[a-z0-9]+\\.)*[a-z0-9]+$/\n\nexport const SchemaZodV1 = z.string().regex(SchemaRegEx)\nexport const SchemaZodV2 = z.string().regex(SchemaRegEx).transform(x => x as (typeof x & { __schema: true }))\nexport type SchemaV2 = z.output<typeof SchemaZodV2>\nexport type SchemaV1 = z.output<typeof SchemaZodV1>\nexport const SchemaZod = z.union([SchemaZodV1, SchemaZodV2])\nexport type Schema = z.infer<typeof SchemaZodV1>\n\nexport const makeSchema = <T extends string>(value: T) => {\n return (z.templateLiteral([z.literal(value)])).transform(x => x as (typeof x & { __schema: true }))\n}\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport const PayloadSchemaZod = z.literal(PayloadSchema)\nexport type PayloadSchema = z.infer<typeof PayloadSchemaZod>\n\nexport const isSchema = (value: unknown): value is Schema => {\n return SchemaZod.safeParse(value).error === undefined\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n","import type { Hash } from '@xylabs/hex'\nimport { isHash } from '@xylabs/hex'\nimport { AsObjectFactory } from '@xylabs/object'\n\nimport type { Payload } from '../Payload.ts'\n\nexport interface DataHashStorageMeta {\n _dataHash: Hash\n}\n\nexport type WithDataHashStorageMeta<T extends Payload = Payload> = T & DataHashStorageMeta\nexport type WithPartialDataHashStorageMeta<T extends Payload = Payload> = Partial<WithDataHashStorageMeta<T>>\n\nexport const isDataHashStorageMeta = (value: unknown): value is DataHashStorageMeta => {\n return isHash((value as WithDataHashStorageMeta)?._dataHash)\n}\n\nexport const asDataHashStorageMeta = AsObjectFactory.create<DataHashStorageMeta>(isDataHashStorageMeta)\nexport const asOptionalDataHashStorageMeta = AsObjectFactory.createOptional<DataHashStorageMeta>(isDataHashStorageMeta)\n","import type { Hash } from '@xylabs/hex'\nimport { isHash } from '@xylabs/hex'\nimport { AsObjectFactory } from '@xylabs/object'\n\nimport type { Payload } from '../Payload.ts'\nimport type { DataHashStorageMeta } from './DataHash.ts'\nimport { isDataHashStorageMeta } from './DataHash.ts'\n\nexport interface HashStorageMeta extends DataHashStorageMeta {\n _hash: Hash\n}\n\nexport type WithHashStorageMeta<T extends Payload = Payload> = T & HashStorageMeta\nexport type WithPartialHashStorageMeta<T extends Payload = Payload> = Partial<WithHashStorageMeta<T>>\n\nexport const isHashStorageMeta = (value: unknown): value is HashStorageMeta => {\n return isDataHashStorageMeta(value) && isHash((value as WithHashStorageMeta)?._hash)\n}\n\nexport const asHashStorageMeta = AsObjectFactory.create<HashStorageMeta>(isHashStorageMeta)\nexport const asOptionalHashStorageMeta = AsObjectFactory.createOptional<HashStorageMeta>(isHashStorageMeta)\n","import { AsObjectFactory } from '@xylabs/object'\n\nimport type { Payload } from '../Payload.ts'\nimport type { Sequence } from './sequence/index.ts'\n\nexport interface SequenceStorageMeta {\n _sequence: Sequence\n}\n\nexport type WithSequenceStorageMeta<T extends Payload = Payload> = T & SequenceStorageMeta\nexport type WithPartialSequenceStorageMeta<T extends Payload = Payload> = Partial<WithSequenceStorageMeta<T>>\n\nexport const isSequenceStorageMeta = (value: unknown): value is SequenceStorageMeta => {\n return (value as WithSequenceStorageMeta)?._sequence != undefined\n}\n\nexport const asSequenceStorageMeta = AsObjectFactory.create(isSequenceStorageMeta)\nexport const asOptionalSequenceStorageMeta = AsObjectFactory.createOptional(isSequenceStorageMeta)\n","import { toUint8Array } from '@xylabs/arraybuffer'\nimport { assertEx } from '@xylabs/assert'\nimport type {\n Address,\n Hash, Hex,\n} from '@xylabs/hex'\nimport {\n isAddress,\n toAddress,\n toHex,\n} from '@xylabs/hex'\n\nimport type {\n Epoch, LocalSequence, Nonce, QualifiedSequence,\n Sequence,\n} from './Sequence.ts'\nimport {\n isQualifiedSequence, isSequence,\n SequenceConstants,\n} from './Sequence.ts'\n\nexport class SequenceParser {\n protected static privateConstructorKey = Date.now().toString()\n\n private readonly data: Readonly<Uint8Array>\n\n protected constructor(privateConstructorKey: string, hex: Hex) {\n assertEx(SequenceParser.privateConstructorKey === privateConstructorKey, () => 'Use create function instead of constructor')\n const paddedHex = toHex(hex, {\n prefix: false,\n bitLength: (hex.length <= SequenceConstants.localSequenceBytes * 2)\n ? SequenceConstants.localSequenceBytes * 8\n : SequenceConstants.qualifiedSequenceBytes * 8,\n })\n this.data = toUint8Array(paddedHex)\n }\n\n get address(): Address {\n const start = SequenceConstants.localSequenceBytes\n const end = SequenceConstants.qualifiedSequenceBytes\n return toAddress(this.data.slice(start, end).buffer, { prefix: false })\n }\n\n get epoch(): Epoch {\n const start = 0\n const end = SequenceConstants.epochBytes\n return toHex(this.data.slice(start, end).buffer, { prefix: false }) as Epoch\n }\n\n get localSequence(): LocalSequence {\n const start = 0\n const end = SequenceConstants.localSequenceBytes\n return toHex(this.data.slice(start, end).buffer, { prefix: false }) as LocalSequence\n }\n\n get nonce(): Nonce {\n const start = SequenceConstants.epochBytes\n const end = SequenceConstants.localSequenceBytes\n return toHex(this.data.slice(start, end).buffer, { prefix: false }) as Nonce\n }\n\n get qualifiedSequence(): QualifiedSequence {\n const start = 0\n const end = SequenceConstants.qualifiedSequenceBytes\n return toHex(this.data.slice(start, end).buffer, { prefix: false }) as QualifiedSequence\n }\n\n static from(sequence: Sequence, address?: Address): SequenceParser\n static from(timestamp: Hex, hash: Hash, address?: Address): SequenceParser\n static from(timestamp: Hex, hash: Hex, address?: Address): SequenceParser\n static from(timestamp: Hex, nonce: Nonce, address?: Address): SequenceParser\n static from(timestamp: Hex, hash: Hash, index?: number, address?: Address): SequenceParser\n static from(timestamp: Hex, hash: Hex, index?: number, address?: Address): SequenceParser\n static from(timestamp: Hex, nonce: Nonce, index?: number, address?: Address): SequenceParser\n static from(timestamp: number, hash: Hash, address?: Address): SequenceParser\n static from(timestamp: number, hash: Hex, address?: Address): SequenceParser\n static from(timestamp: number, nonce: Nonce, address?: Address): SequenceParser\n static from(timestamp: number, hash: Hash, index?: number, address?: Address): SequenceParser\n static from(timestamp: number, hash: Hex, index?: number, address?: Address): SequenceParser\n static from(timestamp: number, nonce: Nonce, index?: number, address?: Address): SequenceParser\n static from(\n timestampOrSequence: Hex | number,\n nonceOrAddress?: Hex,\n addressOrIndex?: Address | number,\n addressOnly?: Address,\n ): SequenceParser {\n const address = typeof addressOrIndex === 'number' ? addressOnly : addressOrIndex\n const index = typeof addressOrIndex === 'number' ? addressOrIndex : undefined\n if (isSequence(timestampOrSequence)) {\n if (nonceOrAddress) {\n assertEx(!isQualifiedSequence(timestampOrSequence), () => 'Providing both a qualified sequence and a address is not allowed')\n assertEx(isAddress(nonceOrAddress), () => 'Invalid address provided')\n return new this(SequenceParser.privateConstructorKey, (timestampOrSequence + address) as Hex)\n }\n return new this(SequenceParser.privateConstructorKey, timestampOrSequence)\n }\n const epoch = SequenceParser.toEpoch(timestampOrSequence)\n const nonce = nonceOrAddress === undefined ? undefined : SequenceParser.toNonce(nonceOrAddress, index)\n const addressHex: Hex = address ? toHex(address, { bitLength: SequenceConstants.addressBytes * 8 }) : SequenceConstants.minAddress\n const hexString = (epoch + nonce + addressHex) as Hex\n assertEx(isSequence(hexString), () => `Invalid sequence [${hexString}] [${epoch}, ${nonce}, ${addressHex}]`)\n return new this(SequenceParser.privateConstructorKey, hexString)\n }\n\n static parse(value: Hex | string | ArrayBufferLike): SequenceParser {\n const hex = toHex(value)\n if (isSequence(hex)) {\n return new this(SequenceParser.privateConstructorKey, hex)\n }\n throw new Error(`Invalid sequence [${value}]`)\n }\n\n // can convert a short number/hex to an epoch (treats it as the whole value) or extract an epoch from a sequence\n static toEpoch(value: number | Hex | Epoch): Epoch {\n assertEx(\n typeof value !== 'number' || Number.isInteger(value),\n () => 'Value must be in integer',\n )\n const hex = toHex(value, { prefix: false })\n if (hex.length <= SequenceConstants.epochBytes * 2) {\n return toHex(value, { prefix: false, bitLength: SequenceConstants.epochBytes * 8 }) as Epoch\n }\n if (isSequence(hex)) {\n return hex.slice(0, SequenceConstants.epochBytes * 2) as Epoch\n }\n throw new Error(`Value could not be converted to epoch [${hex}]`)\n }\n\n // can convert a short number/hex to a nonce (treats it as the whole value) or extract an nonce from a sequence\n static toNonce(value: Hash | Hex, index = 0): Nonce {\n assertEx(\n typeof value !== 'number' || Number.isInteger(value),\n () => 'Value must be in integer',\n )\n const hex = toHex(value, { prefix: false })\n if (isSequence(hex)) {\n return hex.slice(SequenceConstants.epochBytes * 2, SequenceConstants.localSequenceBytes * 2) as Nonce\n }\n const hashHex = toHex((hex as string), { prefix: false, bitLength: SequenceConstants.nonceHashBytes * 8 }).slice(-SequenceConstants.nonceHashBytes * 2)\n const indexHex = toHex(index, { prefix: false, bitLength: SequenceConstants.nonceIndexBytes * 8 }).slice(-SequenceConstants.nonceIndexBytes * 2)\n return (indexHex + hashHex).slice(-SequenceConstants.nonceBytes * 2) as Nonce\n }\n}\n","import type { Address, Hex } from '@xylabs/hex'\nimport { isHex } from '@xylabs/hex'\nimport type { Brand } from '@xylabs/typeof'\n\n// we use Exclude to intentionally make the type not equal to string\nexport type LocalSequence = Brand<Hex, { __localSequence: true }>\nexport type QualifiedSequence = Brand<Hex, { __qualifiedSequence: true }>\nexport type Sequence = LocalSequence | QualifiedSequence\n\nexport type Epoch = Brand<Hex, { __epoch: true }>\n\nexport const isEpoch = (value: unknown): value is Epoch => {\n return isHex(value) && (value as string).length === SequenceConstants.epochBytes * 2\n}\n\nexport type Nonce = Brand<Hex, { __nonce: true }>\n\nexport const isNonce = (value: unknown): value is Nonce => {\n return isHex(value) && (value as string).length === SequenceConstants.nonceBytes * 2\n}\n\nexport const isLocalSequence = (value: unknown): value is LocalSequence => {\n return isHex(value) && (value as string).length === SequenceConstants.localSequenceBytes * 2\n}\n\nexport const isQualifiedSequence = (value: unknown): value is QualifiedSequence => {\n return isHex(value) && (value as string).length === SequenceConstants.qualifiedSequenceBytes * 2\n}\n\nexport const isSequence = (value: unknown): value is Sequence => {\n return isLocalSequence(value) || isQualifiedSequence(value)\n}\n\nexport const SequenceNonceComponentLengths = {\n nonceIndexBytes: 4,\n nonceHashBytes: 4,\n}\n\nexport const SequenceComponentLengths = {\n ...SequenceNonceComponentLengths,\n epochBytes: 8,\n nonceBytes: SequenceNonceComponentLengths.nonceIndexBytes + SequenceNonceComponentLengths.nonceHashBytes,\n addressBytes: 20,\n}\n\nexport const SequenceComponentMinMax = {\n minEpoch: '0'.repeat(SequenceComponentLengths.epochBytes * 2) as Epoch,\n maxEpoch: 'f'.repeat(SequenceComponentLengths.epochBytes * 2) as Epoch,\n minNonce: '0'.repeat(SequenceComponentLengths.nonceBytes * 2) as Nonce,\n maxNonce: 'f'.repeat(SequenceComponentLengths.nonceBytes * 2) as Nonce,\n minAddress: '0'.repeat(SequenceComponentLengths.addressBytes * 2) as Address,\n maxAddress: 'f'.repeat(SequenceComponentLengths.addressBytes * 2) as Address,\n}\n\nexport const LocalSequenceConstants = {\n ...SequenceComponentLengths,\n ...SequenceComponentMinMax,\n localSequenceBytes: SequenceComponentLengths.epochBytes + SequenceComponentLengths.nonceBytes,\n minLocalSequence: SequenceComponentMinMax.minEpoch + SequenceComponentMinMax.minNonce as LocalSequence,\n maxLocalSequence: SequenceComponentMinMax.maxEpoch + SequenceComponentMinMax.maxNonce as LocalSequence,\n}\n\nexport const QualifiedSequenceConstants = {\n qualifiedSequenceBytes: LocalSequenceConstants.localSequenceBytes + SequenceComponentLengths.addressBytes,\n minQualifiedSequence: LocalSequenceConstants.minLocalSequence + SequenceComponentMinMax.minAddress as QualifiedSequence,\n maxQualifiedSequence: LocalSequenceConstants.maxLocalSequence + SequenceComponentMinMax.maxAddress as QualifiedSequence,\n}\n\nexport const SequenceConstants = {\n ...LocalSequenceConstants,\n ...QualifiedSequenceConstants,\n}\n\n// \"11111111111111112222222222222222\" is and example of a local sequence string\n\n// \"111111111111111122222222222222223333333333333333333333333333333333333333\" is and example of a local sequence string\n// epoch = \"1111111111111111\"\n// nonce = \"2222222222222222\"\n// address = \"3333333333333333333333333333333333333333\"\n","import type { Compare } from '@xylabs/object'\n\nimport { SequenceParser } from './Parser.ts'\nimport type { Sequence } from './Sequence.ts'\n\nconst local: Compare<Sequence> = (a, b) => {\n const aa = SequenceParser.from(a)\n const bb = SequenceParser.from(b)\n return aa.localSequence > bb.localSequence ? 1 : aa.localSequence < bb.localSequence ? -1 : 0\n}\n\nconst qualified: Compare<Sequence> = (a, b) => {\n const aa = SequenceParser.from(a)\n const bb = SequenceParser.from(b)\n return aa.qualifiedSequence > bb.qualifiedSequence ? 1 : aa.qualifiedSequence < bb.qualifiedSequence ? -1 : 0\n}\n\nexport const SequenceComparer = { local, qualified }\n","import { HexRegExMinMax, toHex } from '@xylabs/hex'\nimport * as z from 'zod'\n\nimport type { LocalSequence, QualifiedSequence } from './Sequence.ts'\nimport { SequenceConstants } from './Sequence.ts'\n\nconst LocalSequenceRegex = new RegExp(HexRegExMinMax(SequenceConstants.localSequenceBytes, SequenceConstants.localSequenceBytes))\nexport const LocalSequenceToStringZod = z.string().regex(LocalSequenceRegex)\nexport const LocalSequenceFromStringZod = z.string().regex(LocalSequenceRegex).transform<LocalSequence>(v => toHex(v) as LocalSequence)\n\nconst QualifiedSequenceRegex = new RegExp(HexRegExMinMax(SequenceConstants.qualifiedSequenceBytes, SequenceConstants.qualifiedSequenceBytes))\nexport const QualifiedSequenceToStringZod = z.string().regex(QualifiedSequenceRegex)\nexport const QualifiedSequenceFromStringZod = z.string().regex(QualifiedSequenceRegex).transform<QualifiedSequence>(v => toHex(v) as QualifiedSequence)\n\nexport const SequenceToStringZod = z.union([LocalSequenceToStringZod, QualifiedSequenceToStringZod])\nexport const SequenceFromStringZod = z.union([LocalSequenceFromStringZod, QualifiedSequenceFromStringZod])\n","import { AsObjectFactory } from '@xylabs/object'\n\nimport type { Payload } from '../Payload.ts'\nimport type { HashStorageMeta } from './Hash.ts'\nimport { isHashStorageMeta } from './Hash.ts'\nimport type { SequenceStorageMeta } from './Sequence.ts'\nimport { isSequenceStorageMeta } from './Sequence.ts'\n\nexport interface StorageMeta extends SequenceStorageMeta, HashStorageMeta {}\n\nexport type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta\nexport type WithPartialStorageMeta<T extends Payload = Payload> = T & Partial<StorageMeta>\n\nexport const isStorageMeta = (value: unknown): value is StorageMeta => {\n return isSequenceStorageMeta(value) && isHashStorageMeta(value)\n}\n\nexport const asStorageMeta = AsObjectFactory.create(isStorageMeta)\nexport const asOptionalStorageMeta = AsObjectFactory.createOptional(isStorageMeta)\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAgB;AAInC,IAAM,eAAe,CAAC,UAAqC;AAChE,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,OAAQ,MAAkB,WAAW;AAAA,EAC9C;AACA,SAAO;AACT;AAEO,IAAM,eAAe,gBAAgB,OAAO,YAAY;AAExD,IAAM,YACT,CAAoB,WACpB,CAAC,UAA+B;AAC9B,MAAI,aAAa,KAAK,GAAG;AACvB,WAAO,OAAO,SAAS,MAAM,MAAM;AAAA,EACrC;AACA,SAAO;AACT;AAEG,IAAM,YAAY,CAAoB,WAAqB,gBAAgB,OAAO,CAAC,UAA+B,UAAU,MAAM,EAAE,KAAK,CAAC;;;ACnB1I,SAAS,sBAAyD,QAAqB;AAC5F,SAAO,CAAC,MAA+B,aAAa,CAAC,KAAK,GAAG,WAAW;AAC1E;AAEO,IAAM,mCAAmC,CAAoC,WAAwB;AAC1G,SAAO,CAAC,MACN,sBAAsC,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,UAAa,MAAM,QAAQ,EAAE,QAAQ;AAC3G;AAEO,IAAM,yBAAyB,CAAoC,WAAwB;AAChG,SAAO,CAAC,MAA+B,CAAC,aAAa,CAAC,KAAK,GAAG,WAAW;AAC3E;;;ACPO,IAAM,oBAAoB;AAW1B,IAAM,gBAAgB,sBAAmC,iBAAiB;;;AClBjF,SAAS,iBAAiB;AAcnB,SAAS,mBAGd,WAAc,QAAsB;AACpC,SAAO,CAAC,MAA+B;AACrC,QAAI,CAAC,aAAa,CAAC,EAAG,QAAO;AAC7B,QAAI,UAAU,MAAM,KAAK,EAAE,WAAW,OAAQ,QAAO;AACrD,UAAM,EAAE,QAAQ,GAAG,GAAG,KAAK,IAAI;AAC/B,WAAO,UAAU,UAAU,IA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AAS,mBAAAC,wBAAuB;AAazB,IAAM,gBAAgB,CAAC,UAAyC;AACrE,SAAO,sBAAsB,KAAK,KAAK,kBAAkB,KAAK;AAChE;AAEO,IAAM,gBAAgBC,iBAAgB,OAAO,aAAa;AAC1D,IAAM,wBAAwBA,iBAAgB,eAAe,aAAa;;;ATZ1E,IAAM,iBAAmB,UAAO;AAAA,EACrC,OAAO;AAAA,EACP,WAAW;AAAA,EACX,WAAW;AACb,CAAC;AAEM,IAAM,aAAe,UAAO,EAAE,QAAQ,UAAU,CAAC;AACjD,IAAM,4BAA4B,WAAW,OAAO,eAAe,KAAK;AAExE,IAAM,gBAAgB,WAAW,SAAW,QAAK,CAAC;AAClD,IAAM,+BAA+B,cAAc,OAAO,eAAe,KAAK;AAO9E,SAAS,mBAAgD,UAAa;AAC3E,SAAO,eAAe,OAAO,SAAS,KAAK;AAC7C;","names":["AsObjectFactory","AsObjectFactory","z","AsObjectFactory","isHash","AsObjectFactory","isHash","AsObjectFactory","AsObjectFactory","toHex","z","toHex","AsObjectFactory","AsObjectFactory"]}
|
|
1
|
+
{"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadOfZodType.ts","../../src/PayloadBundle.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/PayloadZod.ts","../../src/Schema.ts","../../src/StorageMeta/DataHash.ts","../../src/StorageMeta/Hash.ts","../../src/StorageMeta/Sequence.ts","../../src/StorageMeta/sequence/Parser.ts","../../src/StorageMeta/sequence/Sequence.ts","../../src/StorageMeta/sequence/Comparer.ts","../../src/StorageMeta/sequence/SequenceZod.ts","../../src/StorageMeta/StorageMeta.ts"],"sourcesContent":["import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport type { Payload } from './Payload.ts'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof (value as Payload).schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload\n = <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.ts'\nimport type { Payload, WithSources } from './Payload.ts'\n\nexport function isPayloadOfSchemaType<T extends Payload | never = never>(schema: T['schema']) {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload | never = never>(schema: T['schema']) => {\n return (x?: unknown | null): x is WithSources<T> =>\n isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.$sources != undefined && Array.isArray(x.$sources)\n}\n\nexport const notPayloadOfSchemaType = <T extends Payload | never = never>(schema: T['schema']) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n\n// test types -- keep for future validation, but comment out\n\n/*\ntype TestSchema = 'network.xyo.test'\nconst TestSchema: TestSchema = 'network.xyo.test'\n\ntype Test = Payload<{ field: string }, TestSchema>\n\nconst testPayload: Test = { field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType<Payload>(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n*/\n","import type { Hash } from '@xylabs/hex'\nimport type { JsonValue } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.ts'\nimport type { Payload } from './Payload.ts'\nimport type { Schema } from './Schema.ts'\n\nexport const ModuleErrorSchema = 'network.xyo.error.module' as const\nexport type ModuleErrorSchema = typeof ModuleErrorSchema\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash | Schema\n schema: ModuleErrorSchema\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","import { isDefined } from '@xylabs/typeof'\nimport type { ZodObject } from 'zod'\n\nimport { isAnyPayload } from './isPayload.ts'\nimport type { Payload } from './Payload.ts'\n\n/**\n * Checks if a value is a payload of a specific Zod type.\n * @param zodSchema The Zod schema to validate against\n * @param schema The schema string to match against the payload. Optional in\n * case you want to validate any payload matching the Zod schema or in case\n * schema is part of the Zod schema.\n * @returns A function that checks if a value is a payload of the specified Zod type\n */\nexport function isPayloadOfZodType<\n T extends Payload | never = never,\n S extends ZodObject = ZodObject,\n>(zodSchema: S, schema?: T['schema']) {\n return (x?: unknown | null): x is T => {\n if (!isAnyPayload(x)) return false\n if (isDefined(schema) && x.schema !== schema) return false\n const { schema: _, ...data } = x\n return zodSchema.safeParse(data).success\n }\n}\n","import type { Hash } from '@xylabs/hex'\nimport { AsObjectFactory } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.ts'\nimport type { Payload } from './Payload.ts'\n\n// payload that wraps a complete boundwitness with its payloads for use in systems such as submission queues\nexport const PayloadBundleSchema = 'network.xyo.payload.bundle' as const\nexport type PayloadBundleSchema = typeof PayloadBundleSchema\n\nexport interface PayloadBundleFields<T extends Payload = Payload> {\n payloads: T[]\n root: Hash\n}\n\nexport type PayloadBundle = Payload<PayloadBundleFields, PayloadBundleSchema>\n\nexport const isPayloadBundle = isPayloadOfSchemaType<PayloadBundle>(PayloadBundleSchema)\n\nexport const asPayloadBundle = AsObjectFactory.create(isPayloadBundle)\nexport const asOptionalPayloadBundle = AsObjectFactory.createOptional(isPayloadBundle)\n","export const PayloadSetSchema = 'network.xyo.payload.set' as const\nexport type PayloadSetSchema = typeof PayloadSetSchema\n","import { HashToJsonZod } from '@xylabs/hex'\nimport * as z from 'zod'\n\nimport { SchemaZod } from './Schema.ts'\nimport { SequenceToStringZod } from './StorageMeta/index.ts'\n\nexport const StorageMetaZod = z.object({\n _hash: HashToJsonZod,\n _dataHash: HashToJsonZod,\n _sequence: SequenceToStringZod,\n})\n\nexport const PayloadZod = z.object({ schema: SchemaZod })\nexport const PayloadWithStorageMetaZod = PayloadZod.extend(StorageMetaZod.shape)\n\nexport const AnyPayloadZod = PayloadZod.catchall(z.json())\nexport const AnyPayloadWithStorageMetaZod = AnyPayloadZod.extend(StorageMetaZod.shape)\n\nexport type PayloadWithStorageMeta = z.infer<typeof PayloadWithStorageMetaZod>\n\nexport type AnyPayload = z.infer<typeof AnyPayloadZod>\nexport type AnyPayloadWithStorageMeta = z.infer<typeof AnyPayloadWithStorageMetaZod>\n\nexport function WithStorageMetaZod<T extends typeof PayloadZod>(valueZod: T) {\n return StorageMetaZod.extend(valueZod.shape)\n}\n\nexport const PayloadZodStrict = z.strictObject({ schema: SchemaZod })\nexport type PayloadZodStrict = typeof PayloadZodStrict\nexport const PayloadZodLoose: PayloadZodStrict = z.looseObject({ schema: SchemaZod })\n\nexport const PayloadZodStrictOfSchema = <S extends string>(schema: S) => PayloadZodStrict.extend({ schema: z.literal(schema) })\nexport const PayloadZodLooseOfSchema = <S extends string>(schema: S) => PayloadZodLoose.extend({ schema: z.literal(schema) })\n","import type { EmptyObject } from '@xylabs/object'\nimport { AsTypeFactory } from '@xylabs/object'\nimport * as z from 'zod'\n\nexport const SchemaRegEx = /^(?:[a-z0-9]+\\.)*[a-z0-9]+$/\n\nexport const SchemaZodV1 = z.string().regex(SchemaRegEx)\nexport const SchemaZodV2 = z.string().regex(SchemaRegEx).transform(x => x as (typeof x & { __schema: true }))\nexport type SchemaV2 = z.output<typeof SchemaZodV2>\nexport type SchemaV1 = z.output<typeof SchemaZodV1>\nexport const SchemaZod = z.union([SchemaZodV1, SchemaZodV2])\nexport type Schema = z.infer<typeof SchemaZodV1>\n\nexport const makeSchema = <T extends string>(value: T) => {\n return (z.templateLiteral([z.literal(value)])).transform(x => x as (typeof x & { __schema: true }))\n}\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport const PayloadSchemaZod = z.literal(PayloadSchema)\nexport type PayloadSchema = z.infer<typeof PayloadSchemaZod>\n\nexport const isSchema = (value: unknown): value is Schema => {\n return SchemaZod.safeParse(value).error === undefined\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n","import type { Hash } from '@xylabs/hex'\nimport { isHash } from '@xylabs/hex'\nimport { AsObjectFactory } from '@xylabs/object'\n\nimport type { Payload } from '../Payload.ts'\n\nexport interface DataHashStorageMeta {\n _dataHash: Hash\n}\n\nexport type WithDataHashStorageMeta<T extends Payload = Payload> = T & DataHashStorageMeta\nexport type WithPartialDataHashStorageMeta<T extends Payload = Payload> = Partial<WithDataHashStorageMeta<T>>\n\nexport const isDataHashStorageMeta = (value: unknown): value is DataHashStorageMeta => {\n return isHash((value as WithDataHashStorageMeta)?._dataHash)\n}\n\nexport const asDataHashStorageMeta = AsObjectFactory.create<DataHashStorageMeta>(isDataHashStorageMeta)\nexport const asOptionalDataHashStorageMeta = AsObjectFactory.createOptional<DataHashStorageMeta>(isDataHashStorageMeta)\n","import type { Hash } from '@xylabs/hex'\nimport { isHash } from '@xylabs/hex'\nimport { AsObjectFactory } from '@xylabs/object'\n\nimport type { Payload } from '../Payload.ts'\nimport type { DataHashStorageMeta } from './DataHash.ts'\nimport { isDataHashStorageMeta } from './DataHash.ts'\n\nexport interface HashStorageMeta extends DataHashStorageMeta {\n _hash: Hash\n}\n\nexport type WithHashStorageMeta<T extends Payload = Payload> = T & HashStorageMeta\nexport type WithPartialHashStorageMeta<T extends Payload = Payload> = Partial<WithHashStorageMeta<T>>\n\nexport const isHashStorageMeta = (value: unknown): value is HashStorageMeta => {\n return isDataHashStorageMeta(value) && isHash((value as WithHashStorageMeta)?._hash)\n}\n\nexport const asHashStorageMeta = AsObjectFactory.create<HashStorageMeta>(isHashStorageMeta)\nexport const asOptionalHashStorageMeta = AsObjectFactory.createOptional<HashStorageMeta>(isHashStorageMeta)\n","import { AsObjectFactory } from '@xylabs/object'\n\nimport type { Payload } from '../Payload.ts'\nimport type { Sequence } from './sequence/index.ts'\n\nexport interface SequenceStorageMeta {\n _sequence: Sequence\n}\n\nexport type WithSequenceStorageMeta<T extends Payload = Payload> = T & SequenceStorageMeta\nexport type WithPartialSequenceStorageMeta<T extends Payload = Payload> = Partial<WithSequenceStorageMeta<T>>\n\nexport const isSequenceStorageMeta = (value: unknown): value is SequenceStorageMeta => {\n return (value as WithSequenceStorageMeta)?._sequence != undefined\n}\n\nexport const asSequenceStorageMeta = AsObjectFactory.create(isSequenceStorageMeta)\nexport const asOptionalSequenceStorageMeta = AsObjectFactory.createOptional(isSequenceStorageMeta)\n","import { toUint8Array } from '@xylabs/arraybuffer'\nimport { assertEx } from '@xylabs/assert'\nimport type {\n Address,\n Hash, Hex,\n} from '@xylabs/hex'\nimport {\n isAddress,\n toAddress,\n toHex,\n} from '@xylabs/hex'\n\nimport type {\n Epoch, LocalSequence, Nonce, QualifiedSequence,\n Sequence,\n} from './Sequence.ts'\nimport {\n isQualifiedSequence, isSequence,\n SequenceConstants,\n} from './Sequence.ts'\n\nexport class SequenceParser {\n protected static privateConstructorKey = Date.now().toString()\n\n private readonly data: Readonly<Uint8Array>\n\n protected constructor(privateConstructorKey: string, hex: Hex) {\n assertEx(SequenceParser.privateConstructorKey === privateConstructorKey, () => 'Use create function instead of constructor')\n const paddedHex = toHex(hex, {\n prefix: false,\n bitLength: (hex.length <= SequenceConstants.localSequenceBytes * 2)\n ? SequenceConstants.localSequenceBytes * 8\n : SequenceConstants.qualifiedSequenceBytes * 8,\n })\n this.data = toUint8Array(paddedHex)\n }\n\n get address(): Address {\n const start = SequenceConstants.localSequenceBytes\n const end = SequenceConstants.qualifiedSequenceBytes\n return toAddress(this.data.slice(start, end).buffer, { prefix: false })\n }\n\n get epoch(): Epoch {\n const start = 0\n const end = SequenceConstants.epochBytes\n return toHex(this.data.slice(start, end).buffer, { prefix: false }) as Epoch\n }\n\n get localSequence(): LocalSequence {\n const start = 0\n const end = SequenceConstants.localSequenceBytes\n return toHex(this.data.slice(start, end).buffer, { prefix: false }) as LocalSequence\n }\n\n get nonce(): Nonce {\n const start = SequenceConstants.epochBytes\n const end = SequenceConstants.localSequenceBytes\n return toHex(this.data.slice(start, end).buffer, { prefix: false }) as Nonce\n }\n\n get qualifiedSequence(): QualifiedSequence {\n const start = 0\n const end = SequenceConstants.qualifiedSequenceBytes\n return toHex(this.data.slice(start, end).buffer, { prefix: false }) as QualifiedSequence\n }\n\n static from(sequence: Sequence, address?: Address): SequenceParser\n static from(timestamp: Hex, hash: Hash, address?: Address): SequenceParser\n static from(timestamp: Hex, hash: Hex, address?: Address): SequenceParser\n static from(timestamp: Hex, nonce: Nonce, address?: Address): SequenceParser\n static from(timestamp: Hex, hash: Hash, index?: number, address?: Address): SequenceParser\n static from(timestamp: Hex, hash: Hex, index?: number, address?: Address): SequenceParser\n static from(timestamp: Hex, nonce: Nonce, index?: number, address?: Address): SequenceParser\n static from(timestamp: number, hash: Hash, address?: Address): SequenceParser\n static from(timestamp: number, hash: Hex, address?: Address): SequenceParser\n static from(timestamp: number, nonce: Nonce, address?: Address): SequenceParser\n static from(timestamp: number, hash: Hash, index?: number, address?: Address): SequenceParser\n static from(timestamp: number, hash: Hex, index?: number, address?: Address): SequenceParser\n static from(timestamp: number, nonce: Nonce, index?: number, address?: Address): SequenceParser\n static from(\n timestampOrSequence: Hex | number,\n nonceOrAddress?: Hex,\n addressOrIndex?: Address | number,\n addressOnly?: Address,\n ): SequenceParser {\n const address = typeof addressOrIndex === 'number' ? addressOnly : addressOrIndex\n const index = typeof addressOrIndex === 'number' ? addressOrIndex : undefined\n if (isSequence(timestampOrSequence)) {\n if (nonceOrAddress) {\n assertEx(!isQualifiedSequence(timestampOrSequence), () => 'Providing both a qualified sequence and a address is not allowed')\n assertEx(isAddress(nonceOrAddress), () => 'Invalid address provided')\n return new this(SequenceParser.privateConstructorKey, (timestampOrSequence + address) as Hex)\n }\n return new this(SequenceParser.privateConstructorKey, timestampOrSequence)\n }\n const epoch = SequenceParser.toEpoch(timestampOrSequence)\n const nonce = nonceOrAddress === undefined ? undefined : SequenceParser.toNonce(nonceOrAddress, index)\n const addressHex: Hex = address ? toHex(address, { bitLength: SequenceConstants.addressBytes * 8 }) : SequenceConstants.minAddress\n const hexString = (epoch + nonce + addressHex) as Hex\n assertEx(isSequence(hexString), () => `Invalid sequence [${hexString}] [${epoch}, ${nonce}, ${addressHex}]`)\n return new this(SequenceParser.privateConstructorKey, hexString)\n }\n\n static parse(value: Hex | string | ArrayBufferLike): SequenceParser {\n const hex = toHex(value)\n if (isSequence(hex)) {\n return new this(SequenceParser.privateConstructorKey, hex)\n }\n throw new Error(`Invalid sequence [${value}]`)\n }\n\n // can convert a short number/hex to an epoch (treats it as the whole value) or extract an epoch from a sequence\n static toEpoch(value: number | Hex | Epoch): Epoch {\n assertEx(\n typeof value !== 'number' || Number.isInteger(value),\n () => 'Value must be in integer',\n )\n const hex = toHex(value, { prefix: false })\n if (hex.length <= SequenceConstants.epochBytes * 2) {\n return toHex(value, { prefix: false, bitLength: SequenceConstants.epochBytes * 8 }) as Epoch\n }\n if (isSequence(hex)) {\n return hex.slice(0, SequenceConstants.epochBytes * 2) as Epoch\n }\n throw new Error(`Value could not be converted to epoch [${hex}]`)\n }\n\n // can convert a short number/hex to a nonce (treats it as the whole value) or extract an nonce from a sequence\n static toNonce(value: Hash | Hex, index = 0): Nonce {\n assertEx(\n typeof value !== 'number' || Number.isInteger(value),\n () => 'Value must be in integer',\n )\n const hex = toHex(value, { prefix: false })\n if (isSequence(hex)) {\n return hex.slice(SequenceConstants.epochBytes * 2, SequenceConstants.localSequenceBytes * 2) as Nonce\n }\n const hashHex = toHex((hex as string), { prefix: false, bitLength: SequenceConstants.nonceHashBytes * 8 }).slice(-SequenceConstants.nonceHashBytes * 2)\n const indexHex = toHex(index, { prefix: false, bitLength: SequenceConstants.nonceIndexBytes * 8 }).slice(-SequenceConstants.nonceIndexBytes * 2)\n return (indexHex + hashHex).slice(-SequenceConstants.nonceBytes * 2) as Nonce\n }\n}\n","import type { Address, Hex } from '@xylabs/hex'\nimport { isHex } from '@xylabs/hex'\nimport type { Brand } from '@xylabs/typeof'\n\n// we use Exclude to intentionally make the type not equal to string\nexport type LocalSequence = Brand<Hex, { __localSequence: true }>\nexport type QualifiedSequence = Brand<Hex, { __qualifiedSequence: true }>\nexport type Sequence = LocalSequence | QualifiedSequence\n\nexport type Epoch = Brand<Hex, { __epoch: true }>\n\nexport const isEpoch = (value: unknown): value is Epoch => {\n return isHex(value) && (value as string).length === SequenceConstants.epochBytes * 2\n}\n\nexport type Nonce = Brand<Hex, { __nonce: true }>\n\nexport const isNonce = (value: unknown): value is Nonce => {\n return isHex(value) && (value as string).length === SequenceConstants.nonceBytes * 2\n}\n\nexport const isLocalSequence = (value: unknown): value is LocalSequence => {\n return isHex(value) && (value as string).length === SequenceConstants.localSequenceBytes * 2\n}\n\nexport const isQualifiedSequence = (value: unknown): value is QualifiedSequence => {\n return isHex(value) && (value as string).length === SequenceConstants.qualifiedSequenceBytes * 2\n}\n\nexport const isSequence = (value: unknown): value is Sequence => {\n return isLocalSequence(value) || isQualifiedSequence(value)\n}\n\nexport const SequenceNonceComponentLengths = {\n nonceIndexBytes: 4,\n nonceHashBytes: 4,\n}\n\nexport const SequenceComponentLengths = {\n ...SequenceNonceComponentLengths,\n epochBytes: 8,\n nonceBytes: SequenceNonceComponentLengths.nonceIndexBytes + SequenceNonceComponentLengths.nonceHashBytes,\n addressBytes: 20,\n}\n\nexport const SequenceComponentMinMax = {\n minEpoch: '0'.repeat(SequenceComponentLengths.epochBytes * 2) as Epoch,\n maxEpoch: 'f'.repeat(SequenceComponentLengths.epochBytes * 2) as Epoch,\n minNonce: '0'.repeat(SequenceComponentLengths.nonceBytes * 2) as Nonce,\n maxNonce: 'f'.repeat(SequenceComponentLengths.nonceBytes * 2) as Nonce,\n minAddress: '0'.repeat(SequenceComponentLengths.addressBytes * 2) as Address,\n maxAddress: 'f'.repeat(SequenceComponentLengths.addressBytes * 2) as Address,\n}\n\nexport const LocalSequenceConstants = {\n ...SequenceComponentLengths,\n ...SequenceComponentMinMax,\n localSequenceBytes: SequenceComponentLengths.epochBytes + SequenceComponentLengths.nonceBytes,\n minLocalSequence: SequenceComponentMinMax.minEpoch + SequenceComponentMinMax.minNonce as LocalSequence,\n maxLocalSequence: SequenceComponentMinMax.maxEpoch + SequenceComponentMinMax.maxNonce as LocalSequence,\n}\n\nexport const QualifiedSequenceConstants = {\n qualifiedSequenceBytes: LocalSequenceConstants.localSequenceBytes + SequenceComponentLengths.addressBytes,\n minQualifiedSequence: LocalSequenceConstants.minLocalSequence + SequenceComponentMinMax.minAddress as QualifiedSequence,\n maxQualifiedSequence: LocalSequenceConstants.maxLocalSequence + SequenceComponentMinMax.maxAddress as QualifiedSequence,\n}\n\nexport const SequenceConstants = {\n ...LocalSequenceConstants,\n ...QualifiedSequenceConstants,\n}\n\n// \"11111111111111112222222222222222\" is and example of a local sequence string\n\n// \"111111111111111122222222222222223333333333333333333333333333333333333333\" is and example of a local sequence string\n// epoch = \"1111111111111111\"\n// nonce = \"2222222222222222\"\n// address = \"3333333333333333333333333333333333333333\"\n","import type { Compare } from '@xylabs/object'\n\nimport { SequenceParser } from './Parser.ts'\nimport type { Sequence } from './Sequence.ts'\n\nconst local: Compare<Sequence> = (a, b) => {\n const aa = SequenceParser.from(a)\n const bb = SequenceParser.from(b)\n return aa.localSequence > bb.localSequence ? 1 : aa.localSequence < bb.localSequence ? -1 : 0\n}\n\nconst qualified: Compare<Sequence> = (a, b) => {\n const aa = SequenceParser.from(a)\n const bb = SequenceParser.from(b)\n return aa.qualifiedSequence > bb.qualifiedSequence ? 1 : aa.qualifiedSequence < bb.qualifiedSequence ? -1 : 0\n}\n\nexport const SequenceComparer = { local, qualified }\n","import { HexRegExMinMax, toHex } from '@xylabs/hex'\nimport * as z from 'zod'\n\nimport type { LocalSequence, QualifiedSequence } from './Sequence.ts'\nimport { SequenceConstants } from './Sequence.ts'\n\nconst LocalSequenceRegex = new RegExp(HexRegExMinMax(SequenceConstants.localSequenceBytes, SequenceConstants.localSequenceBytes))\nexport const LocalSequenceToStringZod = z.string().regex(LocalSequenceRegex)\nexport const LocalSequenceFromStringZod = z.string().regex(LocalSequenceRegex).transform<LocalSequence>(v => toHex(v) as LocalSequence)\n\nconst QualifiedSequenceRegex = new RegExp(HexRegExMinMax(SequenceConstants.qualifiedSequenceBytes, SequenceConstants.qualifiedSequenceBytes))\nexport const QualifiedSequenceToStringZod = z.string().regex(QualifiedSequenceRegex)\nexport const QualifiedSequenceFromStringZod = z.string().regex(QualifiedSequenceRegex).transform<QualifiedSequence>(v => toHex(v) as QualifiedSequence)\n\nexport const SequenceToStringZod = z.union([LocalSequenceToStringZod, QualifiedSequenceToStringZod])\nexport const SequenceFromStringZod = z.union([LocalSequenceFromStringZod, QualifiedSequenceFromStringZod])\n","import { AsObjectFactory } from '@xylabs/object'\n\nimport type { Payload } from '../Payload.ts'\nimport type { HashStorageMeta } from './Hash.ts'\nimport { isHashStorageMeta } from './Hash.ts'\nimport type { SequenceStorageMeta } from './Sequence.ts'\nimport { isSequenceStorageMeta } from './Sequence.ts'\n\nexport interface StorageMeta extends SequenceStorageMeta, HashStorageMeta {}\n\nexport type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta\nexport type WithPartialStorageMeta<T extends Payload = Payload> = T & Partial<StorageMeta>\n\nexport const isStorageMeta = (value: unknown): value is StorageMeta => {\n return isSequenceStorageMeta(value) && isHashStorageMeta(value)\n}\n\nexport const asStorageMeta = AsObjectFactory.create(isStorageMeta)\nexport const asOptionalStorageMeta = AsObjectFactory.createOptional(isStorageMeta)\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAgB;AAInC,IAAM,eAAe,CAAC,UAAqC;AA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AAmB,UAAO;AAAA,EACrC,OAAO;AAAA,EACP,WAAW;AAAA,EACX,WAAW;AACb,CAAC;AAEM,IAAM,aAAe,UAAO,EAAE,QAAQ,UAAU,CAAC;AACjD,IAAM,4BAA4B,WAAW,OAAO,eAAe,KAAK;AAExE,IAAM,gBAAgB,WAAW,SAAW,QAAK,CAAC;AAClD,IAAM,+BAA+B,cAAc,OAAO,eAAe,KAAK;AAO9E,SAAS,mBAAgD,UAAa;AAC3E,SAAO,eAAe,OAAO,SAAS,KAAK;AAC7C;AAEO,IAAM,mBAAqB,gBAAa,EAAE,QAAQ,UAAU,CAAC;AAE7D,IAAM,kBAAsC,eAAY,EAAE,QAAQ,UAAU,CAAC;AAE7E,IAAM,2BAA2B,CAAmB,WAAc,iBAAiB,OAAO,EAAE,QAAU,WAAQ,MAAM,EAAE,CAAC;AACvH,IAAM,0BAA0B,CAAmB,WAAc,gBAAgB,OAAO,EAAE,QAAU,WAAQ,MAAM,EAAE,CAAC;","names":["AsObjectFactory","AsObjectFactory","z","AsObjectFactory","isHash","AsObjectFactory","isHash","AsObjectFactory","AsObjectFactory","toHex","z","toHex","AsObjectFactory","AsObjectFactory"]}
|
package/package.json
CHANGED
package/src/PayloadZod.ts
CHANGED
|
@@ -24,3 +24,10 @@ export type AnyPayloadWithStorageMeta = z.infer<typeof AnyPayloadWithStorageMeta
|
|
|
24
24
|
export function WithStorageMetaZod<T extends typeof PayloadZod>(valueZod: T) {
|
|
25
25
|
return StorageMetaZod.extend(valueZod.shape)
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
export const PayloadZodStrict = z.strictObject({ schema: SchemaZod })
|
|
29
|
+
export type PayloadZodStrict = typeof PayloadZodStrict
|
|
30
|
+
export const PayloadZodLoose: PayloadZodStrict = z.looseObject({ schema: SchemaZod })
|
|
31
|
+
|
|
32
|
+
export const PayloadZodStrictOfSchema = <S extends string>(schema: S) => PayloadZodStrict.extend({ schema: z.literal(schema) })
|
|
33
|
+
export const PayloadZodLooseOfSchema = <S extends string>(schema: S) => PayloadZodLoose.extend({ schema: z.literal(schema) })
|