@xyo-network/payload-model 3.6.0-rc.1 → 3.6.0-rc.11
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 +31 -9
- package/dist/browser/Error.d.ts.map +1 -1
- package/dist/browser/Payload.d.ts +23 -17
- package/dist/browser/Payload.d.ts.map +1 -1
- package/dist/browser/Query.d.ts +1 -1
- package/dist/browser/Schema.d.ts +2 -2
- package/dist/browser/StorageMeta/Sequence.d.ts +61 -0
- package/dist/browser/StorageMeta/Sequence.d.ts.map +1 -0
- package/dist/browser/StorageMeta/SequenceParser.d.ts +23 -0
- package/dist/browser/StorageMeta/SequenceParser.d.ts.map +1 -0
- package/dist/browser/StorageMeta/StorageMeta.d.ts +22 -0
- package/dist/browser/StorageMeta/StorageMeta.d.ts.map +1 -0
- package/dist/browser/StorageMeta/index.d.ts +4 -0
- package/dist/browser/StorageMeta/index.d.ts.map +1 -0
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.mjs +170 -1
- package/dist/browser/index.mjs.map +1 -1
- package/dist/browser/isPayload.d.ts +10 -10
- package/dist/browser/isPayload.d.ts.map +1 -1
- package/dist/neutral/Error.d.ts +31 -9
- package/dist/neutral/Error.d.ts.map +1 -1
- package/dist/neutral/Payload.d.ts +23 -17
- package/dist/neutral/Payload.d.ts.map +1 -1
- package/dist/neutral/Query.d.ts +1 -1
- package/dist/neutral/Schema.d.ts +2 -2
- package/dist/neutral/StorageMeta/Sequence.d.ts +61 -0
- package/dist/neutral/StorageMeta/Sequence.d.ts.map +1 -0
- package/dist/neutral/StorageMeta/SequenceParser.d.ts +23 -0
- package/dist/neutral/StorageMeta/SequenceParser.d.ts.map +1 -0
- package/dist/neutral/StorageMeta/StorageMeta.d.ts +22 -0
- package/dist/neutral/StorageMeta/StorageMeta.d.ts.map +1 -0
- package/dist/neutral/StorageMeta/index.d.ts +4 -0
- package/dist/neutral/StorageMeta/index.d.ts.map +1 -0
- package/dist/neutral/index.d.ts +1 -0
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +170 -1
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/isPayload.d.ts +10 -10
- package/dist/neutral/isPayload.d.ts.map +1 -1
- package/dist/node/Error.d.ts +31 -9
- package/dist/node/Error.d.ts.map +1 -1
- package/dist/node/Payload.d.ts +23 -17
- package/dist/node/Payload.d.ts.map +1 -1
- package/dist/node/Query.d.ts +1 -1
- package/dist/node/Schema.d.ts +2 -2
- package/dist/node/StorageMeta/Sequence.d.ts +61 -0
- package/dist/node/StorageMeta/Sequence.d.ts.map +1 -0
- package/dist/node/StorageMeta/SequenceParser.d.ts +23 -0
- package/dist/node/StorageMeta/SequenceParser.d.ts.map +1 -0
- package/dist/node/StorageMeta/StorageMeta.d.ts +22 -0
- package/dist/node/StorageMeta/StorageMeta.d.ts.map +1 -0
- package/dist/node/StorageMeta/index.d.ts +4 -0
- package/dist/node/StorageMeta/index.d.ts.map +1 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.mjs +170 -1
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/isPayload.d.ts +10 -10
- package/dist/node/isPayload.d.ts.map +1 -1
- package/package.json +8 -6
- package/src/Error.ts +0 -1
- package/src/Payload.ts +34 -14
- package/src/Query.ts +1 -1
- package/src/StorageMeta/Sequence.ts +72 -0
- package/src/StorageMeta/SequenceParser.ts +125 -0
- package/src/StorageMeta/StorageMeta.ts +46 -0
- package/src/StorageMeta/index.ts +3 -0
- package/src/index.ts +1 -0
- package/src/isPayloadOfSchemaType.ts +1 -1
package/src/Error.ts
CHANGED
package/src/Payload.ts
CHANGED
|
@@ -1,35 +1,55 @@
|
|
|
1
1
|
import type { Hash } from '@xylabs/hex'
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
DeepOmitStartsWith, DeepPickStartsWith, DeepRestrictToStringKeys, EmptyObject,
|
|
4
|
+
} from '@xylabs/object'
|
|
3
5
|
|
|
4
6
|
import type { Schema, WithSchema } from './Schema.ts'
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
schema: Schema
|
|
8
|
+
export interface SchemaField<T extends Schema = Schema> {
|
|
9
|
+
schema: T
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
/** Additional fields for a payload */
|
|
13
|
+
export interface PayloadFields extends SchemaField {}
|
|
14
|
+
|
|
15
|
+
export type WithPayload<T extends EmptyObject | void = void> =
|
|
16
|
+
DeepRestrictToStringKeys<WithoutMeta<WithSchema<T extends EmptyObject ? PayloadFields & T : PayloadFields>>>
|
|
12
17
|
|
|
13
18
|
/** Base Type for Payloads */
|
|
14
19
|
export type Payload<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> =
|
|
15
20
|
T extends WithSchema ?
|
|
16
21
|
S extends Schema ?
|
|
17
22
|
/* T (w/Schema) & S provided */
|
|
18
|
-
WithPayload<Omit<T, 'schema'> & { schema: S }
|
|
23
|
+
WithPayload<Omit<T, 'schema'> & { schema: S }>
|
|
19
24
|
: /* Only T (w/Schema) provided */ WithPayload<T>
|
|
20
25
|
: T extends object ?
|
|
21
26
|
S extends Schema ?
|
|
22
27
|
/* T (w/o Schema) & S provided */
|
|
23
|
-
WithPayload<T & { schema: S }
|
|
24
|
-
: /* Only T (w/o Schema) provided */ WithPayload<T &
|
|
28
|
+
WithPayload<T & { schema: S }>
|
|
29
|
+
: /* Only T (w/o Schema) provided */ WithPayload<T & PayloadFields>
|
|
25
30
|
: /* Either just S or neither S or T provided */
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
WithPayload<{
|
|
32
|
+
schema: S extends Schema ? S : Schema
|
|
33
|
+
}>
|
|
34
|
+
|
|
35
|
+
export type OverridablePayload<T extends Payload> = WithoutMeta<Omit<T, 'schema'> & PayloadFields>
|
|
29
36
|
|
|
30
|
-
export type
|
|
37
|
+
export type SourcesMetaField = { $sources: Hash[] }
|
|
38
|
+
|
|
39
|
+
export type WithSources<T extends EmptyObject> = T & SourcesMetaField
|
|
40
|
+
export type WithOptionalSources<T extends EmptyObject> = (T & SourcesMetaField) | T
|
|
31
41
|
|
|
32
|
-
export type WithSources<T extends EmptyObject> = T & { sources?: Hash[] }
|
|
33
42
|
export type PayloadWithSources<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithSources<Payload<T, S>>
|
|
43
|
+
export type PayloadWithOptionalSources<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithOptionalSources<Payload<T, S>>
|
|
44
|
+
|
|
45
|
+
export type WithAnySchema<T extends Payload> = OverridablePayload<T>
|
|
46
|
+
|
|
47
|
+
export type WithoutClientMeta<T extends EmptyObject> = DeepOmitStartsWith<T, '$'>
|
|
48
|
+
export type WithoutStorageMeta<T extends EmptyObject> = DeepOmitStartsWith<T, '_'>
|
|
49
|
+
export type WithoutPrivateStorageMeta<T extends EmptyObject> = DeepOmitStartsWith<T, '__'>
|
|
50
|
+
export type WithoutMeta<T extends EmptyObject> = WithoutClientMeta<WithoutStorageMeta<T>>
|
|
51
|
+
|
|
52
|
+
export type WithoutSchema<T extends WithOptionalSchema<Payload>> = Omit<T, 'schema'>
|
|
53
|
+
export type WithOptionalSchema<T extends EmptyObject = EmptyObject> = WithoutSchema<T> & Partial<T & SchemaField>
|
|
34
54
|
|
|
35
|
-
export type
|
|
55
|
+
export type WithOnlyClientMeta<T extends EmptyObject> = DeepPickStartsWith<T, '$'>
|
package/src/Query.ts
CHANGED
|
@@ -22,7 +22,7 @@ export type Query<T extends void | EmptyObject | WithSchema = void, S extends Sc
|
|
|
22
22
|
T extends void ? QueryFields : T & QueryFields,
|
|
23
23
|
S extends void ?
|
|
24
24
|
T extends WithSchema ? T['schema']
|
|
25
|
-
: T extends void ?
|
|
25
|
+
: T extends void ? Schema
|
|
26
26
|
: void
|
|
27
27
|
: S
|
|
28
28
|
>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Address, Hex } from '@xylabs/hex'
|
|
2
|
+
import { isHex } from '@xylabs/hex'
|
|
3
|
+
|
|
4
|
+
// we use Exclude to intentionally make the type not equal to string
|
|
5
|
+
export type LocalSequence = Hex & Exclude<string, 'reserved-local-sequence-value'>
|
|
6
|
+
export type QualifiedSequence = Hex & Exclude<string, 'reserved-qualified-sequence-value'>
|
|
7
|
+
export type Sequence = LocalSequence | QualifiedSequence
|
|
8
|
+
|
|
9
|
+
export type Epoch = Hex & Exclude<string, 'reserved-epoch-sequence-value'>
|
|
10
|
+
|
|
11
|
+
export const isEpoch = (value: unknown): value is Epoch => {
|
|
12
|
+
return isHex(value) && (value as string).length === SequenceConstants.epochBytes * 2
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type Nonce = Hex & Exclude<string, 'reserved-nonce-sequence-value'>
|
|
16
|
+
|
|
17
|
+
export const isNonce = (value: unknown): value is Epoch => {
|
|
18
|
+
return isHex(value) && (value as string).length === SequenceConstants.nonceBytes * 2
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const isLocalSequence = (value: unknown): value is Sequence => {
|
|
22
|
+
return isHex(value) && (value as string).length === SequenceConstants.localSequenceBytes * 2
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const isQualifiedSequence = (value: unknown): value is Sequence => {
|
|
26
|
+
return isHex(value) && (value as string).length === SequenceConstants.qualifiedSequenceBytes * 2
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const isSequence = (value: unknown): value is Sequence => {
|
|
30
|
+
return isLocalSequence(value) || isQualifiedSequence(value)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const SequenceComponentLengths = {
|
|
34
|
+
epochBytes: 8,
|
|
35
|
+
nonceBytes: 8,
|
|
36
|
+
addressBytes: 20,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const SequenceComponentMinMax = {
|
|
40
|
+
minEpoch: '0'.repeat(SequenceComponentLengths.epochBytes * 2) as Epoch,
|
|
41
|
+
maxEpoch: 'f'.repeat(SequenceComponentLengths.epochBytes * 2) as Epoch,
|
|
42
|
+
minNonce: '0'.repeat(SequenceComponentLengths.nonceBytes * 2) as Nonce,
|
|
43
|
+
maxNonce: 'f'.repeat(SequenceComponentLengths.nonceBytes * 2) as Nonce,
|
|
44
|
+
minAddress: '0'.repeat(SequenceComponentLengths.addressBytes * 2) as Address,
|
|
45
|
+
maxAddress: 'f'.repeat(SequenceComponentLengths.addressBytes * 2) as Address,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const LocalSequenceConstants = {
|
|
49
|
+
...SequenceComponentLengths,
|
|
50
|
+
...SequenceComponentMinMax,
|
|
51
|
+
localSequenceBytes: SequenceComponentLengths.epochBytes + SequenceComponentLengths.nonceBytes,
|
|
52
|
+
minLocalSequence: SequenceComponentMinMax.minEpoch + SequenceComponentMinMax.minNonce as LocalSequence,
|
|
53
|
+
maxLocalSequence: SequenceComponentMinMax.maxEpoch + SequenceComponentMinMax.maxNonce as LocalSequence,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const QualifiedSequenceConstants = {
|
|
57
|
+
qualifiedSequenceBytes: LocalSequenceConstants.localSequenceBytes + SequenceComponentLengths.addressBytes,
|
|
58
|
+
minQualifiedSequence: LocalSequenceConstants.minLocalSequence + SequenceComponentMinMax.minAddress as QualifiedSequence,
|
|
59
|
+
maxQualifiedSequence: LocalSequenceConstants.maxLocalSequence + SequenceComponentMinMax.maxAddress as QualifiedSequence,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const SequenceConstants = {
|
|
63
|
+
...LocalSequenceConstants,
|
|
64
|
+
...QualifiedSequenceConstants,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// "11111111111111112222222222222222" is and example of a local sequence string
|
|
68
|
+
|
|
69
|
+
// "111111111111111122222222222222223333333333333333333333333333333333333333" is and example of a local sequence string
|
|
70
|
+
// epoch = "1111111111111111"
|
|
71
|
+
// nonce = "2222222222222222"
|
|
72
|
+
// address = "3333333333333333333333333333333333333333"
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { toUint8Array } from '@xylabs/arraybuffer'
|
|
2
|
+
import { assertEx } from '@xylabs/assert'
|
|
3
|
+
import {
|
|
4
|
+
type Address,
|
|
5
|
+
type Hash, type Hex,
|
|
6
|
+
isAddress,
|
|
7
|
+
toHex,
|
|
8
|
+
} from '@xylabs/hex'
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
Epoch, LocalSequence, Nonce, QualifiedSequence,
|
|
12
|
+
Sequence,
|
|
13
|
+
} from './Sequence.ts'
|
|
14
|
+
import {
|
|
15
|
+
isQualifiedSequence, isSequence, SequenceConstants,
|
|
16
|
+
} from './Sequence.ts'
|
|
17
|
+
|
|
18
|
+
export class SequenceParser {
|
|
19
|
+
protected static privateConstructorKey = Date.now().toString()
|
|
20
|
+
|
|
21
|
+
private readonly data: Readonly<Uint8Array>
|
|
22
|
+
|
|
23
|
+
protected constructor(privateConstructorKey: string, hex: Hex) {
|
|
24
|
+
assertEx(SequenceParser.privateConstructorKey === privateConstructorKey, () => 'Use create function instead of constructor')
|
|
25
|
+
const paddedHex = toHex(hex, {
|
|
26
|
+
prefix: false,
|
|
27
|
+
bitLength: (hex.length <= SequenceConstants.localSequenceBytes * 2)
|
|
28
|
+
? SequenceConstants.localSequenceBytes * 8
|
|
29
|
+
: SequenceConstants.qualifiedSequenceBytes * 8,
|
|
30
|
+
})
|
|
31
|
+
this.data = toUint8Array(paddedHex)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get address(): Address {
|
|
35
|
+
const start = SequenceConstants.localSequenceBytes
|
|
36
|
+
const end = SequenceConstants.qualifiedSequenceBytes
|
|
37
|
+
return toHex(this.data.slice(start, end).buffer, { prefix: false })
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get epoch(): Epoch {
|
|
41
|
+
const start = 0
|
|
42
|
+
const end = SequenceConstants.epochBytes
|
|
43
|
+
return toHex(this.data.slice(start, end).buffer, { prefix: false })
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get localSequence(): LocalSequence {
|
|
47
|
+
const start = 0
|
|
48
|
+
const end = SequenceConstants.localSequenceBytes
|
|
49
|
+
return toHex(this.data.slice(start, end).buffer, { prefix: false })
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get nonce(): Nonce {
|
|
53
|
+
const start = SequenceConstants.epochBytes
|
|
54
|
+
const end = SequenceConstants.localSequenceBytes
|
|
55
|
+
return toHex(this.data.slice(start, end).buffer, { prefix: false })
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get qualifiedSequence(): QualifiedSequence {
|
|
59
|
+
const start = 0
|
|
60
|
+
const end = SequenceConstants.qualifiedSequenceBytes
|
|
61
|
+
return toHex(this.data.slice(start, end).buffer, { prefix: false })
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static from(sequence: Sequence, address?: Address): SequenceParser
|
|
65
|
+
static from(timestamp: Hex, hash: Hash, address?: Address): SequenceParser
|
|
66
|
+
static from(timestamp: Hex, hash: Hex, address?: Address): SequenceParser
|
|
67
|
+
static from(timestamp: Hex, nonce: Nonce, address?: Address): SequenceParser
|
|
68
|
+
static from(timestamp: number, hash: Hash, address?: Address): SequenceParser
|
|
69
|
+
static from(timestamp: number, hash: Hex, address?: Address): SequenceParser
|
|
70
|
+
static from(timestamp: number, nonce: Nonce, address?: Address): SequenceParser
|
|
71
|
+
static from(timestampOrSequence: Sequence | Hex | number, nonceOrAddress: Hash | Nonce, address?: Address): SequenceParser {
|
|
72
|
+
if (isSequence(timestampOrSequence)) {
|
|
73
|
+
if (nonceOrAddress) {
|
|
74
|
+
assertEx(!isQualifiedSequence(timestampOrSequence), () => 'Providing both a qualified sequence and a address is not allowed')
|
|
75
|
+
assertEx(isAddress(nonceOrAddress), () => 'Invalid address provided')
|
|
76
|
+
return new this(SequenceParser.privateConstructorKey, (timestampOrSequence + address) as Hex)
|
|
77
|
+
}
|
|
78
|
+
return new this(SequenceParser.privateConstructorKey, timestampOrSequence)
|
|
79
|
+
}
|
|
80
|
+
const epoch = SequenceParser.toEpoch(timestampOrSequence)
|
|
81
|
+
const nonce = SequenceParser.toNonce(nonceOrAddress)
|
|
82
|
+
const addressHex: Hex = address ? toHex(address, { bitLength: SequenceConstants.addressBytes * 8 }) : SequenceConstants.minAddress
|
|
83
|
+
const hexString = (epoch + nonce + addressHex) as Hex
|
|
84
|
+
assertEx(isSequence(hexString), () => `Invalid sequence [${hexString}] [${epoch}, ${nonce}, ${addressHex}]`)
|
|
85
|
+
return new this(SequenceParser.privateConstructorKey, hexString)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static parse(value: Hex | string | ArrayBufferLike): SequenceParser {
|
|
89
|
+
const hex = toHex(value)
|
|
90
|
+
if (isSequence(hex)) {
|
|
91
|
+
return new this(SequenceParser.privateConstructorKey, hex)
|
|
92
|
+
}
|
|
93
|
+
throw new Error(`Invalid sequence [${value}]`)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// can convert a short number/hex to an epoch (treats it as the whole value) or extract an epoch from a sequence
|
|
97
|
+
static toEpoch(value: number | Hex | Epoch): Epoch {
|
|
98
|
+
assertEx(
|
|
99
|
+
typeof value !== 'number' || Number.isInteger(value),
|
|
100
|
+
() => 'Value must be in integer',
|
|
101
|
+
)
|
|
102
|
+
const hex = toHex(value, { prefix: false })
|
|
103
|
+
if (hex.length <= SequenceConstants.epochBytes * 2) {
|
|
104
|
+
return toHex(value, { prefix: false, bitLength: SequenceConstants.epochBytes * 8 }) as Epoch
|
|
105
|
+
}
|
|
106
|
+
if (isSequence(hex)) {
|
|
107
|
+
return hex.slice(0, SequenceConstants.epochBytes * 2) as Epoch
|
|
108
|
+
}
|
|
109
|
+
throw new Error(`Value could not be converted to epoch [${hex}]`)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// can convert a short number/hex to a nonce (treats it as the whole value) or extract an nonce from a sequence
|
|
113
|
+
static toNonce(value: Hash | Hex): Nonce {
|
|
114
|
+
assertEx(
|
|
115
|
+
typeof value !== 'number' || Number.isInteger(value),
|
|
116
|
+
() => 'Value must be in integer',
|
|
117
|
+
)
|
|
118
|
+
const hex = toHex(value, { prefix: false })
|
|
119
|
+
if (isSequence(hex)) {
|
|
120
|
+
return hex.slice(SequenceConstants.epochBytes * 2, SequenceConstants.localSequenceBytes * 2) as Nonce
|
|
121
|
+
}
|
|
122
|
+
const hash = toHex((hex as string), { prefix: false, bitLength: SequenceConstants.nonceBytes * 8 })
|
|
123
|
+
return hash.slice(-SequenceConstants.nonceBytes * 2) as Nonce
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type Hash, isHash } from '@xylabs/hex'
|
|
2
|
+
|
|
3
|
+
import type { Payload } from '../Payload.ts'
|
|
4
|
+
import type { Sequence } from './Sequence.ts'
|
|
5
|
+
|
|
6
|
+
export interface SequenceMeta {
|
|
7
|
+
_sequence: Sequence
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type WithPartialSequenceMeta<T extends Payload = Payload> = Partial<WithSequenceMeta<T>>
|
|
11
|
+
|
|
12
|
+
export type WithSequenceMeta<T extends Payload = Payload> = T & SequenceMeta
|
|
13
|
+
|
|
14
|
+
export interface HashMeta {
|
|
15
|
+
_dataHash: Hash
|
|
16
|
+
_hash: Hash
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type WithPartialHashMeta<T extends Payload = Payload> = Partial<WithHashMeta<T>>
|
|
20
|
+
|
|
21
|
+
export type WithHashMeta<T extends Payload = Payload> = T & HashMeta
|
|
22
|
+
|
|
23
|
+
export interface StorageMeta extends SequenceMeta, HashMeta {}
|
|
24
|
+
|
|
25
|
+
export type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>
|
|
26
|
+
|
|
27
|
+
export type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta
|
|
28
|
+
|
|
29
|
+
export const isSequenceMeta = (value: unknown): value is SequenceMeta => {
|
|
30
|
+
return (value as WithSequenceMeta)?._sequence !== undefined
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const isHashMeta = (value: unknown): value is HashMeta => {
|
|
34
|
+
return isHash((value as WithHashMeta)?._hash) && isHash((value as WithHashMeta)?._dataHash)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const isStorageMeta = (value: unknown): value is StorageMeta => {
|
|
38
|
+
return isSequenceMeta(value) && isHashMeta(value)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// "00005a7f354762f3ac1bc5ddc6cfd08d14" is and example of a local sequence string
|
|
42
|
+
|
|
43
|
+
// "00005a7f354762f3ac1bc5ddc6cfd08d14a123456789abcdef0123" is and example of a local sequence string
|
|
44
|
+
// epoch = "00005a7f354762f3ac"
|
|
45
|
+
// nonce = "1bc5ddc6cfd08d14"
|
|
46
|
+
// address = "a123456789abcdef0123"
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ export const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {
|
|
|
7
7
|
|
|
8
8
|
export const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {
|
|
9
9
|
return (x?: unknown | null): x is WithSources<T> =>
|
|
10
|
-
isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x
|
|
10
|
+
isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.$sources !== undefined && Array.isArray(x.$sources)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {
|