@xyo-network/payload-model 3.5.2 → 3.6.0-rc.10

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.
Files changed (90) hide show
  1. package/dist/browser/Error.d.ts +31 -9
  2. package/dist/browser/Error.d.ts.map +1 -1
  3. package/dist/browser/Payload.d.ts +22 -23
  4. package/dist/browser/Payload.d.ts.map +1 -1
  5. package/dist/browser/Query.d.ts +1 -1
  6. package/dist/browser/Schema.d.ts +2 -2
  7. package/dist/browser/StorageMeta/Sequence.d.ts +59 -0
  8. package/dist/browser/StorageMeta/Sequence.d.ts.map +1 -0
  9. package/dist/browser/StorageMeta/SequenceParser.d.ts +23 -0
  10. package/dist/browser/StorageMeta/SequenceParser.d.ts.map +1 -0
  11. package/dist/browser/StorageMeta/StorageMeta.d.ts +22 -0
  12. package/dist/browser/StorageMeta/StorageMeta.d.ts.map +1 -0
  13. package/dist/browser/StorageMeta/index.d.ts +4 -0
  14. package/dist/browser/StorageMeta/index.d.ts.map +1 -0
  15. package/dist/browser/index.d.ts +1 -2
  16. package/dist/browser/index.d.ts.map +1 -1
  17. package/dist/browser/index.mjs +171 -30
  18. package/dist/browser/index.mjs.map +1 -1
  19. package/dist/browser/isPayload.d.ts +10 -10
  20. package/dist/browser/isPayload.d.ts.map +1 -1
  21. package/dist/browser/isPayloadOfSchemaType.d.ts +0 -2
  22. package/dist/browser/isPayloadOfSchemaType.d.ts.map +1 -1
  23. package/dist/neutral/Error.d.ts +31 -9
  24. package/dist/neutral/Error.d.ts.map +1 -1
  25. package/dist/neutral/Payload.d.ts +22 -23
  26. package/dist/neutral/Payload.d.ts.map +1 -1
  27. package/dist/neutral/Query.d.ts +1 -1
  28. package/dist/neutral/Schema.d.ts +2 -2
  29. package/dist/neutral/StorageMeta/Sequence.d.ts +59 -0
  30. package/dist/neutral/StorageMeta/Sequence.d.ts.map +1 -0
  31. package/dist/neutral/StorageMeta/SequenceParser.d.ts +23 -0
  32. package/dist/neutral/StorageMeta/SequenceParser.d.ts.map +1 -0
  33. package/dist/neutral/StorageMeta/StorageMeta.d.ts +22 -0
  34. package/dist/neutral/StorageMeta/StorageMeta.d.ts.map +1 -0
  35. package/dist/neutral/StorageMeta/index.d.ts +4 -0
  36. package/dist/neutral/StorageMeta/index.d.ts.map +1 -0
  37. package/dist/neutral/index.d.ts +1 -2
  38. package/dist/neutral/index.d.ts.map +1 -1
  39. package/dist/neutral/index.mjs +171 -30
  40. package/dist/neutral/index.mjs.map +1 -1
  41. package/dist/neutral/isPayload.d.ts +10 -10
  42. package/dist/neutral/isPayload.d.ts.map +1 -1
  43. package/dist/neutral/isPayloadOfSchemaType.d.ts +0 -2
  44. package/dist/neutral/isPayloadOfSchemaType.d.ts.map +1 -1
  45. package/dist/node/Error.d.ts +31 -9
  46. package/dist/node/Error.d.ts.map +1 -1
  47. package/dist/node/Payload.d.ts +22 -23
  48. package/dist/node/Payload.d.ts.map +1 -1
  49. package/dist/node/Query.d.ts +1 -1
  50. package/dist/node/Schema.d.ts +2 -2
  51. package/dist/node/StorageMeta/Sequence.d.ts +59 -0
  52. package/dist/node/StorageMeta/Sequence.d.ts.map +1 -0
  53. package/dist/node/StorageMeta/SequenceParser.d.ts +23 -0
  54. package/dist/node/StorageMeta/SequenceParser.d.ts.map +1 -0
  55. package/dist/node/StorageMeta/StorageMeta.d.ts +22 -0
  56. package/dist/node/StorageMeta/StorageMeta.d.ts.map +1 -0
  57. package/dist/node/StorageMeta/index.d.ts +4 -0
  58. package/dist/node/StorageMeta/index.d.ts.map +1 -0
  59. package/dist/node/index.d.ts +1 -2
  60. package/dist/node/index.d.ts.map +1 -1
  61. package/dist/node/index.mjs +171 -30
  62. package/dist/node/index.mjs.map +1 -1
  63. package/dist/node/isPayload.d.ts +10 -10
  64. package/dist/node/isPayload.d.ts.map +1 -1
  65. package/dist/node/isPayloadOfSchemaType.d.ts +0 -2
  66. package/dist/node/isPayloadOfSchemaType.d.ts.map +1 -1
  67. package/package.json +11 -8
  68. package/src/Error.ts +0 -1
  69. package/src/Payload.ts +32 -20
  70. package/src/Query.ts +1 -1
  71. package/src/StorageMeta/Sequence.ts +72 -0
  72. package/src/StorageMeta/SequenceParser.ts +125 -0
  73. package/src/StorageMeta/StorageMeta.ts +46 -0
  74. package/src/StorageMeta/index.ts +3 -0
  75. package/src/index.ts +1 -2
  76. package/src/isPayloadOfSchemaType.ts +1 -17
  77. package/dist/browser/Meta.d.ts +0 -8
  78. package/dist/browser/Meta.d.ts.map +0 -1
  79. package/dist/browser/isPayloadWithHash.d.ts +0 -15
  80. package/dist/browser/isPayloadWithHash.d.ts.map +0 -1
  81. package/dist/neutral/Meta.d.ts +0 -8
  82. package/dist/neutral/Meta.d.ts.map +0 -1
  83. package/dist/neutral/isPayloadWithHash.d.ts +0 -15
  84. package/dist/neutral/isPayloadWithHash.d.ts.map +0 -1
  85. package/dist/node/Meta.d.ts +0 -8
  86. package/dist/node/Meta.d.ts.map +0 -1
  87. package/dist/node/isPayloadWithHash.d.ts +0 -15
  88. package/dist/node/isPayloadWithHash.d.ts.map +0 -1
  89. package/src/Meta.ts +0 -20
  90. package/src/isPayloadWithHash.ts +0 -21
@@ -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"
@@ -0,0 +1,3 @@
1
+ export * from './Sequence.ts'
2
+ export * from './SequenceParser.ts'
3
+ export * from './StorageMeta.ts'
package/src/index.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  export * from './Error.ts'
2
2
  export * from './isPayload.ts'
3
3
  export * from './isPayloadOfSchemaType.ts'
4
- export * from './isPayloadWithHash.ts'
5
- export * from './Meta.ts'
6
4
  export * from './Payload.ts'
7
5
  export * from './PayloadFindFilter.ts'
8
6
  export * from './PayloadSet/index.ts'
@@ -10,3 +8,4 @@ export * from './PayloadValidationFunction.ts'
10
8
  export * from './PayloadValueExpression.ts'
11
9
  export * from './Query.ts'
12
10
  export * from './Schema.ts'
11
+ export * from './StorageMeta/index.ts'
@@ -1,18 +1,13 @@
1
1
  import { isAnyPayload } from './isPayload.ts'
2
- import type { WithMeta } from './Meta.ts'
3
2
  import type { Payload, WithSources } from './Payload.ts'
4
3
 
5
4
  export const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {
6
5
  return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema
7
6
  }
8
7
 
9
- export const isPayloadOfSchemaTypeWithMeta = <T extends Payload>(schema: string) => {
10
- return (x?: unknown | null): x is WithMeta<T> => isPayloadOfSchemaType<WithMeta<T>>(schema)(x) && x.$hash !== undefined
11
- }
12
-
13
8
  export const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {
14
9
  return (x?: unknown | null): x is WithSources<T> =>
15
- isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.sources !== undefined && Array.isArray(x.sources)
10
+ isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.$sources !== undefined && Array.isArray(x.$sources)
16
11
  }
17
12
 
18
13
  export const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {
@@ -28,21 +23,10 @@ const TestSchema: TestSchema = 'network.xyo.test'
28
23
  type Test = Payload<{ field: string }, TestSchema>
29
24
 
30
25
  const testPayload: Test = { field: 'test', schema: TestSchema }
31
- const testWithMeta: WithMeta<Test> = { $hash: '1234abcd', $meta: { timestamp: Date.now() }, field: 'test', schema: TestSchema }
32
26
 
33
27
  const testPayloads: Payload[] = [testPayload]
34
- const testMetaPayloads: WithMeta<Payload>[] = [testWithMeta]
35
-
36
- const testType: Test = testWithMeta
37
28
 
38
29
  const isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType(TestSchema))
