@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.
- package/dist/browser/Error.d.ts +31 -9
- package/dist/browser/Error.d.ts.map +1 -1
- package/dist/browser/Payload.d.ts +22 -23
- 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 +59 -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 -2
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.mjs +171 -30
- 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/browser/isPayloadOfSchemaType.d.ts +0 -2
- package/dist/browser/isPayloadOfSchemaType.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 +22 -23
- 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 +59 -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 -2
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +171 -30
- 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/neutral/isPayloadOfSchemaType.d.ts +0 -2
- package/dist/neutral/isPayloadOfSchemaType.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 +22 -23
- 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 +59 -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 -2
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.mjs +171 -30
- 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/dist/node/isPayloadOfSchemaType.d.ts +0 -2
- package/dist/node/isPayloadOfSchemaType.d.ts.map +1 -1
- package/package.json +11 -8
- package/src/Error.ts +0 -1
- package/src/Payload.ts +32 -20
- 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 -2
- package/src/isPayloadOfSchemaType.ts +1 -17
- package/dist/browser/Meta.d.ts +0 -8
- package/dist/browser/Meta.d.ts.map +0 -1
- package/dist/browser/isPayloadWithHash.d.ts +0 -15
- package/dist/browser/isPayloadWithHash.d.ts.map +0 -1
- package/dist/neutral/Meta.d.ts +0 -8
- package/dist/neutral/Meta.d.ts.map +0 -1
- package/dist/neutral/isPayloadWithHash.d.ts +0 -15
- package/dist/neutral/isPayloadWithHash.d.ts.map +0 -1
- package/dist/node/Meta.d.ts +0 -8
- package/dist/node/Meta.d.ts.map +0 -1
- package/dist/node/isPayloadWithHash.d.ts +0 -15
- package/dist/node/isPayloadWithHash.d.ts.map +0 -1
- package/src/Meta.ts +0 -20
- package/src/isPayloadWithHash.ts +0 -21
package/dist/node/index.mjs
CHANGED
|
@@ -19,11 +19,8 @@ var asPayload = (schema) => AsObjectFactory.create((value) => isPayload(schema)(
|
|
|
19
19
|
var isPayloadOfSchemaType = (schema) => {
|
|
20
20
|
return (x) => isAnyPayload(x) && x?.schema === schema;
|
|
21
21
|
};
|
|
22
|
-
var isPayloadOfSchemaTypeWithMeta = (schema) => {
|
|
23
|
-
return (x) => isPayloadOfSchemaType(schema)(x) && x.$hash !== void 0;
|
|
24
|
-
};
|
|
25
22
|
var isPayloadOfSchemaTypeWithSources = (schema) => {
|
|
26
|
-
return (x) => isPayloadOfSchemaType(schema)(x) && x
|
|
23
|
+
return (x) => isPayloadOfSchemaType(schema)(x) && x.$sources !== void 0 && Array.isArray(x.$sources);
|
|
27
24
|
};
|
|
28
25
|
var notPayloadOfSchemaType = (schema) => {
|
|
29
26
|
return (x) => !isAnyPayload(x) || x?.schema !== schema;
|
|
@@ -33,27 +30,6 @@ var notPayloadOfSchemaType = (schema) => {
|
|
|
33
30
|
var ModuleErrorSchema = "network.xyo.error.module";
|
|
34
31
|
var isModuleError = isPayloadOfSchemaType(ModuleErrorSchema);
|
|
35
32
|
|
|
36
|
-
// src/isPayloadWithHash.ts
|
|
37
|
-
var isWithHash = (value) => {
|
|
38
|
-
return typeof value?.$hash === "string";
|
|
39
|
-
};
|
|
40
|
-
var isPayloadWithHash = (value) => {
|
|
41
|
-
return isAnyPayload(value) && isWithHash(value);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// src/Meta.ts
|
|
45
|
-
var unMeta = (payload) => {
|
|
46
|
-
if (payload) {
|
|
47
|
-
const {
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
49
|
-
$meta,
|
|
50
|
-
$hash,
|
|
51
|
-
...result
|
|
52
|
-
} = payload;
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
33
|
// src/PayloadSet/PayloadSetSchema.ts
|
|
58
34
|
var PayloadSetSchema = "network.xyo.payload.set";
|
|
59
35
|
|
|
@@ -64,23 +40,188 @@ var isSchema = (value) => {
|
|
|
64
40
|
return typeof value === "string";
|
|
65
41
|
};
|
|
66
42
|
var asSchema = AsTypeFactory.create(isSchema);
|
|
43
|
+
|
|
44
|
+
// src/StorageMeta/Sequence.ts
|
|
45
|
+
import { isHex } from "@xylabs/hex";
|
|
46
|
+
var isEpoch = (value) => {
|
|
47
|
+
return isHex(value) && value.length === SequenceConstants.epochBytes * 2;
|
|
48
|
+
};
|
|
49
|
+
var isNonce = (value) => {
|
|
50
|
+
return isHex(value) && value.length === SequenceConstants.nonceBytes * 2;
|
|
51
|
+
};
|
|
52
|
+
var isLocalSequence = (value) => {
|
|
53
|
+
return isHex(value) && value.length === SequenceConstants.localSequenceBytes * 2;
|
|
54
|
+
};
|
|
55
|
+
var isQualifiedSequence = (value) => {
|
|
56
|
+
return isHex(value) && value.length === SequenceConstants.qualifiedSequenceBytes * 2;
|
|
57
|
+
};
|
|
58
|
+
var isSequence = (value) => {
|
|
59
|
+
return isLocalSequence(value) || isQualifiedSequence(value);
|
|
60
|
+
};
|
|
61
|
+
var SequenceComponentLengths = {
|
|
62
|
+
epochBytes: 8,
|
|
63
|
+
nonceBytes: 8,
|
|
64
|
+
addressBytes: 20
|
|
65
|
+
};
|
|
66
|
+
var SequenceComponentMinMax = {
|
|
67
|
+
minEpoch: "0".repeat(SequenceComponentLengths.epochBytes * 2),
|
|
68
|
+
maxEpoch: "f".repeat(SequenceComponentLengths.epochBytes * 2),
|
|
69
|
+
minNonce: "0".repeat(SequenceComponentLengths.nonceBytes * 2),
|
|
70
|
+
maxNonce: "f".repeat(SequenceComponentLengths.nonceBytes * 2),
|
|
71
|
+
minAddress: "0".repeat(SequenceComponentLengths.addressBytes * 2),
|
|
72
|
+
maxAddress: "f".repeat(SequenceComponentLengths.addressBytes * 2)
|
|
73
|
+
};
|
|
74
|
+
var LocalSequenceConstants = {
|
|
75
|
+
...SequenceComponentLengths,
|
|
76
|
+
...SequenceComponentMinMax,
|
|
77
|
+
localSequenceBytes: SequenceComponentLengths.epochBytes + SequenceComponentLengths.nonceBytes,
|
|
78
|
+
minLocalSequence: SequenceComponentMinMax.minEpoch + SequenceComponentMinMax.minNonce,
|
|
79
|
+
maxLocalSequence: SequenceComponentMinMax.maxEpoch + SequenceComponentMinMax.maxNonce
|
|
80
|
+
};
|
|
81
|
+
var QualifiedSequenceConstants = {
|
|
82
|
+
qualifiedSequenceBytes: LocalSequenceConstants.localSequenceBytes + SequenceComponentLengths.addressBytes,
|
|
83
|
+
minLocalSequence: LocalSequenceConstants.minLocalSequence + SequenceComponentMinMax.minAddress,
|
|
84
|
+
maxLocalSequence: LocalSequenceConstants.maxLocalSequence + SequenceComponentMinMax.maxAddress
|
|
85
|
+
};
|
|
86
|
+
var SequenceConstants = {
|
|
87
|
+
...LocalSequenceConstants,
|
|
88
|
+
...QualifiedSequenceConstants
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// src/StorageMeta/SequenceParser.ts
|
|
92
|
+
import { toUint8Array } from "@xylabs/arraybuffer";
|
|
93
|
+
import { assertEx } from "@xylabs/assert";
|
|
94
|
+
import {
|
|
95
|
+
isAddress,
|
|
96
|
+
toHex
|
|
97
|
+
} from "@xylabs/hex";
|
|
98
|
+
var SequenceParser = class _SequenceParser {
|
|
99
|
+
static privateConstructorKey = Date.now().toString();
|
|
100
|
+
data;
|
|
101
|
+
constructor(privateConstructorKey, hex) {
|
|
102
|
+
assertEx(_SequenceParser.privateConstructorKey === privateConstructorKey, () => "Use create function instead of constructor");
|
|
103
|
+
const paddedHex = toHex(hex, {
|
|
104
|
+
prefix: false,
|
|
105
|
+
bitLength: hex.length <= SequenceConstants.localSequenceBytes * 2 ? SequenceConstants.localSequenceBytes * 8 : SequenceConstants.qualifiedSequenceBytes * 8
|
|
106
|
+
});
|
|
107
|
+
this.data = toUint8Array(paddedHex);
|
|
108
|
+
}
|
|
109
|
+
get address() {
|
|
110
|
+
const start = SequenceConstants.localSequenceBytes;
|
|
111
|
+
const end = SequenceConstants.qualifiedSequenceBytes;
|
|
112
|
+
return toHex(this.data.slice(start, end).buffer, { prefix: false });
|
|
113
|
+
}
|
|
114
|
+
get epoch() {
|
|
115
|
+
const start = 0;
|
|
116
|
+
const end = SequenceConstants.epochBytes;
|
|
117
|
+
return toHex(this.data.slice(start, end).buffer, { prefix: false });
|
|
118
|
+
}
|
|
119
|
+
get localSequence() {
|
|
120
|
+
const start = 0;
|
|
121
|
+
const end = SequenceConstants.localSequenceBytes;
|
|
122
|
+
return toHex(this.data.slice(start, end).buffer, { prefix: false });
|
|
123
|
+
}
|
|
124
|
+
get nonce() {
|
|
125
|
+
const start = SequenceConstants.epochBytes;
|
|
126
|
+
const end = SequenceConstants.localSequenceBytes;
|
|
127
|
+
return toHex(this.data.slice(start, end).buffer, { prefix: false });
|
|
128
|
+
}
|
|
129
|
+
get qualifiedSequence() {
|
|
130
|
+
const start = 0;
|
|
131
|
+
const end = SequenceConstants.qualifiedSequenceBytes;
|
|
132
|
+
return toHex(this.data.slice(start, end).buffer, { prefix: false });
|
|
133
|
+
}
|
|
134
|
+
static from(timestampOrSequence, nonceOrAddress, address) {
|
|
135
|
+
if (isSequence(timestampOrSequence)) {
|
|
136
|
+
if (nonceOrAddress) {
|
|
137
|
+
assertEx(!isQualifiedSequence(timestampOrSequence), () => "Providing both a qualified sequence and a address is not allowed");
|
|
138
|
+
assertEx(isAddress(nonceOrAddress), () => "Invalid address provided");
|
|
139
|
+
return new this(_SequenceParser.privateConstructorKey, timestampOrSequence + address);
|
|
140
|
+
}
|
|
141
|
+
return new this(_SequenceParser.privateConstructorKey, timestampOrSequence);
|
|
142
|
+
}
|
|
143
|
+
const epoch = _SequenceParser.toEpoch(timestampOrSequence);
|
|
144
|
+
const nonce = _SequenceParser.toNonce(nonceOrAddress);
|
|
145
|
+
const addressHex = address ? toHex(address, { bitLength: SequenceConstants.addressBytes * 8 }) : SequenceConstants.minAddress;
|
|
146
|
+
const hexString = epoch + nonce + addressHex;
|
|
147
|
+
assertEx(isSequence(hexString), () => `Invalid sequence [${hexString}] [${epoch}, ${nonce}, ${addressHex}]`);
|
|
148
|
+
return new this(_SequenceParser.privateConstructorKey, hexString);
|
|
149
|
+
}
|
|
150
|
+
static parse(value) {
|
|
151
|
+
const hex = toHex(value);
|
|
152
|
+
if (isSequence(hex)) {
|
|
153
|
+
return new this(_SequenceParser.privateConstructorKey, hex);
|
|
154
|
+
}
|
|
155
|
+
throw new Error(`Invalid sequence [${value}]`);
|
|
156
|
+
}
|
|
157
|
+
// can convert a short number/hex to an epoch (treats it as the whole value) or extract an epoch from a sequence
|
|
158
|
+
static toEpoch(value) {
|
|
159
|
+
assertEx(
|
|
160
|
+
typeof value !== "number" || Number.isInteger(value),
|
|
161
|
+
() => "Value must be in integer"
|
|
162
|
+
);
|
|
163
|
+
const hex = toHex(value, { prefix: false });
|
|
164
|
+
if (hex.length <= SequenceConstants.epochBytes * 2) {
|
|
165
|
+
return toHex(value, { prefix: false, bitLength: SequenceConstants.epochBytes * 8 });
|
|
166
|
+
}
|
|
167
|
+
if (isSequence(hex)) {
|
|
168
|
+
return hex.slice(0, SequenceConstants.epochBytes * 2);
|
|
169
|
+
}
|
|
170
|
+
throw new Error(`Value could not be converted to epoch [${hex}]`);
|
|
171
|
+
}
|
|
172
|
+
// can convert a short number/hex to a nonce (treats it as the whole value) or extract an nonce from a sequence
|
|
173
|
+
static toNonce(value) {
|
|
174
|
+
assertEx(
|
|
175
|
+
typeof value !== "number" || Number.isInteger(value),
|
|
176
|
+
() => "Value must be in integer"
|
|
177
|
+
);
|
|
178
|
+
const hex = toHex(value, { prefix: false });
|
|
179
|
+
if (isSequence(hex)) {
|
|
180
|
+
return hex.slice(SequenceConstants.epochBytes * 2, SequenceConstants.localSequenceBytes * 2);
|
|
181
|
+
}
|
|
182
|
+
const hash = toHex(hex, { prefix: false, bitLength: SequenceConstants.nonceBytes * 8 });
|
|
183
|
+
return hash.slice(-SequenceConstants.nonceBytes * 2);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// src/StorageMeta/StorageMeta.ts
|
|
188
|
+
import { isHash } from "@xylabs/hex";
|
|
189
|
+
var isSequenceMeta = (value) => {
|
|
190
|
+
return value?._sequence !== void 0;
|
|
191
|
+
};
|
|
192
|
+
var isHashMeta = (value) => {
|
|
193
|
+
return isHash(value?._hash) && isHash(value?._dataHash);
|
|
194
|
+
};
|
|
195
|
+
var isStorageMeta = (value) => {
|
|
196
|
+
return isSequenceMeta(value) && isHashMeta(value);
|
|
197
|
+
};
|
|
67
198
|
export {
|
|
199
|
+
LocalSequenceConstants,
|
|
68
200
|
ModuleErrorSchema,
|
|
69
201
|
PayloadSchema,
|
|
70
202
|
PayloadSetSchema,
|
|
203
|
+
QualifiedSequenceConstants,
|
|
204
|
+
SequenceComponentLengths,
|
|
205
|
+
SequenceComponentMinMax,
|
|
206
|
+
SequenceConstants,
|
|
207
|
+
SequenceParser,
|
|
71
208
|
asAnyPayload,
|
|
72
209
|
asPayload,
|
|
73
210
|
asSchema,
|
|
74
211
|
isAnyPayload,
|
|
212
|
+
isEpoch,
|
|
213
|
+
isHashMeta,
|
|
214
|
+
isLocalSequence,
|
|
75
215
|
isModuleError,
|
|
216
|
+
isNonce,
|
|
76
217
|
isPayload,
|
|
77
218
|
isPayloadOfSchemaType,
|
|
78
|
-
isPayloadOfSchemaTypeWithMeta,
|
|
79
219
|
isPayloadOfSchemaTypeWithSources,
|
|
80
|
-
|
|
220
|
+
isQualifiedSequence,
|
|
81
221
|
isSchema,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
222
|
+
isSequence,
|
|
223
|
+
isSequenceMeta,
|
|
224
|
+
isStorageMeta,
|
|
225
|
+
notPayloadOfSchemaType
|
|
85
226
|
};
|
|
86
227
|
//# sourceMappingURL=index.mjs.map
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/isPayloadWithHash.ts","../../src/Meta.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.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 { WithMeta } from './Meta.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 isPayloadOfSchemaTypeWithMeta = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithMeta<T> => isPayloadOfSchemaType<WithMeta<T>>(schema)(x) && x.$hash !== undefined\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 }\nconst testWithMeta: WithMeta<Test> = { $hash: '1234abcd', $meta: { timestamp: Date.now() }, field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\nconst testMetaPayloads: WithMeta<Payload>[] = [testWithMeta]\n\nconst testType: Test = testWithMeta\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMeta: Payload[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\nconst isTestFromMetaWithMeta: PayloadWithMeta[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n\nconst isTestFromMetaTypedWithMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestWithMeta: WithMeta<Test>[] = testPayloads.filter(isPayloadOfSchemaTypeWithMeta(TestSchema))\nconst isTestWithMetaFromMeta: WithMeta<Test>[] = testMetaPayloads.filter(isPayloadOfSchemaTypeWithMeta(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","import { isAnyPayload } from './isPayload.ts'\nimport type { WithMeta } from './Meta.ts'\nimport type { Payload } from './Payload.ts'\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isWithHash = <T extends Payload>(value: T): value is WithMeta<T> => {\n return typeof (value as WithMeta<T>)?.$hash === 'string'\n}\n\n/**\n * Return true if the value is a payload with the required meta fields\n * @param value The value to check\n * @returns True if the value is a payload with the required meta fields\n */\nexport const isPayloadWithHash = <T extends Payload>(value: unknown): value is WithMeta<T> => {\n return isAnyPayload(value) && isWithHash(value)\n}\n","import type { EmptyObject, JsonObject } from '@xylabs/object'\n\nimport type { Payload, PayloadMetaFields } from './Payload.ts'\nimport type { Schema, WithSchema } from './Schema.ts'\n\nexport type WithMeta<T extends Payload = Payload, M extends JsonObject | void = void> = PayloadMetaFields<M> & T\nexport type WithOptionalMeta<T extends Payload = Payload, M extends JsonObject | void = void> = Partial<WithMeta<T, M>> &\n Omit<WithMeta<T, M>, '$hash'>\n\nexport type PayloadWithMeta<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> = WithMeta<Payload<T, S>>\n\nexport const unMeta = <T extends WithMeta<Payload>>(payload?: T): T | undefined => {\n if (payload) {\n const {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n $meta, $hash, ...result\n } = payload\n return result as T\n }\n}\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"],"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;;;AClB1I,IAAM,wBAAwB,CAAoB,WAAmB;AAC1E,SAAO,CAAC,MAA+B,aAAa,CAAC,KAAK,GAAG,WAAW;AAC1E;AAEO,IAAM,gCAAgC,CAAoB,WAAmB;AAClF,SAAO,CAAC,MAAyC,sBAAmC,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU;AAChH;AAEO,IAAM,mCAAmC,CAAoB,WAAmB;AACrF,SAAO,CAAC,MACN,sBAAsC,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,UAAa,MAAM,QAAQ,EAAE,OAAO;AAC1G;AAEO,IAAM,yBAAyB,CAAoB,WAAmB;AAC3E,SAAO,CAAC,MAA+B,CAAC,aAAa,CAAC,KAAK,GAAG,WAAW;AAC3E;;;ACZO,IAAM,oBAAuC;AAW7C,IAAM,gBAAgB,sBAAmC,iBAAiB;;;ACT1E,IAAM,aAAa,CAAoB,UAAmC;AAC/E,SAAO,OAAQ,OAAuB,UAAU;AAClD;AAOO,IAAM,oBAAoB,CAAoB,UAAyC;AAC5F,SAAO,aAAa,KAAK,KAAK,WAAW,KAAK;AAChD;;;ACTO,IAAM,SAAS,CAA8B,YAA+B;AACjF,MAAI,SAAS;AACX,UAAM;AAAA;AAAA,MAEJ;AAAA,MAAO;AAAA,MAAO,GAAG;AAAA,IACnB,IAAI;AACJ,WAAO;AAAA,EACT;AACF;;;AClBO,IAAM,mBAAqC;;;ACAlD,SAAS,qBAAqB;AAKvB,IAAM,gBAAgB;AAGtB,IAAM,WAAW,CAAC,UAAoC;AAC3D,SAAO,OAAO,UAAU;AAC1B;AAEO,IAAM,WAAW,cAAc,OAAe,QAAQ;","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,m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A,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
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { Payload } from './Payload.ts';
|
|
2
2
|
export declare const isAnyPayload: (value: unknown) => value is Payload;
|
|
3
3
|
export declare const asAnyPayload: {
|
|
4
|
-
<TType extends {
|
|
5
|
-
schema:
|
|
6
|
-
}
|
|
7
|
-
<TType extends {
|
|
8
|
-
schema:
|
|
9
|
-
}
|
|
10
|
-
schema:
|
|
11
|
-
}
|
|
4
|
+
<TType extends import("@xylabs/object").DeepRestrictToStringKeys<{
|
|
5
|
+
schema: import("./Schema.ts").Schema;
|
|
6
|
+
}>>(value: import(".store/@xylabs-promise-npm-4.4.21-54890ce283/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
7
|
+
<TType extends import("@xylabs/object").DeepRestrictToStringKeys<{
|
|
8
|
+
schema: import("./Schema.ts").Schema;
|
|
9
|
+
}>>(value: import(".store/@xylabs-promise-npm-4.4.21-54890ce283/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<import("@xylabs/object").DeepRestrictToStringKeys<{
|
|
10
|
+
schema: import("./Schema.ts").Schema;
|
|
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.21-54890ce283/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
|
|
16
|
+
<TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.21-54890ce283/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
|
|
17
17
|
};
|
|
18
18
|
//# sourceMappingURL=isPayload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPayload.d.ts","sourceRoot":"","sources":["../../src/isPayload.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,eAAO,MAAM,YAAY,UAAW,OAAO,KAAG,KAAK,IAAI,OAKtD,CAAA;AAED,eAAO,MAAM,YAAY;;;
|
|
1
|
+
{"version":3,"file":"isPayload.d.ts","sourceRoot":"","sources":["../../src/isPayload.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,eAAO,MAAM,YAAY,UAAW,OAAO,KAAG,KAAK,IAAI,OAKtD,CAAA;AAED,eAAO,MAAM,YAAY;;;sBAHrB,sDAGD,iCAAiC,gBAAoB;;;sBAIpD,sDAAc;;yBAEyB,gBAEjC;CARsD,CAAA;AAEhE,eAAO,MAAM,SAAS,GACjB,CAAC,SAAS,OAAO,UAAU,MAAM,EAAE,aAC5B,OAAO,KAAG,KAAK,IAAI,CAK1B,CAAA;AAEL,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,OAAO,UAAU,MAAM,EAAE;oCAdzD,sDAGD,iCAAiC,gBAAoB;oCAIpD,sDAAc,4FAEyB,gBAEjC;CAGwI,CAAA"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type { WithMeta } from './Meta.ts';
|
|
2
1
|
import type { Payload, WithSources } from './Payload.ts';
|
|
3
2
|
export declare const isPayloadOfSchemaType: <T extends Payload>(schema: string) => (x?: unknown | null) => x is T;
|
|
4
|
-
export declare const isPayloadOfSchemaTypeWithMeta: <T extends Payload>(schema: string) => (x?: unknown | null) => x is WithMeta<T>;
|
|
5
3
|
export declare const isPayloadOfSchemaTypeWithSources: <T extends Payload>(schema: string) => (x?: unknown | null) => x is WithSources<T>;
|
|
6
4
|
export declare const notPayloadOfSchemaType: <T extends Payload>(schema: string) => (x?: unknown | null) => x is T;
|
|
7
5
|
//# sourceMappingURL=isPayloadOfSchemaType.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPayloadOfSchemaType.d.ts","sourceRoot":"","sources":["../../src/isPayloadOfSchemaType.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"isPayloadOfSchemaType.d.ts","sourceRoot":"","sources":["../../src/isPayloadOfSchemaType.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAExD,eAAO,MAAM,qBAAqB,GAAI,CAAC,SAAS,OAAO,UAAU,MAAM,UACzD,OAAO,GAAG,IAAI,KAAG,CAAC,IAAI,CACnC,CAAA;AAED,eAAO,MAAM,gCAAgC,GAAI,CAAC,SAAS,OAAO,UAAU,MAAM,UACpE,OAAO,GAAG,IAAI,KAAG,CAAC,IAAI,WAAW,CAAC,CAAC,CAEhD,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAAS,OAAO,UAAU,MAAM,UAC1D,OAAO,GAAG,IAAI,KAAG,CAAC,IAAI,CACnC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/payload-model",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0-rc.10",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -37,17 +37,20 @@
|
|
|
37
37
|
"module": "dist/neutral/index.mjs",
|
|
38
38
|
"types": "dist/neutral/index.d.ts",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@xylabs/
|
|
41
|
-
"@xylabs/
|
|
40
|
+
"@xylabs/arraybuffer": "^4.4.21",
|
|
41
|
+
"@xylabs/assert": "^4.4.21",
|
|
42
|
+
"@xylabs/hex": "^4.4.21",
|
|
43
|
+
"@xylabs/object": "^4.4.21"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
|
-
"@xylabs/ts-scripts-yarn3": "^4.2.
|
|
45
|
-
"@xylabs/tsconfig": "^4.2.
|
|
46
|
-
"@xylabs/vitest-extended": "^4.4.
|
|
46
|
+
"@xylabs/ts-scripts-yarn3": "^4.2.6",
|
|
47
|
+
"@xylabs/tsconfig": "^4.2.6",
|
|
48
|
+
"@xylabs/vitest-extended": "^4.4.21",
|
|
47
49
|
"typescript": "^5.7.2",
|
|
48
|
-
"vitest": "^2.1.
|
|
50
|
+
"vitest": "^2.1.8"
|
|
49
51
|
},
|
|
50
52
|
"publishConfig": {
|
|
51
53
|
"access": "public"
|
|
52
|
-
}
|
|
54
|
+
},
|
|
55
|
+
"stableVersion": "3.5.2"
|
|
53
56
|
}
|
package/src/Error.ts
CHANGED
package/src/Payload.ts
CHANGED
|
@@ -1,43 +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
|
-
/** Hash of the body of the payload excluding the items in the $meta object */
|
|
9
|
-
$hash: Hash
|
|
10
|
-
/** Meta data that should be included in the main hash of the payload */
|
|
11
|
-
$meta?: TAdditionalMeta extends void ? JsonObject : TAdditionalMeta
|
|
8
|
+
export interface SchemaField<T extends Schema = Schema> {
|
|
9
|
+
schema: T
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
/** Additional fields for a payload */
|
|
15
|
-
export interface PayloadFields extends
|
|
16
|
-
schema: Schema
|
|
17
|
-
}
|
|
13
|
+
export interface PayloadFields extends SchemaField {}
|
|
18
14
|
|
|
19
|
-
export type WithPayload<T extends EmptyObject | void = void> =
|
|
15
|
+
export type WithPayload<T extends EmptyObject | void = void> =
|
|
16
|
+
DeepRestrictToStringKeys<WithoutMeta<WithSchema<T extends EmptyObject ? PayloadFields & T : PayloadFields>>>
|
|
20
17
|
|
|
21
18
|
/** Base Type for Payloads */
|
|
22
19
|
export type Payload<T extends void | EmptyObject | WithSchema = void, S extends Schema | void = void> =
|
|
23
20
|
T extends WithSchema ?
|
|
24
21
|
S extends Schema ?
|
|
25
22
|
/* T (w/Schema) & S provided */
|
|
26
|
-
WithPayload<Omit<T, 'schema'> & { schema: S }
|
|
23
|
+
WithPayload<Omit<T, 'schema'> & { schema: S }>
|
|
27
24
|
: /* Only T (w/Schema) provided */ WithPayload<T>
|
|
28
25
|
: T extends object ?
|
|
29
26
|
S extends Schema ?
|
|
30
27
|
/* T (w/o Schema) & S provided */
|
|
31
|
-
WithPayload<T & { schema: S }
|
|
32
|
-
: /* Only T (w/o Schema) provided */ WithPayload<T &
|
|
28
|
+
WithPayload<T & { schema: S }>
|
|
29
|
+
: /* Only T (w/o Schema) provided */ WithPayload<T & PayloadFields>
|
|
33
30
|
: /* Either just S or neither S or T provided */
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
WithPayload<{
|
|
32
|
+
schema: S extends Schema ? S : Schema
|
|
33
|
+
}>
|
|
34
|
+
|
|
35
|
+
export type OverridablePayload<T extends Payload> = WithoutMeta<Omit<T, 'schema'> & PayloadFields>
|
|
36
|
+
|
|
37
|
+
export type SourcesMetaField = { $sources: Hash[] }
|
|
37
38
|
|
|
38
|
-
export type
|
|
39
|
+
export type WithSources<T extends EmptyObject> = T & SourcesMetaField
|
|
40
|
+
export type WithOptionalSources<T extends EmptyObject> = (T & SourcesMetaField) | T
|
|
39
41
|
|
|
40
|
-
export type WithSources<T extends EmptyObject> = T & { sources?: Hash[] }
|
|
41
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>
|
|
42
54
|
|
|
43
|
-
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
|
+
minLocalSequence: LocalSequenceConstants.minLocalSequence + SequenceComponentMinMax.minAddress as QualifiedSequence,
|
|
59
|
+
maxLocalSequence: 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"
|