@xyo-network/payload-model 3.6.0-rc.8 → 3.6.0-rc.9
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.
- package/dist/browser/Error.d.ts +0 -2
- package/dist/browser/Error.d.ts.map +1 -1
- package/dist/browser/Payload.d.ts +2 -1
- package/dist/browser/Payload.d.ts.map +1 -1
- package/dist/browser/Schema.d.ts +2 -2
- package/dist/browser/index.mjs.map +1 -1
- package/dist/browser/isPayload.d.ts +4 -4
- package/dist/neutral/Error.d.ts +0 -2
- package/dist/neutral/Error.d.ts.map +1 -1
- package/dist/neutral/Payload.d.ts +2 -1
- package/dist/neutral/Payload.d.ts.map +1 -1
- package/dist/neutral/Schema.d.ts +2 -2
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/isPayload.d.ts +4 -4
- package/dist/node/Error.d.ts +0 -2
- package/dist/node/Error.d.ts.map +1 -1
- package/dist/node/Payload.d.ts +2 -1
- package/dist/node/Payload.d.ts.map +1 -1
- package/dist/node/Schema.d.ts +2 -2
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/isPayload.d.ts +4 -4
- package/package.json +6 -6
- package/src/Error.ts +0 -1
- package/src/Payload.ts +3 -1
package/dist/browser/Error.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ export type ModuleError = Payload<{
|
|
|
9
9
|
name?: string;
|
|
10
10
|
query?: Hash;
|
|
11
11
|
schema: ModuleErrorSchema;
|
|
12
|
-
sources?: Hash[];
|
|
13
12
|
}>;
|
|
14
13
|
export declare const isModuleError: (x?: unknown | null) => x is import("@xylabs/object").DeepRestrictToStringKeys<{
|
|
15
14
|
schema: "network.xyo.error.module";
|
|
@@ -41,6 +40,5 @@ export declare const isModuleError: (x?: unknown | null) => x is import("@xylabs
|
|
|
41
40
|
message?: string | undefined;
|
|
42
41
|
name?: string | undefined;
|
|
43
42
|
query?: Hash | undefined;
|
|
44
|
-
sources?: Lowercase<string>[] | undefined;
|
|
45
43
|
}>;
|
|
46
44
|
//# sourceMappingURL=Error.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../src/Error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,MAAM,MAAM,iBAAiB,GAAG,0BAA0B,CAAA;AAC1D,eAAO,MAAM,iBAAiB,EAAE,iBAA8C,CAAA;AAE9E,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC;IAChC,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ,MAAM,EAAE,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../src/Error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,MAAM,MAAM,iBAAiB,GAAG,0BAA0B,CAAA;AAC1D,eAAO,MAAM,iBAAiB,EAAE,iBAA8C,CAAA;AAE9E,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC;IAChC,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ,MAAM,EAAE,iBAAiB,CAAA;CAC1B,CAAC,CAAA;AAEF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;cANd,MAAM;WACT,MAAM;YACL,IAAI;EAIoE,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Hash } from '@xylabs/hex';
|
|
2
|
-
import type { DeepOmitStartsWith, DeepRestrictToStringKeys, EmptyObject } from '@xylabs/object';
|
|
2
|
+
import type { DeepOmitStartsWith, DeepPickStartsWith, 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;
|
|
@@ -31,4 +31,5 @@ export type WithoutPrivateStorageMeta<T extends EmptyObject> = DeepOmitStartsWit
|
|
|
31
31
|
export type WithoutMeta<T extends EmptyObject> = WithoutClientMeta<WithoutStorageMeta<T>>;
|
|
32
32
|
export type WithoutSchema<T extends WithOptionalSchema<Payload>> = Omit<T, 'schema'>;
|
|
33
33
|
export type WithOptionalSchema<T extends EmptyObject = EmptyObject> = WithoutSchema<T> & Partial<T & SchemaField>;
|
|
34
|
+
export type WithOnlyClientMeta<T extends EmptyObject> = DeepPickStartsWith<T, '$'>;
|
|
34
35
|
//# sourceMappingURL=Payload.d.ts.map
|
|
@@ -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,EACV,kBAAkB,EAAE,wBAAwB,EAAE,WAAW,
|
|
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,EACV,kBAAkB,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,WAAW,EAC9E,MAAM,gBAAgB,CAAA;AAEvB,OAAO,KA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W,GAAG,WAAW,IAAI,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,WAAW,CAAC,CAAA;AAEjH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,WAAW,IAAI,kBAAkB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA"}
|
package/dist/browser/Schema.d.ts
CHANGED
|
@@ -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.
|
|
9
|
-
<TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.
|
|
8
|
+
<TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
9
|
+
<TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/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 {
|
|
@@ -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 }) : 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,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Q,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}>\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,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B,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":[]}
|
|
@@ -3,16 +3,16 @@ export declare const isAnyPayload: (value: unknown) => value is Payload;
|
|
|
3
3
|
export declare const asAnyPayload: {
|
|
4
4
|
<TType extends import("@xylabs/object").DeepRestrictToStringKeys<{
|
|
5
5
|
schema: import("./Schema.ts").Schema;
|
|
6
|
-
}>>(value: import(".store/@xylabs-promise-npm-4.4.
|
|
6
|
+
}>>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
7
7
|
<TType extends import("@xylabs/object").DeepRestrictToStringKeys<{
|
|
8
8
|
schema: import("./Schema.ts").Schema;
|
|
9
|
-
}>>(value: import(".store/@xylabs-promise-npm-4.4.
|
|
9
|
+
}>>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/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.
|
|
16
|
-
<TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.
|
|
15
|
+
<TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
16
|
+
<TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
|
|
17
17
|
};
|
|
18
18
|
//# sourceMappingURL=isPayload.d.ts.map
|
package/dist/neutral/Error.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ export type ModuleError = Payload<{
|
|
|
9
9
|
name?: string;
|
|
10
10
|
query?: Hash;
|
|
11
11
|
schema: ModuleErrorSchema;
|
|
12
|
-
sources?: Hash[];
|
|
13
12
|
}>;
|
|
14
13
|
export declare const isModuleError: (x?: unknown | null) => x is import("@xylabs/object").DeepRestrictToStringKeys<{
|
|
15
14
|
schema: "network.xyo.error.module";
|
|
@@ -41,6 +40,5 @@ export declare const isModuleError: (x?: unknown | null) => x is import("@xylabs
|
|
|
41
40
|
message?: string | undefined;
|
|
42
41
|
name?: string | undefined;
|
|
43
42
|
query?: Hash | undefined;
|
|
44
|
-
sources?: Lowercase<string>[] | undefined;
|
|
45
43
|
}>;
|
|
46
44
|
//# sourceMappingURL=Error.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../src/Error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,MAAM,MAAM,iBAAiB,GAAG,0BAA0B,CAAA;AAC1D,eAAO,MAAM,iBAAiB,EAAE,iBAA8C,CAAA;AAE9E,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC;IAChC,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ,MAAM,EAAE,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../src/Error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,MAAM,MAAM,iBAAiB,GAAG,0BAA0B,CAAA;AAC1D,eAAO,MAAM,iBAAiB,EAAE,iBAA8C,CAAA;AAE9E,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC;IAChC,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ,MAAM,EAAE,iBAAiB,CAAA;CAC1B,CAAC,CAAA;AAEF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;cANd,MAAM;WACT,MAAM;YACL,IAAI;EAIoE,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Hash } from '@xylabs/hex';
|
|
2
|
-
import type { DeepOmitStartsWith, DeepRestrictToStringKeys, EmptyObject } from '@xylabs/object';
|
|
2
|
+
import type { DeepOmitStartsWith, DeepPickStartsWith, 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;
|
|
@@ -31,4 +31,5 @@ export type WithoutPrivateStorageMeta<T extends EmptyObject> = DeepOmitStartsWit
|
|
|
31
31
|
export type WithoutMeta<T extends EmptyObject> = WithoutClientMeta<WithoutStorageMeta<T>>;
|
|
32
32
|
export type WithoutSchema<T extends WithOptionalSchema<Payload>> = Omit<T, 'schema'>;
|
|
33
33
|
export type WithOptionalSchema<T extends EmptyObject = EmptyObject> = WithoutSchema<T> & Partial<T & SchemaField>;
|
|
34
|
+
export type WithOnlyClientMeta<T extends EmptyObject> = DeepPickStartsWith<T, '$'>;
|
|
34
35
|
//# sourceMappingURL=Payload.d.ts.map
|
|
@@ -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,EACV,kBAAkB,EAAE,wBAAwB,EAAE,WAAW,
|
|
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,EACV,kBAAkB,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,WAAW,EAC9E,MAAM,gBAAgB,CAAA;AAEvB,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,IAAI,GAAG,IAAI,IACzD,wBAAwB,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,aAAa,GAAG,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAA;AAE9G,6BAA6B;AAC7B,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,IAAI,GAAG,WAAW,GAAG,UAAU,GAAG,IAAI,EAAE,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,IAA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,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;AAEjH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,WAAW,IAAI,kBAAkB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA"}
|
package/dist/neutral/Schema.d.ts
CHANGED
|
@@ -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.
|
|
9
|
-
<TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.
|
|
8
|
+
<TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
9
|
+
<TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/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 {
|
|
@@ -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 }) : 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,EAAE,QAAQ;AAC5G;AAEO,IAAM,yBAAyB,CAAoB,WAAmB;AAC3E,SAAO,CAAC,MAA+B,CAAC,aAAa,CAAC,KAAK,GAAG,WAAW;AAC3E;;;ACPO,IAAM,oBAAuC;AAW7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AClD;","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}>\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,EAAE,QAAQ;AAC5G;AAEO,IAAM,yBAAyB,CAAoB,WAAmB;AAC3E,SAAO,CAAC,MAA+B,CAAC,aAAa,CAAC,KAAK,GAAG,WAAW;AAC3E;;;ACPO,IAAM,oBAAuC;AAU7C,IAAM,gBAAgB,sBAAmC,iBAAiB;;;AChB1E,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,M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AG;AAClD,aAAO,MAAM,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":[]}
|
|
@@ -3,16 +3,16 @@ export declare const isAnyPayload: (value: unknown) => value is Payload;
|
|
|
3
3
|
export declare const asAnyPayload: {
|
|
4
4
|
<TType extends import("@xylabs/object").DeepRestrictToStringKeys<{
|
|
5
5
|
schema: import("./Schema.ts").Schema;
|
|
6
|
-
}>>(value: import(".store/@xylabs-promise-npm-4.4.
|
|
6
|
+
}>>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
7
7
|
<TType extends import("@xylabs/object").DeepRestrictToStringKeys<{
|
|
8
8
|
schema: import("./Schema.ts").Schema;
|
|
9
|
-
}>>(value: import(".store/@xylabs-promise-npm-4.4.
|
|
9
|
+
}>>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/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.
|
|
16
|
-
<TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.
|
|
15
|
+
<TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
16
|
+
<TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
|
|
17
17
|
};
|
|
18
18
|
//# sourceMappingURL=isPayload.d.ts.map
|
package/dist/node/Error.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ export type ModuleError = Payload<{
|
|
|
9
9
|
name?: string;
|
|
10
10
|
query?: Hash;
|
|
11
11
|
schema: ModuleErrorSchema;
|
|
12
|
-
sources?: Hash[];
|
|
13
12
|
}>;
|
|
14
13
|
export declare const isModuleError: (x?: unknown | null) => x is import("@xylabs/object").DeepRestrictToStringKeys<{
|
|
15
14
|
schema: "network.xyo.error.module";
|
|
@@ -41,6 +40,5 @@ export declare const isModuleError: (x?: unknown | null) => x is import("@xylabs
|
|
|
41
40
|
message?: string | undefined;
|
|
42
41
|
name?: string | undefined;
|
|
43
42
|
query?: Hash | undefined;
|
|
44
|
-
sources?: Lowercase<string>[] | undefined;
|
|
45
43
|
}>;
|
|
46
44
|
//# sourceMappingURL=Error.d.ts.map
|
package/dist/node/Error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../src/Error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,MAAM,MAAM,iBAAiB,GAAG,0BAA0B,CAAA;AAC1D,eAAO,MAAM,iBAAiB,EAAE,iBAA8C,CAAA;AAE9E,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC;IAChC,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ,MAAM,EAAE,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../src/Error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,MAAM,MAAM,iBAAiB,GAAG,0BAA0B,CAAA;AAC1D,eAAO,MAAM,iBAAiB,EAAE,iBAA8C,CAAA;AAE9E,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC;IAChC,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ,MAAM,EAAE,iBAAiB,CAAA;CAC1B,CAAC,CAAA;AAEF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;cANd,MAAM;WACT,MAAM;YACL,IAAI;EAIoE,CAAA"}
|
package/dist/node/Payload.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Hash } from '@xylabs/hex';
|
|
2
|
-
import type { DeepOmitStartsWith, DeepRestrictToStringKeys, EmptyObject } from '@xylabs/object';
|
|
2
|
+
import type { DeepOmitStartsWith, DeepPickStartsWith, 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;
|
|
@@ -31,4 +31,5 @@ export type WithoutPrivateStorageMeta<T extends EmptyObject> = DeepOmitStartsWit
|
|
|
31
31
|
export type WithoutMeta<T extends EmptyObject> = WithoutClientMeta<WithoutStorageMeta<T>>;
|
|
32
32
|
export type WithoutSchema<T extends WithOptionalSchema<Payload>> = Omit<T, 'schema'>;
|
|
33
33
|
export type WithOptionalSchema<T extends EmptyObject = EmptyObject> = WithoutSchema<T> & Partial<T & SchemaField>;
|
|
34
|
+
export type WithOnlyClientMeta<T extends EmptyObject> = DeepPickStartsWith<T, '$'>;
|
|
34
35
|
//# sourceMappingURL=Payload.d.ts.map
|
|
@@ -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,EACV,kBAAkB,EAAE,wBAAwB,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../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AC,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;AAEjH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,WAAW,IAAI,kBAAkB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA"}
|
package/dist/node/Schema.d.ts
CHANGED
|
@@ -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.
|
|
9
|
-
<TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.
|
|
8
|
+
<TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
9
|
+
<TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/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 {
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -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 }) : 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;A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ACtD;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}>\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;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BAAkB,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":[]}
|
package/dist/node/isPayload.d.ts
CHANGED
|
@@ -3,16 +3,16 @@ export declare const isAnyPayload: (value: unknown) => value is Payload;
|
|
|
3
3
|
export declare const asAnyPayload: {
|
|
4
4
|
<TType extends import("@xylabs/object").DeepRestrictToStringKeys<{
|
|
5
5
|
schema: import("./Schema.ts").Schema;
|
|
6
|
-
}>>(value: import(".store/@xylabs-promise-npm-4.4.
|
|
6
|
+
}>>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
7
7
|
<TType extends import("@xylabs/object").DeepRestrictToStringKeys<{
|
|
8
8
|
schema: import("./Schema.ts").Schema;
|
|
9
|
-
}>>(value: import(".store/@xylabs-promise-npm-4.4.
|
|
9
|
+
}>>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/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.
|
|
16
|
-
<TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.
|
|
15
|
+
<TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
16
|
+
<TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.18-241add3a6d/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.
|
|
3
|
+
"version": "3.6.0-rc.9",
|
|
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.
|
|
41
|
-
"@xylabs/assert": "^4.4.
|
|
42
|
-
"@xylabs/hex": "^4.4.
|
|
43
|
-
"@xylabs/object": "^4.4.
|
|
40
|
+
"@xylabs/arraybuffer": "^4.4.18",
|
|
41
|
+
"@xylabs/assert": "^4.4.18",
|
|
42
|
+
"@xylabs/hex": "^4.4.18",
|
|
43
|
+
"@xylabs/object": "^4.4.18"
|
|
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.
|
|
48
|
+
"@xylabs/vitest-extended": "^4.4.18",
|
|
49
49
|
"typescript": "^5.7.2",
|
|
50
50
|
"vitest": "^2.1.8"
|
|
51
51
|
},
|
package/src/Error.ts
CHANGED
package/src/Payload.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Hash } from '@xylabs/hex'
|
|
2
2
|
import type {
|
|
3
|
-
DeepOmitStartsWith, DeepRestrictToStringKeys, EmptyObject,
|
|
3
|
+
DeepOmitStartsWith, DeepPickStartsWith, DeepRestrictToStringKeys, EmptyObject,
|
|
4
4
|
} from '@xylabs/object'
|
|
5
5
|
|
|
6
6
|
import type { Schema, WithSchema } from './Schema.ts'
|
|
@@ -51,3 +51,5 @@ export type WithoutMeta<T extends EmptyObject> = WithoutClientMeta<WithoutStorag
|
|
|
51
51
|
|
|
52
52
|
export type WithoutSchema<T extends WithOptionalSchema<Payload>> = Omit<T, 'schema'>
|
|
53
53
|
export type WithOptionalSchema<T extends EmptyObject = EmptyObject> = WithoutSchema<T> & Partial<T & SchemaField>
|
|
54
|
+
|
|
55
|
+
export type WithOnlyClientMeta<T extends EmptyObject> = DeepPickStartsWith<T, '$'>
|