39
- const isTestFromMeta: Payload[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))
40
- const isTestFromMetaWithMeta: PayloadWithMeta[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))
41
30
 
42
31
  const isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))
43
-
44
- const isTestFromMetaTypedWithMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))
45
-
46
- const isTestWithMeta: WithMeta<Test>[] = testPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))
47
- const isTestWithMetaFromMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))
48
32
  */
@@ -1,8 +0,0 @@
1
- import type { EmptyObject, JsonObject } from '@xylabs/object';
2
- import type { Payload, PayloadMetaFields } from './Payload.ts';
3
- import type { Schema, WithSchema } from './Schema.ts';
4
- export type WithMeta<T extends Payload = Payload, M extends JsonObject | void = void> = PayloadMetaFields<M> & T;
5
- export type WithOptionalMeta<T extends Payload = Payload, M extends JsonObject | void = void> = Partial<WithMeta<T, M>> & Omit<WithMeta<T, M>, '$hash'>;
6
- export type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>;
7
- export declare const unMeta: <T extends WithMeta<Payload>>(payload?: T) => T | undefined;
8
- //# sourceMappingURL=Meta.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Meta.d.ts","sourceRoot":"","sources":["../../src/Meta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE7D,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,CAAC,SAAS,UAAU,GAAG,IAAI,GAAG,IAAI,IAAI,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAChH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,CAAC,SAAS,UAAU,GAAG,IAAI,GAAG,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GACrH,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;AAE/B,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,IAAI,GAAG,WAAW,GAAG,UAAU,GAAG,IAAI,EAAE,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAEvI,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,KAAG,CAAC,GAAG,SAQrE,CAAA"}
@@ -1,15 +0,0 @@
1
- import type { WithMeta } from './Meta.ts';
2
- import type { Payload } from './Payload.ts';
3
- /**
4
- * Return true if the value is a payload with the required meta fields
5
- * @param value The value to check
6
- * @returns True if the value is a payload with the required meta fields
7
- */
8
- export declare const isWithHash: <T extends Payload>(value: T) => value is WithMeta<T>;
9
- /**
10
- * Return true if the value is a payload with the required meta fields
11
- * @param value The value to check
12
- * @returns True if the value is a payload with the required meta fields
13
- */
14
- export declare const isPayloadWithHash: <T extends Payload>(value: unknown) => value is WithMeta<T>;
15
- //# sourceMappingURL=isPayloadWithHash.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isPayloadWithHash.d.ts","sourceRoot":"","sources":["../../src/isPayloadWithHash.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,OAAO,SAAS,CAAC,KAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAE3E,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,OAAO,SAAS,OAAO,KAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAExF,CAAA"}
@@ -1,8 +0,0 @@
1
- import type { EmptyObject, JsonObject } from '@xylabs/object';
2
- import type { Payload, PayloadMetaFields } from './Payload.ts';
3
- import type { Schema, WithSchema } from './Schema.ts';
4
- export type WithMeta<T extends Payload = Payload, M extends JsonObject | void = void> = PayloadMetaFields<M> & T;
5
- export type WithOptionalMeta<T extends Payload = Payload, M extends JsonObject | void = void> = Partial<WithMeta<T, M>> & Omit<WithMeta<T, M>, '$hash'>;
6
- export type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>;
7
- export declare const unMeta: <T extends WithMeta<Payload>>(payload?: T) => T | undefined;
8
- //# sourceMappingURL=Meta.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Meta.d.ts","sourceRoot":"","sources":["../../src/Meta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE7D,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,CAAC,SAAS,UAAU,GAAG,IAAI,GAAG,IAAI,IAAI,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAChH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,CAAC,SAAS,UAAU,GAAG,IAAI,GAAG,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GACrH,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;AAE/B,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,IAAI,GAAG,WAAW,GAAG,UAAU,GAAG,IAAI,EAAE,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAEvI,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,KAAG,CAAC,GAAG,SAQrE,CAAA"}
@@ -1,15 +0,0 @@
1
- import type { WithMeta } from './Meta.ts';
2
- import type { Payload } from './Payload.ts';
3
- /**
4
- * Return true if the value is a payload with the required meta fields
5
- * @param value The value to check
6
- * @returns True if the value is a payload with the required meta fields
7
- */
8
- export declare const isWithHash: <T extends Payload>(value: T) => value is WithMeta<T>;
9
- /**
10
- * Return true if the value is a payload with the required meta fields
11
- * @param value The value to check
12
- * @returns True if the value is a payload with the required meta fields
13
- */
14
- export declare const isPayloadWithHash: <T extends Payload>(value: unknown) => value is WithMeta<T>;
15
- //# sourceMappingURL=isPayloadWithHash.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isPayloadWithHash.d.ts","sourceRoot":"","sources":["../../src/isPayloadWithHash.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,OAAO,SAAS,CAAC,KAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAE3E,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,OAAO,SAAS,OAAO,KAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAExF,CAAA"}
@@ -1,8 +0,0 @@
1
- import type { EmptyObject, JsonObject } from '@xylabs/object';
2
- import type { Payload, PayloadMetaFields } from './Payload.ts';
3
- import type { Schema, WithSchema } from './Schema.ts';
4
- export type WithMeta<T extends Payload = Payload, M extends JsonObject | void = void> = PayloadMetaFields<M> & T;
5
- export type WithOptionalMeta<T extends Payload = Payload, M extends JsonObject | void = void> = Partial<WithMeta<T, M>> & Omit<WithMeta<T, M>, '$hash'>;
6
- export type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>;
7
- export declare const unMeta: <T extends WithMeta<Payload>>(payload?: T) => T | undefined;
8
- //# sourceMappingURL=Meta.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Meta.d.ts","sourceRoot":"","sources":["../../src/Meta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE7D,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,CAAC,SAAS,UAAU,GAAG,IAAI,GAAG,IAAI,IAAI,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAChH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,CAAC,SAAS,UAAU,GAAG,IAAI,GAAG,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GACrH,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;AAE/B,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,IAAI,GAAG,WAAW,GAAG,UAAU,GAAG,IAAI,EAAE,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAEvI,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,KAAG,CAAC,GAAG,SAQrE,CAAA"}
@@ -1,15 +0,0 @@
1
- import type { WithMeta } from './Meta.ts';
2
- import type { Payload } from './Payload.ts';
3
- /**
4
- * Return true if the value is a payload with the required meta fields
5
- * @param value The value to check
6
- * @returns True if the value is a payload with the required meta fields
7
- */
8
- export declare const isWithHash: <T extends Payload>(value: T) => value is WithMeta<T>;
9
- /**
10
- * Return true if the value is a payload with the required meta fields
11
- * @param value The value to check
12
- * @returns True if the value is a payload with the required meta fields
13
- */
14
- export declare const isPayloadWithHash: <T extends Payload>(value: unknown) => value is WithMeta<T>;
15
- //# sourceMappingURL=isPayloadWithHash.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isPayloadWithHash.d.ts","sourceRoot":"","sources":["../../src/isPayloadWithHash.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,OAAO,SAAS,CAAC,KAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAE3E,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,OAAO,SAAS,OAAO,KAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAExF,CAAA"}
package/src/Meta.ts DELETED
@@ -1,20 +0,0 @@
1
- import type { EmptyObject, JsonObject } from '@xylabs/object'
2
-
3
- import type { Payload, PayloadMetaFields } from './Payload.ts'
4
- import type { Schema, WithSchema } from './Schema.ts'
5
-
6
- export type WithMeta<T extends Payload = Payload, M extends JsonObject | void = void> = PayloadMetaFields<M> & T
7
- export type WithOptionalMeta<T extends Payload = Payload, M extends JsonObject | void = void> = Partial<WithMeta<T, M>> &
8
- Omit<WithMeta<T, M>, '$hash'>
9
-
10
- export type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>
11
-
12
- export const unMeta = <T extends WithMeta<Payload>>(payload?: T): T | undefined => {
13
- if (payload) {
14
- const {
15
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
- $meta, $hash, ...result
17
- } = payload
18
- return result as T
19
- }
20
- }
@@ -1,21 +0,0 @@
1
- import { isAnyPayload } from './isPayload.ts'
2
- import type { WithMeta } from './Meta.ts'
3
- import type { Payload } from './Payload.ts'
4
-
5
- /**
6
- * Return true if the value is a payload with the required meta fields
7
- * @param value The value to check
8
- * @returns True if the value is a payload with the required meta fields
9
- */
10
- export const isWithHash = <T extends Payload>(value: T): value is WithMeta<T> => {
11
- return typeof (value as WithMeta<T>)?.$hash === 'string'
12
- }
13
-
14
- /**
15
- * Return true if the value is a payload with the required meta fields
16
- * @param value The value to check
17
- * @returns True if the value is a payload with the required meta fields
18
- */
19
- export const isPayloadWithHash = <T extends Payload>(value: unknown): value is WithMeta<T> => {
20
- return isAnyPayload(value) && isWithHash(value)
21
- }