@xyo-network/payload-model 3.6.0-rc.6 → 3.6.0-rc.8

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.
@@ -11,7 +11,7 @@ export type ModuleError = Payload<{
11
11
  schema: ModuleErrorSchema;
12
12
  sources?: Hash[];
13
13
  }>;
14
- export declare const isModuleError: (x?: unknown | null) => x is import("./Payload.ts").DeepRestrictToStringKeys<{
14
+ export declare const isModuleError: (x?: unknown | null) => x is import("@xylabs/object").DeepRestrictToStringKeys<{
15
15
  schema: "network.xyo.error.module";
16
16
  details?: string | number | boolean | {
17
17
  [x: string]: string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
@@ -1,5 +1,5 @@
1
1
  import type { Hash } from '@xylabs/hex';
2
- import type { EmptyObject } from '@xylabs/object';
2
+ import type { DeepOmitStartsWith, DeepRestrictToStringKeys, EmptyObject } from '@xylabs/object';
3
3
  import type { Schema, WithSchema } from './Schema.ts';
4
4
  export interface SchemaField<T extends Schema = Schema> {
5
5
  schema: T;
@@ -17,17 +17,14 @@ export type Payload<T extends void | EmptyObject | WithSchema = void, S extends
17
17
  schema: S extends Schema ? S : Schema;
18
18
  }>;
19
19
  export type OverridablePayload<T extends Payload> = WithoutMeta<Omit<T, 'schema'> & PayloadFields>;
20
- export type WithSources<T extends EmptyObject> = T & {
21
- sources?: Hash[];
20
+ export type SourcesMetaField = {
21
+ $sources: Hash[];
22
22
  };
23
+ export type WithSources<T extends EmptyObject> = T & SourcesMetaField;
24
+ export type WithOptionalSources<T extends EmptyObject> = (T & SourcesMetaField) | T;
23
25
  export type PayloadWithSources<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithSources<Payload<T, S>>;
26
+ export type PayloadWithOptionalSources<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithOptionalSources<Payload<T, S>>;
24
27
  export type WithAnySchema<T extends Payload> = OverridablePayload<T>;
25
- export type DeepOmitStartsWith<T, Prefix extends string> = T extends (infer U)[] ? DeepOmitStartsWith<U, Prefix>[] : T extends object ? {
26
- [K in keyof T as K extends string ? K extends `${Prefix}${string}` ? never : K : K]: DeepOmitStartsWith<T[K], Prefix>;
27
- } : T;
28
- export type DeepRestrictToStringKeys<T> = {
29
- [K in keyof T as K extends string ? K : never]: T[K] extends (infer U)[] ? DeepRestrictToStringKeys<U>[] : T[K] extends object ? DeepRestrictToStringKeys<T[K]> : T[K];
30
- };
31
28
  export type WithoutClientMeta<T extends EmptyObject> = DeepOmitStartsWith<T, '$'>;
32
29
  export type WithoutStorageMeta<T extends EmptyObject> = DeepOmitStartsWith<T, '_'>;
33
30
  export type WithoutPrivateStorageMeta<T extends EmptyObject> = DeepOmitStartsWith<T, '__'>;
@@ -1 +1 @@
1
- {"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAEjD,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACpD,MAAM,EAAE,CAAC,CAAA;CACV;AAED,sCAAsC;AACtC,MAAM,WAAW,aAAc,SAAQ,WAAW;CAAG;AAErD,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,WAAW,GAAG,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C,CAAA;AACjF,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,WAAW,IAAI,kBAAkB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AAClF,MAAM,MAAM,yBAAyB,CAAC,CAAC,SAAS,WAAW,IAAI,kBAAkB,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;AAC1F,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,WAAW,IAAI,iBAAiB,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAA;AAEzF,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,kBAAkB,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA;AACpF,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,IAAI,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,WAAW,CAAC,CAAA"}
@@ -5,8 +5,8 @@ export declare const PayloadSchema: "network.xyo.payload";
5
5
  export type PayloadSchema = typeof PayloadSchema;
6
6
  export declare const isSchema: (value: unknown) => value is Schema;
7
7
  export declare const asSchema: {
8
- <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
9
- <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<string>, config?: import("@xylabs/object").TypeCheckConfig): TType;
8
+ <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
9
+ <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<string>, config?: import("@xylabs/object").TypeCheckConfig): TType;
10
10
  };
11
11
  /** Schema fields for a Payload */
12
12
  export interface SchemaFields extends EmptyObject {
@@ -20,7 +20,7 @@ var isPayloadOfSchemaType = (schema) => {
20
20
  return (x) => isAnyPayload(x) && x?.schema === schema;
21
21
  };
22
22
  var isPayloadOfSchemaTypeWithSources = (schema) => {
23
- return (x) => isPayloadOfSchemaType(schema)(x) && x.sources !== void 0 && Array.isArray(x.sources);
23
+ return (x) => isPayloadOfSchemaType(schema)(x) && x.$sources !== void 0 && Array.isArray(x.$sources);
24
24
  };
25
25
  var notPayloadOfSchemaType = (schema) => {
26
26
  return (x) => !isAnyPayload(x) || x?.schema !== schema;
@@ -142,7 +142,7 @@ var SequenceParser = class _SequenceParser {
142
142
  }
143
143
  const epoch = _SequenceParser.toEpoch(timestampOrSequence);
144
144
  const nonce = _SequenceParser.toNonce(nonceOrAddress);
145
- const addressHex = address ? toHex(address, { bitLength: SequenceConstants.addressBytes * 8 }) : "";
145
+ const addressHex = address ? toHex(address, { bitLength: SequenceConstants.addressBytes * 8 }) : SequenceConstants.minAddress;
146
146
  const hexString = epoch + nonce + addressHex;
147
147
  assertEx(isSequence(hexString), () => `Invalid sequence [${hexString}] [${epoch}, ${nonce}, ${addressHex}]`);
148
148
  return new this(_SequenceParser.privateConstructorKey, hexString);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts","../../src/StorageMeta/Sequence.ts","../../src/StorageMeta/SequenceParser.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.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 const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\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>(schema: string) => {\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(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'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import type { EmptyObject } from '@xylabs/object'\nimport { AsTypeFactory } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n return typeof value === 'string'\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n","import type { Address, Hex } from '@xylabs/hex'\nimport { isHex } from '@xylabs/hex'\n\n// we use Exclude to intentionally make the type not equal to string\nexport type LocalSequence = Hex & Exclude<string, 'reserved-local-sequence-value'>\nexport type QualifiedSequence = Hex & Exclude<string, 'reserved-qualified-sequence-value'>\nexport type Sequence = LocalSequence | QualifiedSequence\n\nexport type Epoch = Hex & Exclude<string, 'reserved-epoch-sequence-value'>\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 = Hex & Exclude<string, 'reserved-nonce-sequence-value'>\n\nexport const isNonce = (value: unknown): value is Epoch => {\n return isHex(value) && (value as string).length === SequenceConstants.nonceBytes * 2\n}\n\nexport const isLocalSequence = (value: unknown): value is Sequence => {\n return isHex(value) && (value as string).length === SequenceConstants.localSequenceBytes * 2\n}\n\nexport const isQualifiedSequence = (value: unknown): value is Sequence => {\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 SequenceComponentLengths = {\n epochBytes: 8,\n nonceBytes: 8,\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 minLocalSequence: LocalSequenceConstants.minLocalSequence + SequenceComponentMinMax.minAddress as QualifiedSequence,\n maxLocalSequence: 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 { toUint8Array } from '@xylabs/arraybuffer'\nimport { assertEx } from '@xylabs/assert'\nimport {\n type Address,\n type Hash, type Hex,\n isAddress,\n toHex,\n} from '@xylabs/hex'\n\nimport type {\n Epoch, LocalSequence, Nonce, QualifiedSequence,\n Sequence,\n} from './Sequence.ts'\nimport {\n isQualifiedSequence, isSequence, 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 toHex(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 })\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 })\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 })\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 })\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: 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(timestampOrSequence: Sequence | Hex | number, nonceOrAddress: Hash | Nonce, address?: Address): SequenceParser {\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 = SequenceParser.toNonce(nonceOrAddress)\n const addressHex: Hex = address ? toHex(address, { bitLength: SequenceConstants.addressBytes * 8 }) : '' as Hex\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): 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 hash = toHex((hex as string), { prefix: false, bitLength: SequenceConstants.nonceBytes * 8 })\n return hash.slice(-SequenceConstants.nonceBytes * 2) as Nonce\n }\n}\n","import { type Hash, isHash } from '@xylabs/hex'\n\nimport type { Payload } from '../Payload.ts'\nimport type { Sequence } from './Sequence.ts'\n\nexport interface SequenceMeta {\n _sequence: Sequence\n}\n\nexport type WithPartialSequenceMeta<T extends Payload = Payload> = Partial<WithSequenceMeta<T>>\n\nexport type WithSequenceMeta<T extends Payload = Payload> = T & SequenceMeta\n\nexport interface HashMeta {\n _dataHash: Hash\n _hash: Hash\n}\n\nexport type WithPartialHashMeta<T extends Payload = Payload> = Partial<WithHashMeta<T>>\n\nexport type WithHashMeta<T extends Payload = Payload> = T & HashMeta\n\nexport interface StorageMeta extends SequenceMeta, HashMeta {}\n\nexport type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>\n\nexport type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta\n\nexport const isSequenceMeta = (value: unknown): value is SequenceMeta => {\n return (value as WithSequenceMeta)?._sequence !== undefined\n}\n\nexport const isHashMeta = (value: unknown): value is HashMeta => {\n return isHash((value as WithHashMeta)?._hash) && isHash((value as WithHashMeta)?._dataHash)\n}\n\nexport const isStorageMeta = (value: unknown): value is StorageMeta => {\n return isSequenceMeta(value) && isHashMeta(value)\n}\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14\" is and example of a local sequence string\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14a123456789abcdef0123\" is and example of a local sequence string\n// epoch = \"00005a7f354762f3ac\"\n// nonce = \"1bc5ddc6cfd08d14\"\n// address = \"a123456789abcdef0123\"\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAgB;AAInC,IAAM,eAAe,CAAC,UAAqC;AAChE,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,OAAO,MAAM,WAAW;AAAA,EACjC;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,CAAo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CAAC;AAAA,IAC7F;AACA,UAAM,OAAO,MAAO,KAAgB,EAAE,QAAQ,OAAO,WAAW,kBAAkB,aAAa,EAAE,CAAC;AAClG,WAAO,KAAK,MAAM,CAAC,kBAAkB,aAAa,CAAC;AAAA,EACrD;AACF;;;AC5HA,SAAoB,cAAc;AA4B3B,IAAM,iBAAiB,CAAC,UAA0C;AACvE,SAAQ,OAA4B,cAAc;AACpD;AAEO,IAAM,aAAa,CAAC,UAAsC;AAC/D,SAAO,OAAQ,OAAwB,KAAK,KAAK,OAAQ,OAAwB,SAAS;AAC5F;AAEO,IAAM,gBAAgB,CAAC,UAAyC;AACrE,SAAO,eAAe,KAAK,KAAK,WAAW,KAAK;AAClD;","names":[]}
1
+ {"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts","../../src/StorageMeta/Sequence.ts","../../src/StorageMeta/SequenceParser.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.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 const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\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>(schema: string) => {\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(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'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import type { EmptyObject } from '@xylabs/object'\nimport { AsTypeFactory } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n return typeof value === 'string'\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n","import type { Address, Hex } from '@xylabs/hex'\nimport { isHex } from '@xylabs/hex'\n\n// we use Exclude to intentionally make the type not equal to string\nexport type LocalSequence = Hex & Exclude<string, 'reserved-local-sequence-value'>\nexport type QualifiedSequence = Hex & Exclude<string, 'reserved-qualified-sequence-value'>\nexport type Sequence = LocalSequence | QualifiedSequence\n\nexport type Epoch = Hex & Exclude<string, 'reserved-epoch-sequence-value'>\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 = Hex & Exclude<string, 'reserved-nonce-sequence-value'>\n\nexport const isNonce = (value: unknown): value is Epoch => {\n return isHex(value) && (value as string).length === SequenceConstants.nonceBytes * 2\n}\n\nexport const isLocalSequence = (value: unknown): value is Sequence => {\n return isHex(value) && (value as string).length === SequenceConstants.localSequenceBytes * 2\n}\n\nexport const isQualifiedSequence = (value: unknown): value is Sequence => {\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 SequenceComponentLengths = {\n epochBytes: 8,\n nonceBytes: 8,\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 minLocalSequence: LocalSequenceConstants.minLocalSequence + SequenceComponentMinMax.minAddress as QualifiedSequence,\n maxLocalSequence: 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 { toUint8Array } from '@xylabs/arraybuffer'\nimport { assertEx } from '@xylabs/assert'\nimport {\n type Address,\n type Hash, type Hex,\n isAddress,\n toHex,\n} from '@xylabs/hex'\n\nimport type {\n Epoch, LocalSequence, Nonce, QualifiedSequence,\n Sequence,\n} from './Sequence.ts'\nimport {\n isQualifiedSequence, isSequence, 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 toHex(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 })\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 })\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 })\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 })\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: 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(timestampOrSequence: Sequence | Hex | number, nonceOrAddress: Hash | Nonce, address?: Address): SequenceParser {\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 = SequenceParser.toNonce(nonceOrAddress)\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): 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 hash = toHex((hex as string), { prefix: false, bitLength: SequenceConstants.nonceBytes * 8 })\n return hash.slice(-SequenceConstants.nonceBytes * 2) as Nonce\n }\n}\n","import { type Hash, isHash } from '@xylabs/hex'\n\nimport type { Payload } from '../Payload.ts'\nimport type { Sequence } from './Sequence.ts'\n\nexport interface SequenceMeta {\n _sequence: Sequence\n}\n\nexport type WithPartialSequenceMeta<T extends Payload = Payload> = Partial<WithSequenceMeta<T>>\n\nexport type WithSequenceMeta<T extends Payload = Payload> = T & SequenceMeta\n\nexport interface HashMeta {\n _dataHash: Hash\n _hash: Hash\n}\n\nexport type WithPartialHashMeta<T extends Payload = Payload> = Partial<WithHashMeta<T>>\n\nexport type WithHashMeta<T extends Payload = Payload> = T & HashMeta\n\nexport interface StorageMeta extends SequenceMeta, HashMeta {}\n\nexport type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>\n\nexport type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta\n\nexport const isSequenceMeta = (value: unknown): value is SequenceMeta => {\n return (value as WithSequenceMeta)?._sequence !== undefined\n}\n\nexport const isHashMeta = (value: unknown): value is HashMeta => {\n return isHash((value as WithHashMeta)?._hash) && isHash((value as WithHashMeta)?._dataHash)\n}\n\nexport const isStorageMeta = (value: unknown): value is StorageMeta => {\n return isSequenceMeta(value) && isHashMeta(value)\n}\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14\" is and example of a local sequence string\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14a123456789abcdef0123\" is and example of a local sequence string\n// epoch = \"00005a7f354762f3ac\"\n// nonce = \"1bc5ddc6cfd08d14\"\n// address = \"a123456789abcdef0123\"\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAgB;AAInC,IAAM,eAAe,CAAC,UAAqC;AAChE,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,OAAO,MAAM,WAAW;AAAA,EACjC;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,IAAM,wBAAwB,CAAoB,WAAmB;AAC1E,SAAO,CAAC,MAA+B,aAAa,CAAC,KAAK,GAAG,WAAW;AAC1E;AAEO,IAAM,mCAAmC,CAAoB,WAAmB;AACrF,SAAO,CAAC,MACN,sBAAsC,MAAM,EAAE,CAAC,KAAK,EAAE,aAAa,UAAa,MAAM,QAAQ,E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UAAsC;AAC/D,SAAO,OAAQ,OAAwB,KAAK,KAAK,OAAQ,OAAwB,SAAS;AAC5F;AAEO,IAAM,gBAAgB,CAAC,UAAyC;AACrE,SAAO,eAAe,KAAK,KAAK,WAAW,KAAK;AAClD;","names":[]}
@@ -1,18 +1,18 @@
1
1
  import type { Payload } from './Payload.ts';
2
2
  export declare const isAnyPayload: (value: unknown) => value is Payload;
3
3
  export declare const asAnyPayload: {
4
- <TType extends import("./Payload.ts").DeepRestrictToStringKeys<{
4
+ <TType extends import("@xylabs/object").DeepRestrictToStringKeys<{
5
5
  schema: import("./Schema.ts").Schema;
6
- }>>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
7
- <TType extends import("./Payload.ts").DeepRestrictToStringKeys<{
6
+ }>>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
7
+ <TType extends import("@xylabs/object").DeepRestrictToStringKeys<{
8
8
  schema: import("./Schema.ts").Schema;
9
- }>>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<import("./Payload.ts").DeepRestrictToStringKeys<{
9
+ }>>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<import("@xylabs/object").DeepRestrictToStringKeys<{
10
10
  schema: import("./Schema.ts").Schema;
11
11
  }>>, config?: import("@xylabs/object").TypeCheckConfig): TType;
12
12
  };
13
13
  export declare const isPayload: <T extends Payload>(schema: string[]) => (value: unknown) => value is T;
14
14
  export declare const asPayload: <T extends Payload>(schema: string[]) => {
15
- <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
16
- <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
15
+ <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
16
+ <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
17
17
  };
18
18
  //# sourceMappingURL=isPayload.d.ts.map
@@ -11,7 +11,7 @@ export type ModuleError = Payload<{
11
11
  schema: ModuleErrorSchema;
12
12
  sources?: Hash[];
13
13
  }>;
14
- export declare const isModuleError: (x?: unknown | null) => x is import("./Payload.ts").DeepRestrictToStringKeys<{
14
+ export declare const isModuleError: (x?: unknown | null) => x is import("@xylabs/object").DeepRestrictToStringKeys<{
15
15
  schema: "network.xyo.error.module";
16
16
  details?: string | number | boolean | {
17
17
  [x: string]: string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
@@ -1,5 +1,5 @@
1
1
  import type { Hash } from '@xylabs/hex';
2
- import type { EmptyObject } from '@xylabs/object';
2
+ import type { DeepOmitStartsWith, DeepRestrictToStringKeys, EmptyObject } from '@xylabs/object';
3
3
  import type { Schema, WithSchema } from './Schema.ts';
4
4
  export interface SchemaField<T extends Schema = Schema> {
5
5
  schema: T;
@@ -17,17 +17,14 @@ export type Payload<T extends void | EmptyObject | WithSchema = void, S extends
17
17
  schema: S extends Schema ? S : Schema;
18
18
  }>;
19
19
  export type OverridablePayload<T extends Payload> = WithoutMeta<Omit<T, 'schema'> & PayloadFields>;
20
- export type WithSources<T extends EmptyObject> = T & {
21
- sources?: Hash[];
20
+ export type SourcesMetaField = {
21
+ $sources: Hash[];
22
22
  };
23
+ export type WithSources<T extends EmptyObject> = T & SourcesMetaField;
24
+ export type WithOptionalSources<T extends EmptyObject> = (T & SourcesMetaField) | T;
23
25
  export type PayloadWithSources<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithSources<Payload<T, S>>;
26
+ export type PayloadWithOptionalSources<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithOptionalSources<Payload<T, S>>;
24
27
  export type WithAnySchema<T extends Payload> = OverridablePayload<T>;
25
- export type DeepOmitStartsWith<T, Prefix extends string> = T extends (infer U)[] ? DeepOmitStartsWith<U, Prefix>[] : T extends object ? {
26
- [K in keyof T as K extends string ? K extends `${Prefix}${string}` ? never : K : K]: DeepOmitStartsWith<T[K], Prefix>;
27
- } : T;
28
- export type DeepRestrictToStringKeys<T> = {
29
- [K in keyof T as K extends string ? K : never]: T[K] extends (infer U)[] ? DeepRestrictToStringKeys<U>[] : T[K] extends object ? DeepRestrictToStringKeys<T[K]> : T[K];
30
- };
31
28
  export type WithoutClientMeta<T extends EmptyObject> = DeepOmitStartsWith<T, '$'>;
32
29
  export type WithoutStorageMeta<T extends EmptyObject> = DeepOmitStartsWith<T, '_'>;
33
30
  export type WithoutPrivateStorageMeta<T extends EmptyObject> = DeepOmitStartsWith<T, '__'>;
@@ -1 +1 @@
1
- {"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAEjD,OAAO,KAAK,EAAE,MAA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mBAAmB,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAE7J,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,OAAO,IAAI,kBAAkB,CAAC,CAAC,CAAC,CAAA;AAEpE,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,WAAW,IAAI,kBAAkB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AACjF,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,WAAW,IAAI,kBAAkB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AAClF,MAAM,MAAM,yBAAyB,CAAC,CAAC,SAAS,WAAW,IAAI,kBAAkB,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;AAC1F,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,WAAW,IAAI,iBAAiB,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAA;AAEzF,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,kBAAkB,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA;AACpF,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,IAAI,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,WAAW,CAAC,CAAA"}
@@ -5,8 +5,8 @@ export declare const PayloadSchema: "network.xyo.payload";
5
5
  export type PayloadSchema = typeof PayloadSchema;
6
6
  export declare const isSchema: (value: unknown) => value is Schema;
7
7
  export declare const asSchema: {
8
- <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
9
- <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<string>, config?: import("@xylabs/object").TypeCheckConfig): TType;
8
+ <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
9
+ <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<string>, config?: import("@xylabs/object").TypeCheckConfig): TType;
10
10
  };
11
11
  /** Schema fields for a Payload */
12
12
  export interface SchemaFields extends EmptyObject {
@@ -20,7 +20,7 @@ var isPayloadOfSchemaType = (schema) => {
20
20
  return (x) => isAnyPayload(x) && x?.schema === schema;
21
21
  };
22
22
  var isPayloadOfSchemaTypeWithSources = (schema) => {
23
- return (x) => isPayloadOfSchemaType(schema)(x) && x.sources !== void 0 && Array.isArray(x.sources);
23
+ return (x) => isPayloadOfSchemaType(schema)(x) && x.$sources !== void 0 && Array.isArray(x.$sources);
24
24
  };
25
25
  var notPayloadOfSchemaType = (schema) => {
26
26
  return (x) => !isAnyPayload(x) || x?.schema !== schema;
@@ -142,7 +142,7 @@ var SequenceParser = class _SequenceParser {
142
142
  }
143
143
  const epoch = _SequenceParser.toEpoch(timestampOrSequence);
144
144
  const nonce = _SequenceParser.toNonce(nonceOrAddress);
145
- const addressHex = address ? toHex(address, { bitLength: SequenceConstants.addressBytes * 8 }) : "";
145
+ const addressHex = address ? toHex(address, { bitLength: SequenceConstants.addressBytes * 8 }) : SequenceConstants.minAddress;
146
146
  const hexString = epoch + nonce + addressHex;
147
147
  assertEx(isSequence(hexString), () => `Invalid sequence [${hexString}] [${epoch}, ${nonce}, ${addressHex}]`);
148
148
  return new this(_SequenceParser.privateConstructorKey, hexString);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts","../../src/StorageMeta/Sequence.ts","../../src/StorageMeta/SequenceParser.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.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 const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\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>(schema: string) => {\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(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'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import type { EmptyObject } from '@xylabs/object'\nimport { AsTypeFactory } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n return typeof value === 'string'\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n","import type { Address, Hex } from '@xylabs/hex'\nimport { isHex } from '@xylabs/hex'\n\n// we use Exclude to intentionally make the type not equal to string\nexport type LocalSequence = Hex & Exclude<string, 'reserved-local-sequence-value'>\nexport type QualifiedSequence = Hex & Exclude<string, 'reserved-qualified-sequence-value'>\nexport type Sequence = LocalSequence | QualifiedSequence\n\nexport type Epoch = Hex & Exclude<string, 'reserved-epoch-sequence-value'>\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 = Hex & Exclude<string, 'reserved-nonce-sequence-value'>\n\nexport const isNonce = (value: unknown): value is Epoch => {\n return isHex(value) && (value as string).length === SequenceConstants.nonceBytes * 2\n}\n\nexport const isLocalSequence = (value: unknown): value is Sequence => {\n return isHex(value) && (value as string).length === SequenceConstants.localSequenceBytes * 2\n}\n\nexport const isQualifiedSequence = (value: unknown): value is Sequence => {\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 SequenceComponentLengths = {\n epochBytes: 8,\n nonceBytes: 8,\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 minLocalSequence: LocalSequenceConstants.minLocalSequence + SequenceComponentMinMax.minAddress as QualifiedSequence,\n maxLocalSequence: 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 { toUint8Array } from '@xylabs/arraybuffer'\nimport { assertEx } from '@xylabs/assert'\nimport {\n type Address,\n type Hash, type Hex,\n isAddress,\n toHex,\n} from '@xylabs/hex'\n\nimport type {\n Epoch, LocalSequence, Nonce, QualifiedSequence,\n Sequence,\n} from './Sequence.ts'\nimport {\n isQualifiedSequence, isSequence, 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 toHex(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 })\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 })\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 })\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 })\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: 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(timestampOrSequence: Sequence | Hex | number, nonceOrAddress: Hash | Nonce, address?: Address): SequenceParser {\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 = SequenceParser.toNonce(nonceOrAddress)\n const addressHex: Hex = address ? toHex(address, { bitLength: SequenceConstants.addressBytes * 8 }) : '' as Hex\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): 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 hash = toHex((hex as string), { prefix: false, bitLength: SequenceConstants.nonceBytes * 8 })\n return hash.slice(-SequenceConstants.nonceBytes * 2) as Nonce\n }\n}\n","import { type Hash, isHash } from '@xylabs/hex'\n\nimport type { Payload } from '../Payload.ts'\nimport type { Sequence } from './Sequence.ts'\n\nexport interface SequenceMeta {\n _sequence: Sequence\n}\n\nexport type WithPartialSequenceMeta<T extends Payload = Payload> = Partial<WithSequenceMeta<T>>\n\nexport type WithSequenceMeta<T extends Payload = Payload> = T & SequenceMeta\n\nexport interface HashMeta {\n _dataHash: Hash\n _hash: Hash\n}\n\nexport type WithPartialHashMeta<T extends Payload = Payload> = Partial<WithHashMeta<T>>\n\nexport type WithHashMeta<T extends Payload = Payload> = T & HashMeta\n\nexport interface StorageMeta extends SequenceMeta, HashMeta {}\n\nexport type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>\n\nexport type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta\n\nexport const isSequenceMeta = (value: unknown): value is SequenceMeta => {\n return (value as WithSequenceMeta)?._sequence !== undefined\n}\n\nexport const isHashMeta = (value: unknown): value is HashMeta => {\n return isHash((value as WithHashMeta)?._hash) && isHash((value as WithHashMeta)?._dataHash)\n}\n\nexport const isStorageMeta = (value: unknown): value is StorageMeta => {\n return isSequenceMeta(value) && isHashMeta(value)\n}\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14\" is and example of a local sequence string\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14a123456789abcdef0123\" is and example of a local sequence string\n// epoch = \"00005a7f354762f3ac\"\n// nonce = \"1bc5ddc6cfd08d14\"\n// address = \"a123456789abcdef0123\"\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAgB;AAInC,IAAM,eAAe,CAAC,UAAqC;AAChE,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,O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,QAAQ,OAA0B;AACvC;AAAA,MACE,OAAO,UAAU,YAAY,OAAO,UAAU,KAAK;AAAA,MACnD,MAAM;AAAA,IACR;AACA,UAAM,MAAM,MAAM,OAAO,EAAE,QAAQ,MAAM,CAAC;AAC1C,QAAI,WAAW,GAAG,GAAG;AACnB,aAAO,IAAI,MAAM,kBAAkB,aAAa,GAAG,kBAAkB,qBAAqB,CAAC;AAAA,IAC7F;AACA,UAAM,OAAO,MAAO,KAAgB,EAAE,QAAQ,OAAO,WAAW,kBAAkB,aAAa,EAAE,CAAC;AAClG,WAAO,KAAK,MAAM,CAAC,kBAAkB,aAAa,CAAC;AAAA,EACrD;AACF;;;AC5HA,SAAoB,cAAc;AA4B3B,IAAM,iBAAiB,CAAC,UAA0C;AACvE,SAAQ,OAA4B,cAAc;AACpD;AAEO,IAAM,aAAa,CAAC,UAAsC;AAC/D,SAAO,OAAQ,OAAwB,KAAK,KAAK,OAAQ,OAAwB,SAAS;AAC5F;AAEO,IAAM,gBAAgB,CAAC,UAAyC;AACrE,SAAO,eAAe,KAAK,KAAK,WAAW,KAAK;AAClD;","names":[]}
1
+ {"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts","../../src/StorageMeta/Sequence.ts","../../src/StorageMeta/SequenceParser.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.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 const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\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>(schema: string) => {\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(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'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import type { EmptyObject } from '@xylabs/object'\nimport { AsTypeFactory } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n return typeof value === 'string'\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n","import type { Address, Hex } from '@xylabs/hex'\nimport { isHex } from '@xylabs/hex'\n\n// we use Exclude to intentionally make the type not equal to string\nexport type LocalSequence = Hex & Exclude<string, 'reserved-local-sequence-value'>\nexport type QualifiedSequence = Hex & Exclude<string, 'reserved-qualified-sequence-value'>\nexport type Sequence = LocalSequence | QualifiedSequence\n\nexport type Epoch = Hex & Exclude<string, 'reserved-epoch-sequence-value'>\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 = Hex & Exclude<string, 'reserved-nonce-sequence-value'>\n\nexport const isNonce = (value: unknown): value is Epoch => {\n return isHex(value) && (value as string).length === SequenceConstants.nonceBytes * 2\n}\n\nexport const isLocalSequence = (value: unknown): value is Sequence => {\n return isHex(value) && (value as string).length === SequenceConstants.localSequenceBytes * 2\n}\n\nexport const isQualifiedSequence = (value: unknown): value is Sequence => {\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 SequenceComponentLengths = {\n epochBytes: 8,\n nonceBytes: 8,\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 minLocalSequence: LocalSequenceConstants.minLocalSequence + SequenceComponentMinMax.minAddress as QualifiedSequence,\n maxLocalSequence: 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 { toUint8Array } from '@xylabs/arraybuffer'\nimport { assertEx } from '@xylabs/assert'\nimport {\n type Address,\n type Hash, type Hex,\n isAddress,\n toHex,\n} from '@xylabs/hex'\n\nimport type {\n Epoch, LocalSequence, Nonce, QualifiedSequence,\n Sequence,\n} from './Sequence.ts'\nimport {\n isQualifiedSequence, isSequence, 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 toHex(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 })\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 })\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 })\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 })\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: 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(timestampOrSequence: Sequence | Hex | number, nonceOrAddress: Hash | Nonce, address?: Address): SequenceParser {\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 = SequenceParser.toNonce(nonceOrAddress)\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): 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 hash = toHex((hex as string), { prefix: false, bitLength: SequenceConstants.nonceBytes * 8 })\n return hash.slice(-SequenceConstants.nonceBytes * 2) as Nonce\n }\n}\n","import { type Hash, isHash } from '@xylabs/hex'\n\nimport type { Payload } from '../Payload.ts'\nimport type { Sequence } from './Sequence.ts'\n\nexport interface SequenceMeta {\n _sequence: Sequence\n}\n\nexport type WithPartialSequenceMeta<T extends Payload = Payload> = Partial<WithSequenceMeta<T>>\n\nexport type WithSequenceMeta<T extends Payload = Payload> = T & SequenceMeta\n\nexport interface HashMeta {\n _dataHash: Hash\n _hash: Hash\n}\n\nexport type WithPartialHashMeta<T extends Payload = Payload> = Partial<WithHashMeta<T>>\n\nexport type WithHashMeta<T extends Payload = Payload> = T & HashMeta\n\nexport interface StorageMeta extends SequenceMeta, HashMeta {}\n\nexport type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>\n\nexport type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta\n\nexport const isSequenceMeta = (value: unknown): value is SequenceMeta => {\n return (value as WithSequenceMeta)?._sequence !== undefined\n}\n\nexport const isHashMeta = (value: unknown): value is HashMeta => {\n return isHash((value as WithHashMeta)?._hash) && isHash((value as WithHashMeta)?._dataHash)\n}\n\nexport const isStorageMeta = (value: unknown): value is StorageMeta => {\n return isSequenceMeta(value) && isHashMeta(value)\n}\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14\" is and example of a local sequence string\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14a123456789abcdef0123\" is and example of a local sequence string\n// epoch = \"00005a7f354762f3ac\"\n// nonce = \"1bc5ddc6cfd08d14\"\n// address = \"a123456789abcdef0123\"\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAgB;AAInC,IAAM,eAAe,CAAC,UAAqC;AAChE,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,OAAO,MAAM,WAAW;AAAA,EACjC;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,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O,KAAgB,EAAE,QAAQ,OAAO,WAAW,kBAAkB,aAAa,EAAE,CAAC;AAClG,WAAO,KAAK,MAAM,CAAC,kBAAkB,aAAa,CAAC;AAAA,EACrD;AACF;;;AC5HA,SAAoB,cAAc;AA4B3B,IAAM,iBAAiB,CAAC,UAA0C;AACvE,SAAQ,OAA4B,cAAc;AACpD;AAEO,IAAM,aAAa,CAAC,UAAsC;AAC/D,SAAO,OAAQ,OAAwB,KAAK,KAAK,OAAQ,OAAwB,SAAS;AAC5F;AAEO,IAAM,gBAAgB,CAAC,UAAyC;AACrE,SAAO,eAAe,KAAK,KAAK,WAAW,KAAK;AAClD;","names":[]}
@@ -1,18 +1,18 @@
1
1
  import type { Payload } from './Payload.ts';
2
2
  export declare const isAnyPayload: (value: unknown) => value is Payload;
3
3
  export declare const asAnyPayload: {
4
- <TType extends import("./Payload.ts").DeepRestrictToStringKeys<{
4
+ <TType extends import("@xylabs/object").DeepRestrictToStringKeys<{
5
5
  schema: import("./Schema.ts").Schema;
6
- }>>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
7
- <TType extends import("./Payload.ts").DeepRestrictToStringKeys<{
6
+ }>>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
7
+ <TType extends import("@xylabs/object").DeepRestrictToStringKeys<{
8
8
  schema: import("./Schema.ts").Schema;
9
- }>>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<import("./Payload.ts").DeepRestrictToStringKeys<{
9
+ }>>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<import("@xylabs/object").DeepRestrictToStringKeys<{
10
10
  schema: import("./Schema.ts").Schema;
11
11
  }>>, config?: import("@xylabs/object").TypeCheckConfig): TType;
12
12
  };
13
13
  export declare const isPayload: <T extends Payload>(schema: string[]) => (value: unknown) => value is T;
14
14
  export declare const asPayload: <T extends Payload>(schema: string[]) => {
15
- <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
16
- <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
15
+ <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
16
+ <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
17
17
  };
18
18
  //# sourceMappingURL=isPayload.d.ts.map
@@ -11,7 +11,7 @@ export type ModuleError = Payload<{
11
11
  schema: ModuleErrorSchema;
12
12
  sources?: Hash[];
13
13
  }>;
14
- export declare const isModuleError: (x?: unknown | null) => x is import("./Payload.ts").DeepRestrictToStringKeys<{
14
+ export declare const isModuleError: (x?: unknown | null) => x is import("@xylabs/object").DeepRestrictToStringKeys<{
15
15
  schema: "network.xyo.error.module";
16
16
  details?: string | number | boolean | {
17
17
  [x: string]: string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | (string | number | boolean | /*elided*/ any | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
@@ -1,5 +1,5 @@
1
1
  import type { Hash } from '@xylabs/hex';
2
- import type { EmptyObject } from '@xylabs/object';
2
+ import type { DeepOmitStartsWith, DeepRestrictToStringKeys, EmptyObject } from '@xylabs/object';
3
3
  import type { Schema, WithSchema } from './Schema.ts';
4
4
  export interface SchemaField<T extends Schema = Schema> {
5
5
  schema: T;
@@ -17,17 +17,14 @@ export type Payload<T extends void | EmptyObject | WithSchema = void, S extends
17
17
  schema: S extends Schema ? S : Schema;
18
18
  }>;
19
19
  export type OverridablePayload<T extends Payload> = WithoutMeta<Omit<T, 'schema'> & PayloadFields>;
20
- export type WithSources<T extends EmptyObject> = T & {
21
- sources?: Hash[];
20
+ export type SourcesMetaField = {
21
+ $sources: Hash[];
22
22
  };
23
+ export type WithSources<T extends EmptyObject> = T & SourcesMetaField;
24
+ export type WithOptionalSources<T extends EmptyObject> = (T & SourcesMetaField) | T;
23
25
  export type PayloadWithSources<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithSources<Payload<T, S>>;
26
+ export type PayloadWithOptionalSources<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithOptionalSources<Payload<T, S>>;
24
27
  export type WithAnySchema<T extends Payload> = OverridablePayload<T>;
25
- export type DeepOmitStartsWith<T, Prefix extends string> = T extends (infer U)[] ? DeepOmitStartsWith<U, Prefix>[] : T extends object ? {
26
- [K in keyof T as K extends string ? K extends `${Prefix}${string}` ? never : K : K]: DeepOmitStartsWith<T[K], Prefix>;
27
- } : T;
28
- export type DeepRestrictToStringKeys<T> = {
29
- [K in keyof T as K extends string ? K : never]: T[K] extends (infer U)[] ? DeepRestrictToStringKeys<U>[] : T[K] extends object ? DeepRestrictToStringKeys<T[K]> : T[K];
30
- };
31
28
  export type WithoutClientMeta<T extends EmptyObject> = DeepOmitStartsWith<T, '$'>;
32
29
  export type WithoutStorageMeta<T extends EmptyObject> = DeepOmitStartsWith<T, '_'>;
33
30
  export type WithoutPrivateStorageMeta<T extends EmptyObject> = Deep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SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAC7I,MAAM,MAAM,0BAA0B,CAAC,CAAC,SAAS,IAAI,GAAG,WAAW,GAAG,UAAU,GAAG,IAAI,EAAE,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAE7J,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,OAAO,IAAI,kBAAkB,CAAC,CAAC,CAAC,CAAA;AAEpE,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,WAAW,IAAI,kBAAkB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AACjF,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,WAAW,IAAI,kBAAkB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AAClF,MAAM,MAAM,yBAAyB,CAAC,CAAC,SAAS,WAAW,IAAI,kBAAkB,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;AAC1F,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,WAAW,IAAI,iBAAiB,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAA;AAEzF,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,kBAAkB,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA;AACpF,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,IAAI,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,WAAW,CAAC,CAAA"}
@@ -5,8 +5,8 @@ export declare const PayloadSchema: "network.xyo.payload";
5
5
  export type PayloadSchema = typeof PayloadSchema;
6
6
  export declare const isSchema: (value: unknown) => value is Schema;
7
7
  export declare const asSchema: {
8
- <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
9
- <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<string>, config?: import("@xylabs/object").TypeCheckConfig): TType;
8
+ <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
9
+ <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<string>, config?: import("@xylabs/object").TypeCheckConfig): TType;
10
10
  };
11
11
  /** Schema fields for a Payload */
12
12
  export interface SchemaFields extends EmptyObject {
@@ -20,7 +20,7 @@ var isPayloadOfSchemaType = (schema) => {
20
20
  return (x) => isAnyPayload(x) && x?.schema === schema;
21
21
  };
22
22
  var isPayloadOfSchemaTypeWithSources = (schema) => {
23
- return (x) => isPayloadOfSchemaType(schema)(x) && x.sources !== void 0 && Array.isArray(x.sources);
23
+ return (x) => isPayloadOfSchemaType(schema)(x) && x.$sources !== void 0 && Array.isArray(x.$sources);
24
24
  };
25
25
  var notPayloadOfSchemaType = (schema) => {
26
26
  return (x) => !isAnyPayload(x) || x?.schema !== schema;
@@ -142,7 +142,7 @@ var SequenceParser = class _SequenceParser {
142
142
  }
143
143
  const epoch = _SequenceParser.toEpoch(timestampOrSequence);
144
144
  const nonce = _SequenceParser.toNonce(nonceOrAddress);
145
- const addressHex = address ? toHex(address, { bitLength: SequenceConstants.addressBytes * 8 }) : "";
145
+ const addressHex = address ? toHex(address, { bitLength: SequenceConstants.addressBytes * 8 }) : SequenceConstants.minAddress;
146
146
  const hexString = epoch + nonce + addressHex;
147
147
  assertEx(isSequence(hexString), () => `Invalid sequence [${hexString}] [${epoch}, ${nonce}, ${addressHex}]`);
148
148
  return new this(_SequenceParser.privateConstructorKey, hexString);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts","../../src/StorageMeta/Sequence.ts","../../src/StorageMeta/SequenceParser.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.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 const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\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>(schema: string) => {\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(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'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import type { EmptyObject } from '@xylabs/object'\nimport { AsTypeFactory } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n return typeof value === 'string'\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n","import type { Address, Hex } from '@xylabs/hex'\nimport { isHex } from '@xylabs/hex'\n\n// we use Exclude to intentionally make the type not equal to string\nexport type LocalSequence = Hex & Exclude<string, 'reserved-local-sequence-value'>\nexport type QualifiedSequence = Hex & Exclude<string, 'reserved-qualified-sequence-value'>\nexport type Sequence = LocalSequence | QualifiedSequence\n\nexport type Epoch = Hex & Exclude<string, 'reserved-epoch-sequence-value'>\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 = Hex & Exclude<string, 'reserved-nonce-sequence-value'>\n\nexport const isNonce = (value: unknown): value is Epoch => {\n return isHex(value) && (value as string).length === SequenceConstants.nonceBytes * 2\n}\n\nexport const isLocalSequence = (value: unknown): value is Sequence => {\n return isHex(value) && (value as string).length === SequenceConstants.localSequenceBytes * 2\n}\n\nexport const isQualifiedSequence = (value: unknown): value is Sequence => {\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 SequenceComponentLengths = {\n epochBytes: 8,\n nonceBytes: 8,\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 minLocalSequence: LocalSequenceConstants.minLocalSequence + SequenceComponentMinMax.minAddress as QualifiedSequence,\n maxLocalSequence: 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 { toUint8Array } from '@xylabs/arraybuffer'\nimport { assertEx } from '@xylabs/assert'\nimport {\n type Address,\n type Hash, type Hex,\n isAddress,\n toHex,\n} from '@xylabs/hex'\n\nimport type {\n Epoch, LocalSequence, Nonce, QualifiedSequence,\n Sequence,\n} from './Sequence.ts'\nimport {\n isQualifiedSequence, isSequence, 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 toHex(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 })\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 })\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 })\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 })\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: 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(timestampOrSequence: Sequence | Hex | number, nonceOrAddress: Hash | Nonce, address?: Address): SequenceParser {\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 = SequenceParser.toNonce(nonceOrAddress)\n const addressHex: Hex = address ? toHex(address, { bitLength: SequenceConstants.addressBytes * 8 }) : '' as Hex\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): 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 hash = toHex((hex as string), { prefix: false, bitLength: SequenceConstants.nonceBytes * 8 })\n return hash.slice(-SequenceConstants.nonceBytes * 2) as Nonce\n }\n}\n","import { type Hash, isHash } from '@xylabs/hex'\n\nimport type { Payload } from '../Payload.ts'\nimport type { Sequence } from './Sequence.ts'\n\nexport interface SequenceMeta {\n _sequence: Sequence\n}\n\nexport type WithPartialSequenceMeta<T extends Payload = Payload> = Partial<WithSequenceMeta<T>>\n\nexport type WithSequenceMeta<T extends Payload = Payload> = T & SequenceMeta\n\nexport interface HashMeta {\n _dataHash: Hash\n _hash: Hash\n}\n\nexport type WithPartialHashMeta<T extends Payload = Payload> = Partial<WithHashMeta<T>>\n\nexport type WithHashMeta<T extends Payload = Payload> = T & HashMeta\n\nexport interface StorageMeta extends SequenceMeta, HashMeta {}\n\nexport type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>\n\nexport type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta\n\nexport const isSequenceMeta = (value: unknown): value is SequenceMeta => {\n return (value as WithSequenceMeta)?._sequence !== undefined\n}\n\nexport const isHashMeta = (value: unknown): value is HashMeta => {\n return isHash((value as WithHashMeta)?._hash) && isHash((value as WithHashMeta)?._dataHash)\n}\n\nexport const isStorageMeta = (value: unknown): value is StorageMeta => {\n return isSequenceMeta(value) && isHashMeta(value)\n}\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14\" is and example of a local sequence string\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14a123456789abcdef0123\" is and example of a local sequence string\n// epoch = \"00005a7f354762f3ac\"\n// nonce = \"1bc5ddc6cfd08d14\"\n// address = \"a123456789abcdef0123\"\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAgB;AAInC,IAAM,eAAe,CAAC,UAAqC;AAChE,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,OAAO,MAAM,WAAW;AAAA,EACjC;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,IAAM,wBAAwB,CAAoB,WAAmB;AAC1E,SAAO,CAAC,MAA+B,aAAa,CAAC,KAAK,GAAG,WAAW;AAC1E;AAEO,IAAM,mCAAmC,CAAoB,WAAmB;AACrF,SAAO,CAAC,MACN,sBAAsC,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,UAAa,MAAM,QAAQ,EAAE,OAAO;AAC1G;AAEO,IAAM,yBAAyB,CAAoB,WAAmB;AAC3E,SAAO,CAAC,MAA+B,CAAC,aAAa,CAAC,KAAK,GAAG,WAAW;AAC3E;;;ACPO,IAAM,oBAAuC;AAW7C,IAAM,gBAAgB,sBAAmC,iBAAiB;;;ACjB1E,IAAM,mBAAqC;;;ACAlD,SAAS,qBAAqB;AAKvB,IAAM,gBAAgB;AAGtB,IAAM,WAAW,CAAC,UAAoC;AAC3D,SAAO,OAAO,UAAU;AAC1B;AAEO,IAAM,WAAW,cAAc,OAAe,QAAQ;;;ACZ7D,SAAS,aAAa;AASf,IAAM,UAAU,CAAC,UAAmC;AACzD,SAAO,MAAM,KAAK,KAAM,MAAiB,WA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AAM,OAAO,EAAE,QAAQ,OAAO,WAAW,kBAAkB,aAAa,EAAE,CAAC;AAAA,IACpF;AACA,QAAI,WAAW,GAAG,GAAG;AACnB,aAAO,IAAI,MAAM,GAAG,kBAAkB,aAAa,CAAC;AAAA,IACtD;AACA,UAAM,IAAI,MAAM,0CAA0C,GAAG,GAAG;AAAA,EAClE;AAAA;AAAA,EAGA,OAAO,QAAQ,OAA0B;AACvC;AAAA,MACE,OAAO,UAAU,YAAY,OAAO,UAAU,KAAK;AAAA,MACnD,MAAM;AAAA,IACR;AACA,UAAM,MAAM,MAAM,OAAO,EAAE,QAAQ,MAAM,CAAC;AAC1C,QAAI,WAAW,GAAG,GAAG;AACnB,aAAO,IAAI,MAAM,kBAAkB,aAAa,GAAG,kBAAkB,qBAAqB,CAAC;AAAA,IAC7F;AACA,UAAM,OAAO,MAAO,KAAgB,EAAE,QAAQ,OAAO,WAAW,kBAAkB,aAAa,EAAE,CAAC;AAClG,WAAO,KAAK,MAAM,CAAC,kBAAkB,aAAa,CAAC;AAAA,EACrD;AACF;;;AC5HA,SAAoB,cAAc;AA4B3B,IAAM,iBAAiB,CAAC,UAA0C;AACvE,SAAQ,OAA4B,cAAc;AACpD;AAEO,IAAM,aAAa,CAAC,UAAsC;AAC/D,SAAO,OAAQ,OAAwB,KAAK,KAAK,OAAQ,OAAwB,SAAS;AAC5F;AAEO,IAAM,gBAAgB,CAAC,UAAyC;AACrE,SAAO,eAAe,KAAK,KAAK,WAAW,KAAK;AAClD;","names":[]}
1
+ {"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts","../../src/StorageMeta/Sequence.ts","../../src/StorageMeta/SequenceParser.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.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 const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\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>(schema: string) => {\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(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'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import type { EmptyObject } from '@xylabs/object'\nimport { AsTypeFactory } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n return typeof value === 'string'\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n","import type { Address, Hex } from '@xylabs/hex'\nimport { isHex } from '@xylabs/hex'\n\n// we use Exclude to intentionally make the type not equal to string\nexport type LocalSequence = Hex & Exclude<string, 'reserved-local-sequence-value'>\nexport type QualifiedSequence = Hex & Exclude<string, 'reserved-qualified-sequence-value'>\nexport type Sequence = LocalSequence | QualifiedSequence\n\nexport type Epoch = Hex & Exclude<string, 'reserved-epoch-sequence-value'>\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 = Hex & Exclude<string, 'reserved-nonce-sequence-value'>\n\nexport const isNonce = (value: unknown): value is Epoch => {\n return isHex(value) && (value as string).length === SequenceConstants.nonceBytes * 2\n}\n\nexport const isLocalSequence = (value: unknown): value is Sequence => {\n return isHex(value) && (value as string).length === SequenceConstants.localSequenceBytes * 2\n}\n\nexport const isQualifiedSequence = (value: unknown): value is Sequence => {\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 SequenceComponentLengths = {\n epochBytes: 8,\n nonceBytes: 8,\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 minLocalSequence: LocalSequenceConstants.minLocalSequence + SequenceComponentMinMax.minAddress as QualifiedSequence,\n maxLocalSequence: 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 { toUint8Array } from '@xylabs/arraybuffer'\nimport { assertEx } from '@xylabs/assert'\nimport {\n type Address,\n type Hash, type Hex,\n isAddress,\n toHex,\n} from '@xylabs/hex'\n\nimport type {\n Epoch, LocalSequence, Nonce, QualifiedSequence,\n Sequence,\n} from './Sequence.ts'\nimport {\n isQualifiedSequence, isSequence, 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 toHex(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 })\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 })\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 })\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 })\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: 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(timestampOrSequence: Sequence | Hex | number, nonceOrAddress: Hash | Nonce, address?: Address): SequenceParser {\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 = SequenceParser.toNonce(nonceOrAddress)\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): 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 hash = toHex((hex as string), { prefix: false, bitLength: SequenceConstants.nonceBytes * 8 })\n return hash.slice(-SequenceConstants.nonceBytes * 2) as Nonce\n }\n}\n","import { type Hash, isHash } from '@xylabs/hex'\n\nimport type { Payload } from '../Payload.ts'\nimport type { Sequence } from './Sequence.ts'\n\nexport interface SequenceMeta {\n _sequence: Sequence\n}\n\nexport type WithPartialSequenceMeta<T extends Payload = Payload> = Partial<WithSequenceMeta<T>>\n\nexport type WithSequenceMeta<T extends Payload = Payload> = T & SequenceMeta\n\nexport interface HashMeta {\n _dataHash: Hash\n _hash: Hash\n}\n\nexport type WithPartialHashMeta<T extends Payload = Payload> = Partial<WithHashMeta<T>>\n\nexport type WithHashMeta<T extends Payload = Payload> = T & HashMeta\n\nexport interface StorageMeta extends SequenceMeta, HashMeta {}\n\nexport type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>\n\nexport type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta\n\nexport const isSequenceMeta = (value: unknown): value is SequenceMeta => {\n return (value as WithSequenceMeta)?._sequence !== undefined\n}\n\nexport const isHashMeta = (value: unknown): value is HashMeta => {\n return isHash((value as WithHashMeta)?._hash) && isHash((value as WithHashMeta)?._dataHash)\n}\n\nexport const isStorageMeta = (value: unknown): value is StorageMeta => {\n return isSequenceMeta(value) && isHashMeta(value)\n}\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14\" is and example of a local sequence string\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14a123456789abcdef0123\" is and example of a local sequence string\n// epoch = \"00005a7f354762f3ac\"\n// nonce = \"1bc5ddc6cfd08d14\"\n// address = \"a123456789abcdef0123\"\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAgB;AAInC,IAAM,eAAe,CAAC,UAAqC;AAChE,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,OAAO,MAAM,WAAW;AAAA,EACjC;AACA,SAAO;AACT;AAEO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AAU,YAAY,OAAO,UAAU,KAAK;AAAA,MACnD,MAAM;AAAA,IACR;AACA,UAAM,MAAM,MAAM,OAAO,EAAE,QAAQ,MAAM,CAAC;AAC1C,QAAI,WAAW,GAAG,GAAG;AACnB,aAAO,IAAI,MAAM,kBAAkB,aAAa,GAAG,kBAAkB,qBAAqB,CAAC;AAAA,IAC7F;AACA,UAAM,OAAO,MAAO,KAAgB,EAAE,QAAQ,OAAO,WAAW,kBAAkB,aAAa,EAAE,CAAC;AAClG,WAAO,KAAK,MAAM,CAAC,kBAAkB,aAAa,CAAC;AAAA,EACrD;AACF;;;AC5HA,SAAoB,cAAc;AA4B3B,IAAM,iBAAiB,CAAC,UAA0C;AACvE,SAAQ,OAA4B,cAAc;AACpD;AAEO,IAAM,aAAa,CAAC,UAAsC;AAC/D,SAAO,OAAQ,OAAwB,KAAK,KAAK,OAAQ,OAAwB,SAAS;AAC5F;AAEO,IAAM,gBAAgB,CAAC,UAAyC;AACrE,SAAO,eAAe,KAAK,KAAK,WAAW,KAAK;AAClD;","names":[]}
@@ -1,18 +1,18 @@
1
1
  import type { Payload } from './Payload.ts';
2
2
  export declare const isAnyPayload: (value: unknown) => value is Payload;
3
3
  export declare const asAnyPayload: {
4
- <TType extends import("./Payload.ts").DeepRestrictToStringKeys<{
4
+ <TType extends import("@xylabs/object").DeepRestrictToStringKeys<{
5
5
  schema: import("./Schema.ts").Schema;
6
- }>>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
7
- <TType extends import("./Payload.ts").DeepRestrictToStringKeys<{
6
+ }>>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
7
+ <TType extends import("@xylabs/object").DeepRestrictToStringKeys<{
8
8
  schema: import("./Schema.ts").Schema;
9
- }>>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<import("./Payload.ts").DeepRestrictToStringKeys<{
9
+ }>>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<import("@xylabs/object").DeepRestrictToStringKeys<{
10
10
  schema: import("./Schema.ts").Schema;
11
11
  }>>, config?: import("@xylabs/object").TypeCheckConfig): TType;
12
12
  };
13
13
  export declare const isPayload: <T extends Payload>(schema: string[]) => (value: unknown) => value is T;
14
14
  export declare const asPayload: <T extends Payload>(schema: string[]) => {
15
- <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
16
- <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.15-6ab7463903/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
15
+ <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
16
+ <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.16-991629d558/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
17
17
  };
18
18
  //# sourceMappingURL=isPayload.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/payload-model",
3
- "version": "3.6.0-rc.6",
3
+ "version": "3.6.0-rc.8",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -37,15 +37,15 @@
37
37
  "module": "dist/neutral/index.mjs",
38
38
  "types": "dist/neutral/index.d.ts",
39
39
  "dependencies": {
40
- "@xylabs/arraybuffer": "^4.4.15",
41
- "@xylabs/assert": "^4.4.15",
42
- "@xylabs/hex": "^4.4.15",
43
- "@xylabs/object": "^4.4.15"
40
+ "@xylabs/arraybuffer": "^4.4.16",
41
+ "@xylabs/assert": "^4.4.16",
42
+ "@xylabs/hex": "^4.4.16",
43
+ "@xylabs/object": "^4.4.16"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@xylabs/ts-scripts-yarn3": "^4.2.4",
47
47
  "@xylabs/tsconfig": "^4.2.4",
48
- "@xylabs/vitest-extended": "^4.4.15",
48
+ "@xylabs/vitest-extended": "^4.4.16",
49
49
  "typescript": "^5.7.2",
50
50
  "vitest": "^2.1.8"
51
51
  },
package/src/Payload.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import type { Hash } from '@xylabs/hex'
2
- import type { EmptyObject } from '@xylabs/object'
2
+ import type {
3
+ DeepOmitStartsWith, DeepRestrictToStringKeys, EmptyObject,
4
+ } from '@xylabs/object'
3
5
 
4
6
  import type { Schema, WithSchema } from './Schema.ts'
5
7
 
@@ -32,30 +34,15 @@ export type Payload<T extends void | EmptyObject | WithSchema = void, S extends
32
34
 
33
35
  export type OverridablePayload<T extends Payload> = WithoutMeta<Omit<T, 'schema'> & PayloadFields>
34
36
 
35
- export type WithSources<T extends EmptyObject> = T & { sources?: Hash[] }
36
- export type PayloadWithSources<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithSources<Payload<T, S>>
37
+ export type SourcesMetaField = { $sources: Hash[] }
37
38
 
38
- export type WithAnySchema<T extends Payload> = OverridablePayload<T>
39
+ export type WithSources<T extends EmptyObject> = T & SourcesMetaField
40
+ export type WithOptionalSources<T extends EmptyObject> = (T & SourcesMetaField) | T
39
41
 
40
- export type DeepOmitStartsWith<T, Prefix extends string> = T extends (infer U)[]
41
- ? DeepOmitStartsWith<U, Prefix>[] // Special handling for arrays
42
- : T extends object
43
- ? {
44
- [K in keyof T as K extends string
45
- ? K extends `${Prefix}${string}`
46
- ? never
47
- : K
48
- : K]: DeepOmitStartsWith<T[K], Prefix>;
49
- }
50
- : T
42
+ export type PayloadWithSources<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithSources<Payload<T, S>>
43
+ export type PayloadWithOptionalSources<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithOptionalSources<Payload<T, S>>
51
44
 
52
- export type DeepRestrictToStringKeys<T> = {
53
- [K in keyof T as K extends string ? K : never]: T[K] extends (infer U)[]
54
- ? DeepRestrictToStringKeys<U>[] // Handle arrays recursively
55
- : T[K] extends object
56
- ? DeepRestrictToStringKeys<T[K]> // Handle objects recursively
57
- : T[K]; // Leave other types untouched
58
- }
45
+ export type WithAnySchema<T extends Payload> = OverridablePayload<T>
59
46
 
60
47
  export type WithoutClientMeta<T extends EmptyObject> = DeepOmitStartsWith<T, '$'>
61
48
  export type WithoutStorageMeta<T extends EmptyObject> = DeepOmitStartsWith<T, '_'>
@@ -63,5 +50,4 @@ export type WithoutPrivateStorageMeta<T extends EmptyObject> = DeepOmitStartsWit
63
50
  export type WithoutMeta<T extends EmptyObject> = WithoutClientMeta<WithoutStorageMeta<T>>
64
51
 
65
52
  export type WithoutSchema<T extends WithOptionalSchema<Payload>> = Omit<T, 'schema'>
66
-
67
53
  export type WithOptionalSchema<T extends EmptyObject = EmptyObject> = WithoutSchema<T> & Partial<T & SchemaField>
@@ -79,7 +79,7 @@ export class SequenceParser {
79
79
  }
80
80
  const epoch = SequenceParser.toEpoch(timestampOrSequence)
81
81
  const nonce = SequenceParser.toNonce(nonceOrAddress)
82
- const addressHex: Hex = address ? toHex(address, { bitLength: SequenceConstants.addressBytes * 8 }) : '' as Hex
82
+ const addressHex: Hex = address ? toHex(address, { bitLength: SequenceConstants.addressBytes * 8 }) : SequenceConstants.minAddress
83
83
  const hexString = (epoch + nonce + addressHex) as Hex
84
84
  assertEx(isSequence(hexString), () => `Invalid sequence [${hexString}] [${epoch}, ${nonce}, ${addressHex}]`)
85
85
  return new this(SequenceParser.privateConstructorKey, hexString)
@@ -7,7 +7,7 @@ export const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {
7
7
 
8
8
  export const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {
9
9
  return (x?: unknown | null): x is WithSources<T> =>
10
- isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.sources !== undefined && Array.isArray(x.sources)
10
+ isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.$sources !== undefined && Array.isArray(x.$sources)
11
11
  }
12
12
 
13
13
  export const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {