@xyo-network/payload-model 5.3.20 → 5.3.24
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/neutral/StorageMeta/DataHash.d.ts +2 -2
- package/dist/neutral/StorageMeta/DataHash.d.ts.map +1 -1
- package/dist/neutral/StorageMeta/Hash.d.ts +2 -2
- package/dist/neutral/StorageMeta/Hash.d.ts.map +1 -1
- package/dist/neutral/StorageMeta/Sequence.d.ts +1 -1
- package/dist/neutral/StorageMeta/Sequence.d.ts.map +1 -1
- package/package.json +15 -9
- package/src/Error.ts +0 -17
- package/src/Payload.ts +0 -56
- package/src/PayloadBundle.ts +0 -27
- package/src/PayloadFindFilter.ts +0 -5
- package/src/PayloadHashMap.ts +0 -11
- package/src/PayloadSet/PayloadSetPayload.ts +0 -9
- package/src/PayloadSet/PayloadSetSchema.ts +0 -4
- package/src/PayloadSet/index.ts +0 -2
- package/src/PayloadValidationFunction.ts +0 -16
- package/src/PayloadValueExpression.ts +0 -43
- package/src/PayloadZod.ts +0 -78
- package/src/Query.ts +0 -27
- package/src/Schema.ts +0 -21
- package/src/StorageMeta/DataHash.ts +0 -36
- package/src/StorageMeta/Hash.ts +0 -38
- package/src/StorageMeta/Sequence.ts +0 -18
- package/src/StorageMeta/index.ts +0 -2
- package/src/StorageMeta/sequence/Comparer.ts +0 -18
- package/src/StorageMeta/sequence/Parser.ts +0 -142
- package/src/StorageMeta/sequence/Sequence.ts +0 -80
- package/src/StorageMeta/sequence/SequenceZod.ts +0 -16
- package/src/StorageMeta/sequence/index.ts +0 -4
- package/src/Timestamp.ts +0 -9
- package/src/index.ts +0 -15
- package/src/isPayloadOfSchemaType.ts +0 -32
- package/src/isPayloadOfZodType.ts +0 -25
- package/src/types.d.ts +0 -6
|
@@ -7,7 +7,7 @@ export type WithDataHashMeta<T extends Payload = Payload> = T & DataHashMeta;
|
|
|
7
7
|
export type WithPartialDataHashMeta<T extends Payload = Payload> = Partial<WithDataHashMeta<T>>;
|
|
8
8
|
export declare const isDataHashMeta: (value: unknown) => value is DataHashMeta;
|
|
9
9
|
export declare const asDataHashMeta: import("@xylabs/sdk-js").AsTypeFunction<DataHashMeta>;
|
|
10
|
-
export declare const asOptionalDataHashMeta: (value: import("@xylabs/
|
|
10
|
+
export declare const asOptionalDataHashMeta: (value: import("@xylabs/sdk-js").AnyNonPromise) => DataHashMeta | undefined;
|
|
11
11
|
/** @deprecated use DataHashMeta instead */
|
|
12
12
|
export interface DataHashStorageMeta extends DataHashMeta {
|
|
13
13
|
}
|
|
@@ -20,5 +20,5 @@ export declare const isDataHashStorageMeta: (value: unknown) => value is DataHas
|
|
|
20
20
|
/** @deprecated use asDataHashMeta instead */
|
|
21
21
|
export declare const asDataHashStorageMeta: import("@xylabs/sdk-js").AsTypeFunction<DataHashMeta>;
|
|
22
22
|
/** @deprecated use asOptionalDataHashMeta instead */
|
|
23
|
-
export declare const asOptionalDataHashStorageMeta: (value: import("@xylabs/
|
|
23
|
+
export declare const asOptionalDataHashStorageMeta: (value: import("@xylabs/sdk-js").AnyNonPromise) => DataHashMeta | undefined;
|
|
24
24
|
//# sourceMappingURL=DataHash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataHash.d.ts","sourceRoot":"","sources":["../../../src/StorageMeta/DataHash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAG1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,IAAI,CAAA;CAChB;AAED,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,CAAC,GAAG,YAAY,CAAA;AAC5E,MAAM,MAAM,uBAAuB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAA;AAE/F,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,YAExD,CAAA;AAED,eAAO,MAAM,cAAc,uDAAuD,CAAA;AAClF,eAAO,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"DataHash.d.ts","sourceRoot":"","sources":["../../../src/StorageMeta/DataHash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAG1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,IAAI,CAAA;CAChB;AAED,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,CAAC,GAAG,YAAY,CAAA;AAC5E,MAAM,MAAM,uBAAuB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAA;AAE/F,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,YAExD,CAAA;AAED,eAAO,MAAM,cAAc,uDAAuD,CAAA;AAClF,eAAO,MAAM,sBAAsB,6EAA+D,CAAA;AAElG,2CAA2C;AAC3C,MAAM,WAAW,mBAAoB,SAAQ,YAAY;CAAG;AAE5D,+CAA+C;AAC/C,MAAM,MAAM,uBAAuB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAA;AAEtF,sDAAsD;AACtD,MAAM,MAAM,8BAA8B,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,uBAAuB,CAAC,CAAC,CAAC,CAAA;AAEpG,6CAA6C;AAC7C,eAAO,MAAM,qBAAqB,UAjBI,OAAO,KAAG,KAAK,IAAI,YAiBN,CAAA;AAEnD,6CAA6C;AAC7C,eAAO,MAAM,qBAAqB,uDAAiB,CAAA;AAEnD,qDAAqD;AACrD,eAAO,MAAM,6BAA6B,6EAAyB,CAAA"}
|
|
@@ -8,7 +8,7 @@ export type WithHashMeta<T extends Payload = Payload> = T & HashMeta;
|
|
|
8
8
|
export type WithPartialHashMeta<T extends Payload = Payload> = Partial<WithHashMeta<T>>;
|
|
9
9
|
export declare const isHashMeta: (value: unknown) => value is HashMeta;
|
|
10
10
|
export declare const asHashMeta: import("@xylabs/sdk-js").AsTypeFunction<HashMeta>;
|
|
11
|
-
export declare const asOptionalHashMeta: (value: import("@xylabs/
|
|
11
|
+
export declare const asOptionalHashMeta: (value: import("@xylabs/sdk-js").AnyNonPromise) => HashMeta | undefined;
|
|
12
12
|
/** @deprecated use HashMeta instead */
|
|
13
13
|
export interface HashStorageMeta extends HashMeta {
|
|
14
14
|
}
|
|
@@ -21,5 +21,5 @@ export declare const isHashStorageMeta: (value: unknown) => value is HashMeta;
|
|
|
21
21
|
/** @deprecated use asHashMeta instead */
|
|
22
22
|
export declare const asHashStorageMeta: import("@xylabs/sdk-js").AsTypeFunction<HashMeta>;
|
|
23
23
|
/** @deprecated use asOptionalHashMeta instead */
|
|
24
|
-
export declare const asOptionalHashStorageMeta: (value: import("@xylabs/
|
|
24
|
+
export declare const asOptionalHashStorageMeta: (value: import("@xylabs/sdk-js").AnyNonPromise) => HashMeta | undefined;
|
|
25
25
|
//# sourceMappingURL=Hash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Hash.d.ts","sourceRoot":"","sources":["../../../src/StorageMeta/Hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAG1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAGjD,MAAM,WAAW,QAAS,SAAQ,YAAY;IAC5C,KAAK,EAAE,IAAI,CAAA;CACZ;AAED,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,CAAC,GAAG,QAAQ,CAAA;AACpE,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;AAEvF,eAAO,MAAM,UAAU,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,QAEpD,CAAA;AAED,eAAO,MAAM,UAAU,mDAA+C,CAAA;AACtE,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"Hash.d.ts","sourceRoot":"","sources":["../../../src/StorageMeta/Hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAG1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAGjD,MAAM,WAAW,QAAS,SAAQ,YAAY;IAC5C,KAAK,EAAE,IAAI,CAAA;CACZ;AAED,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,CAAC,GAAG,QAAQ,CAAA;AACpE,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;AAEvF,eAAO,MAAM,UAAU,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,QAEpD,CAAA;AAED,eAAO,MAAM,UAAU,mDAA+C,CAAA;AACtE,eAAO,MAAM,kBAAkB,yEAAuD,CAAA;AAEtF,uCAAuC;AACvC,MAAM,WAAW,eAAgB,SAAQ,QAAQ;CAAG;AAEpD,2CAA2C;AAC3C,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,YAAY,CAAC,CAAC,CAAC,CAAA;AAE9E,kDAAkD;AAClD,MAAM,MAAM,0BAA0B,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;AAE9F,yCAAyC;AACzC,eAAO,MAAM,iBAAiB,UAjBI,OAAO,KAAG,KAAK,IAAI,QAiBV,CAAA;AAE3C,yCAAyC;AACzC,eAAO,MAAM,iBAAiB,mDAAa,CAAA;AAE3C,iDAAiD;AACjD,eAAO,MAAM,yBAAyB,yEAAqB,CAAA"}
|
|
@@ -7,5 +7,5 @@ export type WithSequenceStorageMeta<T extends Payload = Payload> = T & SequenceS
|
|
|
7
7
|
export type WithPartialSequenceStorageMeta<T extends Payload = Payload> = Partial<WithSequenceStorageMeta<T>>;
|
|
8
8
|
export declare const isSequenceStorageMeta: (value: unknown) => value is SequenceStorageMeta;
|
|
9
9
|
export declare const asSequenceStorageMeta: import("@xylabs/sdk-js").AsTypeFunction<SequenceStorageMeta>;
|
|
10
|
-
export declare const asOptionalSequenceStorageMeta: (value: import("@xylabs/
|
|
10
|
+
export declare const asOptionalSequenceStorageMeta: (value: import("@xylabs/sdk-js").AnyNonPromise) => SequenceStorageMeta | undefined;
|
|
11
11
|
//# sourceMappingURL=Sequence.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sequence.d.ts","sourceRoot":"","sources":["../../../src/StorageMeta/Sequence.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAEnD,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,QAAQ,CAAA;CACpB;AAED,MAAM,MAAM,uBAAuB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,CAAC,GAAG,mBAAmB,CAAA;AAC1F,MAAM,MAAM,8BAA8B,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAA;AAE7G,eAAO,MAAM,qBAAqB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,mBAE/D,CAAA;AAED,eAAO,MAAM,qBAAqB,8DAAgD,CAAA;AAClF,eAAO,MAAM,6BAA6B,
|
|
1
|
+
{"version":3,"file":"Sequence.d.ts","sourceRoot":"","sources":["../../../src/StorageMeta/Sequence.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAEnD,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,QAAQ,CAAA;CACpB;AAED,MAAM,MAAM,uBAAuB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,CAAC,GAAG,mBAAmB,CAAA;AAC1F,MAAM,MAAM,8BAA8B,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAA;AAE7G,eAAO,MAAM,qBAAqB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,mBAE/D,CAAA;AAED,eAAO,MAAM,qBAAqB,8DAAgD,CAAA;AAClF,eAAO,MAAM,6BAA6B,oFAAwD,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/payload-model",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.24",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -30,18 +30,24 @@
|
|
|
30
30
|
"types": "dist/neutral/index.d.ts",
|
|
31
31
|
"files": [
|
|
32
32
|
"dist",
|
|
33
|
-
"src",
|
|
34
33
|
"!**/*.bench.*",
|
|
35
34
|
"!**/*.spec.*",
|
|
36
|
-
"!**/*.test.*"
|
|
35
|
+
"!**/*.test.*",
|
|
36
|
+
"README.md"
|
|
37
37
|
],
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@xylabs/
|
|
42
|
-
"@xylabs/
|
|
43
|
-
"@xylabs/
|
|
39
|
+
"@opentelemetry/api": "^1.9.1",
|
|
40
|
+
"@types/node": "^25.5.0",
|
|
41
|
+
"@xylabs/sdk-js": "^5.0.93",
|
|
42
|
+
"@xylabs/ts-scripts-common": "~7.6.16",
|
|
43
|
+
"@xylabs/ts-scripts-pnpm": "~7.6.16",
|
|
44
|
+
"@xylabs/tsconfig": "~7.6.16",
|
|
45
|
+
"@xylabs/vitest-extended": "~5.0.93",
|
|
46
|
+
"acorn": "^8.16.0",
|
|
47
|
+
"axios": "^1.14.0",
|
|
48
|
+
"esbuild": "^0.28.0",
|
|
44
49
|
"typescript": "~5.9.3",
|
|
50
|
+
"vite": "^8.0.3",
|
|
45
51
|
"vitest": "~4.1.2",
|
|
46
52
|
"zod": "~4.3.6"
|
|
47
53
|
},
|
|
@@ -52,4 +58,4 @@
|
|
|
52
58
|
"publishConfig": {
|
|
53
59
|
"access": "public"
|
|
54
60
|
}
|
|
55
|
-
}
|
|
61
|
+
}
|
package/src/Error.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Hash, JsonValue } from '@xylabs/sdk-js'
|
|
2
|
-
|
|
3
|
-
import { isPayloadOfSchemaType } from './isPayloadOfSchemaType.ts'
|
|
4
|
-
import type { Payload } from './Payload.ts'
|
|
5
|
-
import { asSchema, type Schema } from './Schema.ts'
|
|
6
|
-
|
|
7
|
-
export const ModuleErrorSchema = asSchema('network.xyo.error.module', true)
|
|
8
|
-
export type ModuleErrorSchema = typeof ModuleErrorSchema
|
|
9
|
-
|
|
10
|
-
export type ModuleError = Payload<{
|
|
11
|
-
details?: JsonValue
|
|
12
|
-
message?: string
|
|
13
|
-
name?: string
|
|
14
|
-
query?: Hash | Schema
|
|
15
|
-
}, ModuleErrorSchema>
|
|
16
|
-
|
|
17
|
-
export const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)
|
package/src/Payload.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
DeepOmitStartsWith, DeepPickStartsWith, EmptyObject, Hash,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
|
|
5
|
-
import type { BrandedSchema, Schema } from './Schema.ts'
|
|
6
|
-
|
|
7
|
-
export interface SchemaField<T extends Schema = Schema> {
|
|
8
|
-
schema: T
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type WithSchema<T extends EmptyObject | void = void>
|
|
12
|
-
= T extends EmptyObject ? SchemaField & T : PayloadFields
|
|
13
|
-
|
|
14
|
-
/** Additional fields for a payload */
|
|
15
|
-
export interface PayloadFields extends SchemaField {}
|
|
16
|
-
|
|
17
|
-
export interface SourcesMetaField { $sources: Hash[] }
|
|
18
|
-
|
|
19
|
-
export interface PayloadMetaFields extends SourcesMetaField {}
|
|
20
|
-
|
|
21
|
-
export type WithPayload<T extends EmptyObject | void = void>
|
|
22
|
-
= T extends EmptyObject ? PayloadFields & T : PayloadFields
|
|
23
|
-
|
|
24
|
-
/** Base Type for Payloads */
|
|
25
|
-
export type Payload<T extends void | EmptyObject | SchemaField = void, S extends Schema | void = void>
|
|
26
|
-
= (T extends SchemaField
|
|
27
|
-
? S extends Schema
|
|
28
|
-
/* T (w/Schema) & S provided */
|
|
29
|
-
? WithPayload<Omit<T, 'schema'> & { schema: BrandedSchema<S> }>
|
|
30
|
-
: /* Only T (w/Schema) provided */ WithPayload<T>
|
|
31
|
-
: T extends object
|
|
32
|
-
? S extends Schema
|
|
33
|
-
/* T (w/o Schema) & S provided */
|
|
34
|
-
? WithPayload<T & { schema: BrandedSchema<S> }>
|
|
35
|
-
: /* Only T (w/o Schema) provided */ WithPayload<T & PayloadFields>
|
|
36
|
-
: /* Either just S or neither S or T provided */ WithPayload<{
|
|
37
|
-
schema: S extends Schema ? S : Schema
|
|
38
|
-
}>) & Partial<PayloadMetaFields>
|
|
39
|
-
|
|
40
|
-
export type OverridablePayload<T extends Payload> = WithoutMeta<Omit<T, 'schema'> & PayloadFields>
|
|
41
|
-
|
|
42
|
-
export type WithSources<T extends EmptyObject> = T & SourcesMetaField
|
|
43
|
-
|
|
44
|
-
export type PayloadWithSources<T extends void | EmptyObject | SchemaField = void, S extends Schema | void = void> = WithSources<Payload<T, S>>
|
|
45
|
-
|
|
46
|
-
export type WithAnySchema<T extends Payload> = OverridablePayload<T>
|
|
47
|
-
|
|
48
|
-
export type WithoutClientMeta<T extends Payload | EmptyObject> = DeepOmitStartsWith<T, '$'> & (T extends Payload ? Payload : EmptyObject)
|
|
49
|
-
export type WithoutStorageMeta<T extends Payload | EmptyObject> = DeepOmitStartsWith<T, '_'> & (T extends Payload ? Payload : EmptyObject)
|
|
50
|
-
export type WithoutPrivateStorageMeta<T extends Payload | EmptyObject> = DeepOmitStartsWith<T, '__'> & (T extends Payload ? Payload : EmptyObject)
|
|
51
|
-
export type WithoutMeta<T extends Payload | EmptyObject> = WithoutClientMeta<WithoutStorageMeta<T>> & (T extends Payload ? Payload : EmptyObject)
|
|
52
|
-
|
|
53
|
-
export type WithoutSchema<T extends WithOptionalSchema<Payload>> = Omit<T, 'schema'>
|
|
54
|
-
export type WithOptionalSchema<T extends Payload = Payload> = WithoutSchema<T> & Partial<T & SchemaField>
|
|
55
|
-
|
|
56
|
-
export type WithOnlyClientMeta<T extends Payload> = DeepPickStartsWith<T, '$'>
|
package/src/PayloadBundle.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HashZod,
|
|
3
|
-
zodAsFactory, zodIsFactory, zodToFactory,
|
|
4
|
-
} from '@xylabs/sdk-js'
|
|
5
|
-
import z from 'zod'
|
|
6
|
-
|
|
7
|
-
import { PayloadZodLoose, PayloadZodOfSchema } from './PayloadZod.ts'
|
|
8
|
-
import { asSchema } from './Schema.ts'
|
|
9
|
-
|
|
10
|
-
// payload that wraps a complete boundwitness with its payloads for use in systems such as submission queues
|
|
11
|
-
export const PayloadBundleSchema = asSchema('network.xyo.payload.bundle', true)
|
|
12
|
-
export type PayloadBundleSchema = typeof PayloadBundleSchema
|
|
13
|
-
|
|
14
|
-
export const PayloadBundleFieldsZod = z.object({
|
|
15
|
-
payloads: PayloadZodLoose.array(),
|
|
16
|
-
root: HashZod,
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
export type PayloadBundleFields = z.infer<typeof PayloadBundleFieldsZod>
|
|
20
|
-
|
|
21
|
-
export const PayloadBundleZod = PayloadZodOfSchema(PayloadBundleSchema).extend(PayloadBundleFieldsZod.shape)
|
|
22
|
-
|
|
23
|
-
export type PayloadBundle = z.infer<typeof PayloadBundleZod>
|
|
24
|
-
|
|
25
|
-
export const isPayloadBundle = zodIsFactory(PayloadBundleZod)
|
|
26
|
-
export const asPayloadBundle = zodAsFactory(PayloadBundleZod, 'asPayloadBundle')
|
|
27
|
-
export const asOptionalPayloadBundle = zodToFactory(PayloadBundleZod, 'asPayloadBundle')
|
package/src/PayloadFindFilter.ts
DELETED
package/src/PayloadHashMap.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
-
|
|
3
|
-
import type { Payload } from './Payload.ts'
|
|
4
|
-
|
|
5
|
-
export interface PayloadHashMap<TPayload extends Payload = Payload, TId extends string | number | symbol = Hash> {
|
|
6
|
-
// these hashes are data hashes, but reference an arbitrary root hash that matches the data hash
|
|
7
|
-
// this list can be shorter than the full list since multiple root hashes may have the same data hash
|
|
8
|
-
dataHash: Record<TId, TId>
|
|
9
|
-
// this if the full list of all payloads
|
|
10
|
-
hash: Record<TId, TPayload>
|
|
11
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Payload } from '../Payload.ts'
|
|
2
|
-
import type { PayloadSetSchema } from './PayloadSetSchema.ts'
|
|
3
|
-
|
|
4
|
-
export interface PayloadSet {
|
|
5
|
-
optional?: Record<string, number>
|
|
6
|
-
required?: Record<string, number>
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type PayloadSetPayload = Payload<PayloadSet, PayloadSetSchema>
|
package/src/PayloadSet/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Payload } from './Payload.ts'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A function that validates the supplied payload synchronously
|
|
5
|
-
*/
|
|
6
|
-
export type SyncPayloadValidationFunction<T extends Payload = Payload> = (payload: T) => boolean
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A function that validates the supplied payload asynchronously
|
|
10
|
-
*/
|
|
11
|
-
export type AsyncPayloadValidationFunction<T extends Payload = Payload> = (payload: T) => Promise<boolean>
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* A function that validates the supplied payload
|
|
15
|
-
*/
|
|
16
|
-
export type PayloadValidationFunction<T extends Payload = Payload> = SyncPayloadValidationFunction<T> | AsyncPayloadValidationFunction<T>
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { Payload } from './Payload.ts'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Type corresponding to the properties of a payload
|
|
5
|
-
*/
|
|
6
|
-
export type PayloadProperty<
|
|
7
|
-
/**
|
|
8
|
-
* The type of payload
|
|
9
|
-
*/
|
|
10
|
-
T extends Payload = Payload,
|
|
11
|
-
> = keyof T
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Type corresponding to the payload values
|
|
15
|
-
*/
|
|
16
|
-
export type PayloadValue<
|
|
17
|
-
/**
|
|
18
|
-
* The type of payload
|
|
19
|
-
*/
|
|
20
|
-
T extends Payload = Payload,
|
|
21
|
-
/**
|
|
22
|
-
* The property of the payload to select
|
|
23
|
-
*/
|
|
24
|
-
Key extends PayloadProperty<T> = PayloadProperty<T>,
|
|
25
|
-
> = T[Key]
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* An expressions that selects a property value from the payload
|
|
29
|
-
*/
|
|
30
|
-
export type PayloadValueExpression<
|
|
31
|
-
/**
|
|
32
|
-
* The type of payload
|
|
33
|
-
*/
|
|
34
|
-
T extends Payload = Payload,
|
|
35
|
-
/**
|
|
36
|
-
* The property of the payload to select
|
|
37
|
-
*/
|
|
38
|
-
Key extends PayloadProperty<T> = PayloadProperty<T>,
|
|
39
|
-
/**
|
|
40
|
-
* The type of the selected property's value
|
|
41
|
-
*/
|
|
42
|
-
TValue = PayloadValue<T, Key>,
|
|
43
|
-
> = (payload: T) => TValue
|
package/src/PayloadZod.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HashZod,
|
|
3
|
-
zodAsFactory, zodIsFactory, zodToFactory,
|
|
4
|
-
} from '@xylabs/sdk-js'
|
|
5
|
-
import type { ZodRawShape } from 'zod'
|
|
6
|
-
import z from 'zod'
|
|
7
|
-
|
|
8
|
-
import type { Payload } from './Payload.ts'
|
|
9
|
-
import type { Schema } from './Schema.ts'
|
|
10
|
-
import { SchemaZod } from './Schema.ts'
|
|
11
|
-
import { SequenceFromStringZod } from './StorageMeta/index.ts'
|
|
12
|
-
|
|
13
|
-
export const HashMetaZod = z.object({
|
|
14
|
-
_hash: HashZod,
|
|
15
|
-
_dataHash: HashZod,
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
export type HashMeta = z.infer<typeof HashMetaZod>
|
|
19
|
-
|
|
20
|
-
export type WithHashMeta<T extends Payload> = T & HashMeta
|
|
21
|
-
|
|
22
|
-
export const isHashMeta = zodIsFactory(HashMetaZod)
|
|
23
|
-
export const asHashMeta = zodAsFactory(HashMetaZod, 'asHashMeta')
|
|
24
|
-
export const toHashMeta = zodToFactory(HashMetaZod, 'toHashMeta')
|
|
25
|
-
|
|
26
|
-
export const SequenceMetaZod = z.object({ _sequence: SequenceFromStringZod })
|
|
27
|
-
|
|
28
|
-
export type SequenceMeta = z.infer<typeof SequenceMetaZod>
|
|
29
|
-
|
|
30
|
-
export const isSequenceMeta = zodIsFactory(SequenceMetaZod)
|
|
31
|
-
export const asSequenceMeta = zodAsFactory(SequenceMetaZod, 'asSequenceMeta')
|
|
32
|
-
export const toSequenceMeta = zodToFactory(SequenceMetaZod, 'toSequenceMeta')
|
|
33
|
-
|
|
34
|
-
export const StorageMetaZod = z.object({
|
|
35
|
-
_hash: HashZod,
|
|
36
|
-
_dataHash: HashZod,
|
|
37
|
-
_sequence: SequenceFromStringZod,
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
export type StorageMeta = z.infer<typeof StorageMetaZod>
|
|
41
|
-
|
|
42
|
-
export type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta
|
|
43
|
-
|
|
44
|
-
export const isStorageMeta = zodIsFactory(StorageMetaZod)
|
|
45
|
-
export const asStorageMeta = zodAsFactory(StorageMetaZod, 'asStorageMeta')
|
|
46
|
-
export const toStorageMeta = zodToFactory(StorageMetaZod, 'toStorageMeta')
|
|
47
|
-
|
|
48
|
-
export const PayloadZod = z.object({ schema: SchemaZod })
|
|
49
|
-
|
|
50
|
-
export const isPayload = zodIsFactory(PayloadZod)
|
|
51
|
-
export const asPayload = zodAsFactory(PayloadZod, 'asPayload')
|
|
52
|
-
export const toPayload = zodToFactory(PayloadZod, 'toPayload')
|
|
53
|
-
|
|
54
|
-
export const AnyPayloadZod = PayloadZod.loose()
|
|
55
|
-
|
|
56
|
-
export const isAnyPayload = zodIsFactory(AnyPayloadZod)
|
|
57
|
-
export const asAnyPayload = zodAsFactory(AnyPayloadZod, 'asAnyPayload')
|
|
58
|
-
export const toAnyPayload = zodToFactory(AnyPayloadZod, 'toAnyPayload')
|
|
59
|
-
|
|
60
|
-
export type AnyPayload = z.infer<typeof AnyPayloadZod>
|
|
61
|
-
|
|
62
|
-
export function WithStorageMetaZod<T extends ZodRawShape>(valueZod: z.ZodObject<T>) {
|
|
63
|
-
return z.object({ ...valueZod.shape, ...StorageMetaZod.shape })
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function WithHashMetaZod<T extends ZodRawShape>(valueZod: z.ZodObject<T>) {
|
|
67
|
-
return z.object({ ...valueZod.shape, ...HashMetaZod.shape })
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export const PayloadZodStrict = z.strictObject({ schema: SchemaZod })
|
|
71
|
-
export type PayloadZodStrict = typeof PayloadZodStrict
|
|
72
|
-
|
|
73
|
-
export const PayloadZodLoose: PayloadZodStrict = z.looseObject({ schema: SchemaZod })
|
|
74
|
-
export type PayloadZodLoose = typeof PayloadZodLoose
|
|
75
|
-
|
|
76
|
-
export const PayloadZodOfSchema = <S extends Schema>(schema: S) => PayloadZod.extend({ schema: z.literal(schema) })
|
|
77
|
-
export const PayloadZodStrictOfSchema = <S extends Schema>(schema: S) => PayloadZodStrict.extend({ schema: z.literal(schema) })
|
|
78
|
-
export const PayloadZodLooseOfSchema = <S extends Schema>(schema: S) => PayloadZodLoose.extend({ schema: z.literal(schema) })
|
package/src/Query.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Address, EmptyObject } from '@xylabs/sdk-js'
|
|
2
|
-
|
|
3
|
-
import type { Payload, SchemaField } from './Payload.ts'
|
|
4
|
-
import type { Schema } from './Schema.ts'
|
|
5
|
-
|
|
6
|
-
export interface QueryFields {
|
|
7
|
-
/** @field The addresses of the intended handlers */
|
|
8
|
-
address?: Address | Address[]
|
|
9
|
-
|
|
10
|
-
/** @field The maximum XYO that can be spent executing the query */
|
|
11
|
-
budget?: number
|
|
12
|
-
|
|
13
|
-
/** @field The frequency on which this query can be rerun */
|
|
14
|
-
maxFrequency?: 'once' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year'
|
|
15
|
-
|
|
16
|
-
/** @field The starting point for the bidding on the query */
|
|
17
|
-
minBid?: number
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type Query<T extends void | EmptyObject | SchemaField = void, S extends Schema | void = void> = Payload<
|
|
21
|
-
T extends void ? QueryFields : T & QueryFields,
|
|
22
|
-
S extends void
|
|
23
|
-
? T extends SchemaField ? T['schema']
|
|
24
|
-
: T extends void ? Schema
|
|
25
|
-
: void
|
|
26
|
-
: S
|
|
27
|
-
>
|
package/src/Schema.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Brand } from '@xylabs/sdk-js'
|
|
2
|
-
import { zodAsFactory, zodIsFactory } from '@xylabs/sdk-js'
|
|
3
|
-
import z from 'zod'
|
|
4
|
-
|
|
5
|
-
export type BrandedSchema<T extends string = string> = Brand<T, { readonly __schema: true }>
|
|
6
|
-
export const SchemaRegEx = /^(?:[a-z0-9]+\.)*[a-z0-9]+$/
|
|
7
|
-
|
|
8
|
-
export const SchemaZod = z.string().regex(SchemaRegEx).transform<BrandedSchema>(v => v as BrandedSchema)
|
|
9
|
-
export type Schema<T extends string = string> = z.infer<typeof SchemaZod> & BrandedSchema<T>
|
|
10
|
-
|
|
11
|
-
export const makeSchema = <T extends string>(value: T) => {
|
|
12
|
-
return (z.templateLiteral([z.literal(value)])).transform(x => x as (typeof x & { __schema: true }))
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const isSchema = zodIsFactory(SchemaZod)
|
|
16
|
-
export const asSchema = zodAsFactory(SchemaZod, 'asSchema')
|
|
17
|
-
export const toSchema = zodAsFactory(SchemaZod, 'toSchema')
|
|
18
|
-
|
|
19
|
-
export const PayloadSchema = asSchema('network.xyo.payload', true)
|
|
20
|
-
export const PayloadSchemaZod = z.literal(PayloadSchema)
|
|
21
|
-
export type PayloadSchema = z.infer<typeof PayloadSchemaZod>
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import { AsObjectFactory, isHash } from '@xylabs/sdk-js'
|
|
3
|
-
|
|
4
|
-
import type { Payload } from '../Payload.ts'
|
|
5
|
-
|
|
6
|
-
export interface DataHashMeta {
|
|
7
|
-
_dataHash: Hash
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type WithDataHashMeta<T extends Payload = Payload> = T & DataHashMeta
|
|
11
|
-
export type WithPartialDataHashMeta<T extends Payload = Payload> = Partial<WithDataHashMeta<T>>
|
|
12
|
-
|
|
13
|
-
export const isDataHashMeta = (value: unknown): value is DataHashMeta => {
|
|
14
|
-
return isHash((value as WithDataHashMeta)?._dataHash)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const asDataHashMeta = AsObjectFactory.create<DataHashMeta>(isDataHashMeta)
|
|
18
|
-
export const asOptionalDataHashMeta = AsObjectFactory.createOptional<DataHashMeta>(isDataHashMeta)
|
|
19
|
-
|
|
20
|
-
/** @deprecated use DataHashMeta instead */
|
|
21
|
-
export interface DataHashStorageMeta extends DataHashMeta {}
|
|
22
|
-
|
|
23
|
-
/** @deprecated use WithDataHashMeta instead */
|
|
24
|
-
export type WithDataHashStorageMeta<T extends Payload = Payload> = WithDataHashMeta<T>
|
|
25
|
-
|
|
26
|
-
/** @deprecated use WithPartialDataHashMeta instead */
|
|
27
|
-
export type WithPartialDataHashStorageMeta<T extends Payload = Payload> = WithPartialDataHashMeta<T>
|
|
28
|
-
|
|
29
|
-
/** @deprecated use isDataHashMeta instead */
|
|
30
|
-
export const isDataHashStorageMeta = isDataHashMeta
|
|
31
|
-
|
|
32
|
-
/** @deprecated use asDataHashMeta instead */
|
|
33
|
-
export const asDataHashStorageMeta = asDataHashMeta
|
|
34
|
-
|
|
35
|
-
/** @deprecated use asOptionalDataHashMeta instead */
|
|
36
|
-
export const asOptionalDataHashStorageMeta = asOptionalDataHashMeta
|
package/src/StorageMeta/Hash.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import { AsObjectFactory, isHash } from '@xylabs/sdk-js'
|
|
3
|
-
|
|
4
|
-
import type { Payload } from '../Payload.ts'
|
|
5
|
-
import type { DataHashMeta } from './DataHash.ts'
|
|
6
|
-
import { isDataHashMeta } from './DataHash.ts'
|
|
7
|
-
|
|
8
|
-
export interface HashMeta extends DataHashMeta {
|
|
9
|
-
_hash: Hash
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type WithHashMeta<T extends Payload = Payload> = T & HashMeta
|
|
13
|
-
export type WithPartialHashMeta<T extends Payload = Payload> = Partial<WithHashMeta<T>>
|
|
14
|
-
|
|
15
|
-
export const isHashMeta = (value: unknown): value is HashMeta => {
|
|
16
|
-
return isDataHashMeta(value) && isHash((value as WithHashMeta)?._hash)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const asHashMeta = AsObjectFactory.create<HashMeta>(isHashMeta)
|
|
20
|
-
export const asOptionalHashMeta = AsObjectFactory.createOptional<HashMeta>(isHashMeta)
|
|
21
|
-
|
|
22
|
-
/** @deprecated use HashMeta instead */
|
|
23
|
-
export interface HashStorageMeta extends HashMeta {}
|
|
24
|
-
|
|
25
|
-
/** @deprecated use WithHashMeta instead */
|
|
26
|
-
export type WithHashStorageMeta<T extends Payload = Payload> = WithHashMeta<T>
|
|
27
|
-
|
|
28
|
-
/** @deprecated use WithPartialHashMeta instead */
|
|
29
|
-
export type WithPartialHashStorageMeta<T extends Payload = Payload> = Partial<WithHashMeta<T>>
|
|
30
|
-
|
|
31
|
-
/** @deprecated use isHashMeta instead */
|
|
32
|
-
export const isHashStorageMeta = isHashMeta
|
|
33
|
-
|
|
34
|
-
/** @deprecated use asHashMeta instead */
|
|
35
|
-
export const asHashStorageMeta = asHashMeta
|
|
36
|
-
|
|
37
|
-
/** @deprecated use asOptionalHashMeta instead */
|
|
38
|
-
export const asOptionalHashStorageMeta = asOptionalHashMeta
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { AsObjectFactory } from '@xylabs/sdk-js'
|
|
2
|
-
|
|
3
|
-
import type { Payload } from '../Payload.ts'
|
|
4
|
-
import type { Sequence } from './sequence/index.ts'
|
|
5
|
-
|
|
6
|
-
export interface SequenceStorageMeta {
|
|
7
|
-
_sequence: Sequence
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type WithSequenceStorageMeta<T extends Payload = Payload> = T & SequenceStorageMeta
|
|
11
|
-
export type WithPartialSequenceStorageMeta<T extends Payload = Payload> = Partial<WithSequenceStorageMeta<T>>
|
|
12
|
-
|
|
13
|
-
export const isSequenceStorageMeta = (value: unknown): value is SequenceStorageMeta => {
|
|
14
|
-
return (value as WithSequenceStorageMeta)?._sequence != undefined
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const asSequenceStorageMeta = AsObjectFactory.create(isSequenceStorageMeta)
|
|
18
|
-
export const asOptionalSequenceStorageMeta = AsObjectFactory.createOptional(isSequenceStorageMeta)
|
package/src/StorageMeta/index.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Compare } from '@xylabs/sdk-js'
|
|
2
|
-
|
|
3
|
-
import { SequenceParser } from './Parser.ts'
|
|
4
|
-
import type { Sequence } from './Sequence.ts'
|
|
5
|
-
|
|
6
|
-
const local: Compare<Sequence> = (a, b) => {
|
|
7
|
-
const aa = SequenceParser.from(a)
|
|
8
|
-
const bb = SequenceParser.from(b)
|
|
9
|
-
return aa.localSequence > bb.localSequence ? 1 : aa.localSequence < bb.localSequence ? -1 : 0
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const qualified: Compare<Sequence> = (a, b) => {
|
|
13
|
-
const aa = SequenceParser.from(a)
|
|
14
|
-
const bb = SequenceParser.from(b)
|
|
15
|
-
return aa.qualifiedSequence > bb.qualifiedSequence ? 1 : aa.qualifiedSequence < bb.qualifiedSequence ? -1 : 0
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const SequenceComparer = { local, qualified }
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Address,
|
|
3
|
-
Hash, Hex,
|
|
4
|
-
} from '@xylabs/sdk-js'
|
|
5
|
-
import {
|
|
6
|
-
assertEx,
|
|
7
|
-
isAddress,
|
|
8
|
-
toAddress,
|
|
9
|
-
toHex, toUint8Array,
|
|
10
|
-
} from '@xylabs/sdk-js'
|
|
11
|
-
|
|
12
|
-
import type {
|
|
13
|
-
Epoch, LocalSequence, Nonce, QualifiedSequence,
|
|
14
|
-
Sequence,
|
|
15
|
-
} from './Sequence.ts'
|
|
16
|
-
import {
|
|
17
|
-
isQualifiedSequence, isSequence,
|
|
18
|
-
SequenceConstants,
|
|
19
|
-
} from './Sequence.ts'
|
|
20
|
-
|
|
21
|
-
export class SequenceParser {
|
|
22
|
-
protected static privateConstructorKey = Date.now().toString()
|
|
23
|
-
|
|
24
|
-
private readonly data: Readonly<Uint8Array>
|
|
25
|
-
|
|
26
|
-
protected constructor(privateConstructorKey: string, hex: Hex) {
|
|
27
|
-
assertEx(SequenceParser.privateConstructorKey === privateConstructorKey, () => 'Use create function instead of constructor')
|
|
28
|
-
const paddedHex = toHex(hex, {
|
|
29
|
-
prefix: false,
|
|
30
|
-
bitLength: (hex.length <= SequenceConstants.localSequenceBytes * 2)
|
|
31
|
-
? SequenceConstants.localSequenceBytes * 8
|
|
32
|
-
: SequenceConstants.qualifiedSequenceBytes * 8,
|
|
33
|
-
})
|
|
34
|
-
this.data = toUint8Array(paddedHex)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get address(): Address {
|
|
38
|
-
const start = SequenceConstants.localSequenceBytes
|
|
39
|
-
const end = SequenceConstants.qualifiedSequenceBytes
|
|
40
|
-
return toAddress(this.data.slice(start, end).buffer, { prefix: false })
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get epoch(): Epoch {
|
|
44
|
-
const start = 0
|
|
45
|
-
const end = SequenceConstants.epochBytes
|
|
46
|
-
return toHex(this.data.slice(start, end).buffer, { prefix: false }) as Epoch
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get localSequence(): LocalSequence {
|
|
50
|
-
const start = 0
|
|
51
|
-
const end = SequenceConstants.localSequenceBytes
|
|
52
|
-
return toHex(this.data.slice(start, end).buffer, { prefix: false }) as LocalSequence
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
get nonce(): Nonce {
|
|
56
|
-
const start = SequenceConstants.epochBytes
|
|
57
|
-
const end = SequenceConstants.localSequenceBytes
|
|
58
|
-
return toHex(this.data.slice(start, end).buffer, { prefix: false }) as Nonce
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
get qualifiedSequence(): QualifiedSequence {
|
|
62
|
-
const start = 0
|
|
63
|
-
const end = SequenceConstants.qualifiedSequenceBytes
|
|
64
|
-
return toHex(this.data.slice(start, end).buffer, { prefix: false }) as QualifiedSequence
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
static from(sequence: Sequence, address?: Address): SequenceParser
|
|
68
|
-
static from(timestamp: Hex, hash: Hash, address?: Address): SequenceParser
|
|
69
|
-
static from(timestamp: Hex, hash: Hex, address?: Address): SequenceParser
|
|
70
|
-
static from(timestamp: Hex, nonce: Nonce, address?: Address): SequenceParser
|
|
71
|
-
static from(timestamp: Hex, hash: Hash, index?: number, address?: Address): SequenceParser
|
|
72
|
-
static from(timestamp: Hex, hash: Hex, index?: number, address?: Address): SequenceParser
|
|
73
|
-
static from(timestamp: Hex, nonce: Nonce, index?: number, address?: Address): SequenceParser
|
|
74
|
-
static from(timestamp: number, hash: Hash, address?: Address): SequenceParser
|
|
75
|
-
static from(timestamp: number, hash: Hex, address?: Address): SequenceParser
|
|
76
|
-
static from(timestamp: number, nonce: Nonce, address?: Address): SequenceParser
|
|
77
|
-
static from(timestamp: number, hash: Hash, index?: number, address?: Address): SequenceParser
|
|
78
|
-
static from(timestamp: number, hash: Hex, index?: number, address?: Address): SequenceParser
|
|
79
|
-
static from(timestamp: number, nonce: Nonce, index?: number, address?: Address): SequenceParser
|
|
80
|
-
static from(
|
|
81
|
-
timestampOrSequence: Hex | number,
|
|
82
|
-
nonceOrAddress?: Hex,
|
|
83
|
-
addressOrIndex?: Address | number,
|
|
84
|
-
addressOnly?: Address,
|
|
85
|
-
): SequenceParser {
|
|
86
|
-
const address = typeof addressOrIndex === 'number' ? addressOnly : addressOrIndex
|
|
87
|
-
const index = typeof addressOrIndex === 'number' ? addressOrIndex : undefined
|
|
88
|
-
if (isSequence(timestampOrSequence)) {
|
|
89
|
-
if (nonceOrAddress) {
|
|
90
|
-
assertEx(!isQualifiedSequence(timestampOrSequence), () => 'Providing both a qualified sequence and a address is not allowed')
|
|
91
|
-
assertEx(isAddress(nonceOrAddress), () => 'Invalid address provided')
|
|
92
|
-
return new this(SequenceParser.privateConstructorKey, (timestampOrSequence + address) as Hex)
|
|
93
|
-
}
|
|
94
|
-
return new this(SequenceParser.privateConstructorKey, timestampOrSequence)
|
|
95
|
-
}
|
|
96
|
-
const epoch = SequenceParser.toEpoch(timestampOrSequence)
|
|
97
|
-
const nonce = nonceOrAddress === undefined ? undefined : SequenceParser.toNonce(nonceOrAddress, index)
|
|
98
|
-
const addressHex: Hex = address ? toHex(address, { bitLength: SequenceConstants.addressBytes * 8 }) : SequenceConstants.minAddress
|
|
99
|
-
const hexString = (epoch + nonce + addressHex) as Hex
|
|
100
|
-
assertEx(isSequence(hexString), () => `Invalid sequence [${hexString}] [${epoch}, ${nonce}, ${addressHex}]`)
|
|
101
|
-
return new this(SequenceParser.privateConstructorKey, hexString)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
static parse(value: Hex | string | ArrayBufferLike): SequenceParser {
|
|
105
|
-
const hex = toHex(value)
|
|
106
|
-
if (isSequence(hex)) {
|
|
107
|
-
return new this(SequenceParser.privateConstructorKey, hex)
|
|
108
|
-
}
|
|
109
|
-
throw new Error(`Invalid sequence [${value}]`)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// can convert a short number/hex to an epoch (treats it as the whole value) or extract an epoch from a sequence
|
|
113
|
-
static toEpoch(value: number | Hex | Epoch): Epoch {
|
|
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 (hex.length <= SequenceConstants.epochBytes * 2) {
|
|
120
|
-
return toHex(value, { prefix: false, bitLength: SequenceConstants.epochBytes * 8 }) as Epoch
|
|
121
|
-
}
|
|
122
|
-
if (isSequence(hex)) {
|
|
123
|
-
return hex.slice(0, SequenceConstants.epochBytes * 2) as Epoch
|
|
124
|
-
}
|
|
125
|
-
throw new Error(`Value could not be converted to epoch [${hex}]`)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// can convert a short number/hex to a nonce (treats it as the whole value) or extract an nonce from a sequence
|
|
129
|
-
static toNonce(value: Hash | Hex, index = 0): Nonce {
|
|
130
|
-
assertEx(
|
|
131
|
-
typeof value !== 'number' || Number.isInteger(value),
|
|
132
|
-
() => 'Value must be in integer',
|
|
133
|
-
)
|
|
134
|
-
const hex = toHex(value, { prefix: false })
|
|
135
|
-
if (isSequence(hex)) {
|
|
136
|
-
return hex.slice(SequenceConstants.epochBytes * 2, SequenceConstants.localSequenceBytes * 2) as Nonce
|
|
137
|
-
}
|
|
138
|
-
const hashHex = toHex((hex as string), { prefix: false, bitLength: SequenceConstants.nonceHashBytes * 8 }).slice(-SequenceConstants.nonceHashBytes * 2)
|
|
139
|
-
const indexHex = toHex(index, { prefix: false, bitLength: SequenceConstants.nonceIndexBytes * 8 }).slice(-SequenceConstants.nonceIndexBytes * 2)
|
|
140
|
-
return (indexHex + hashHex).slice(-SequenceConstants.nonceBytes * 2) as Nonce
|
|
141
|
-
}
|
|
142
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Address, Brand, Hex,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import { isHex } from '@xylabs/sdk-js'
|
|
5
|
-
|
|
6
|
-
// we use Exclude to intentionally make the type not equal to string
|
|
7
|
-
export type LocalSequence = Brand<Hex, { __localSequence: true }>
|
|
8
|
-
export type QualifiedSequence = Brand<Hex, { __qualifiedSequence: true }>
|
|
9
|
-
export type Sequence = LocalSequence | QualifiedSequence
|
|
10
|
-
|
|
11
|
-
export type Epoch = Brand<Hex, { __epoch: true }>
|
|
12
|
-
|
|
13
|
-
export const isEpoch = (value: unknown): value is Epoch => {
|
|
14
|
-
return isHex(value) && (value as string).length === SequenceConstants.epochBytes * 2
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type Nonce = Brand<Hex, { __nonce: true }>
|
|
18
|
-
|
|
19
|
-
export const isNonce = (value: unknown): value is Nonce => {
|
|
20
|
-
return isHex(value) && (value as string).length === SequenceConstants.nonceBytes * 2
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const isLocalSequence = (value: unknown): value is LocalSequence => {
|
|
24
|
-
return isHex(value) && (value as string).length === SequenceConstants.localSequenceBytes * 2
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const isQualifiedSequence = (value: unknown): value is QualifiedSequence => {
|
|
28
|
-
return isHex(value) && (value as string).length === SequenceConstants.qualifiedSequenceBytes * 2
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const isSequence = (value: unknown): value is Sequence => {
|
|
32
|
-
return isLocalSequence(value) || isQualifiedSequence(value)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const SequenceNonceComponentLengths = {
|
|
36
|
-
nonceIndexBytes: 4,
|
|
37
|
-
nonceHashBytes: 4,
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const SequenceComponentLengths = {
|
|
41
|
-
...SequenceNonceComponentLengths,
|
|
42
|
-
epochBytes: 8,
|
|
43
|
-
nonceBytes: SequenceNonceComponentLengths.nonceIndexBytes + SequenceNonceComponentLengths.nonceHashBytes,
|
|
44
|
-
addressBytes: 20,
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const SequenceComponentMinMax = {
|
|
48
|
-
minEpoch: '0'.repeat(SequenceComponentLengths.epochBytes * 2) as Epoch,
|
|
49
|
-
maxEpoch: 'f'.repeat(SequenceComponentLengths.epochBytes * 2) as Epoch,
|
|
50
|
-
minNonce: '0'.repeat(SequenceComponentLengths.nonceBytes * 2) as Nonce,
|
|
51
|
-
maxNonce: 'f'.repeat(SequenceComponentLengths.nonceBytes * 2) as Nonce,
|
|
52
|
-
minAddress: '0'.repeat(SequenceComponentLengths.addressBytes * 2) as Address,
|
|
53
|
-
maxAddress: 'f'.repeat(SequenceComponentLengths.addressBytes * 2) as Address,
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export const LocalSequenceConstants = {
|
|
57
|
-
...SequenceComponentLengths,
|
|
58
|
-
...SequenceComponentMinMax,
|
|
59
|
-
localSequenceBytes: SequenceComponentLengths.epochBytes + SequenceComponentLengths.nonceBytes,
|
|
60
|
-
minLocalSequence: SequenceComponentMinMax.minEpoch + SequenceComponentMinMax.minNonce as LocalSequence,
|
|
61
|
-
maxLocalSequence: SequenceComponentMinMax.maxEpoch + SequenceComponentMinMax.maxNonce as LocalSequence,
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export const QualifiedSequenceConstants = {
|
|
65
|
-
qualifiedSequenceBytes: LocalSequenceConstants.localSequenceBytes + SequenceComponentLengths.addressBytes,
|
|
66
|
-
minQualifiedSequence: LocalSequenceConstants.minLocalSequence + SequenceComponentMinMax.minAddress as QualifiedSequence,
|
|
67
|
-
maxQualifiedSequence: LocalSequenceConstants.maxLocalSequence + SequenceComponentMinMax.maxAddress as QualifiedSequence,
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export const SequenceConstants = {
|
|
71
|
-
...LocalSequenceConstants,
|
|
72
|
-
...QualifiedSequenceConstants,
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// "11111111111111112222222222222222" is and example of a local sequence string
|
|
76
|
-
|
|
77
|
-
// "111111111111111122222222222222223333333333333333333333333333333333333333" is and example of a local sequence string
|
|
78
|
-
// epoch = "1111111111111111"
|
|
79
|
-
// nonce = "2222222222222222"
|
|
80
|
-
// address = "3333333333333333333333333333333333333333"
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { HexRegExMinMax, toHex } from '@xylabs/sdk-js'
|
|
2
|
-
import z from 'zod'
|
|
3
|
-
|
|
4
|
-
import type { LocalSequence, QualifiedSequence } from './Sequence.ts'
|
|
5
|
-
import { SequenceConstants } from './Sequence.ts'
|
|
6
|
-
|
|
7
|
-
const LocalSequenceRegex = new RegExp(HexRegExMinMax(SequenceConstants.localSequenceBytes, SequenceConstants.localSequenceBytes))
|
|
8
|
-
export const LocalSequenceToStringZod = z.string().regex(LocalSequenceRegex)
|
|
9
|
-
export const LocalSequenceFromStringZod = z.string().regex(LocalSequenceRegex).transform<LocalSequence>(v => toHex(v) as LocalSequence)
|
|
10
|
-
|
|
11
|
-
const QualifiedSequenceRegex = new RegExp(HexRegExMinMax(SequenceConstants.qualifiedSequenceBytes, SequenceConstants.qualifiedSequenceBytes))
|
|
12
|
-
export const QualifiedSequenceToStringZod = z.string().regex(QualifiedSequenceRegex)
|
|
13
|
-
export const QualifiedSequenceFromStringZod = z.string().regex(QualifiedSequenceRegex).transform<QualifiedSequence>(v => toHex(v) as QualifiedSequence)
|
|
14
|
-
|
|
15
|
-
export const SequenceToStringZod = z.union([LocalSequenceToStringZod, QualifiedSequenceToStringZod])
|
|
16
|
-
export const SequenceFromStringZod = z.union([LocalSequenceFromStringZod, QualifiedSequenceFromStringZod])
|
package/src/Timestamp.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { EmptyObject } from '@xylabs/sdk-js'
|
|
2
|
-
|
|
3
|
-
/** Object with a timestamp */
|
|
4
|
-
export interface Timestamp {
|
|
5
|
-
timestamp: number
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/** Add a timestamp field to any object */
|
|
9
|
-
export type WithTimestamp<T extends EmptyObject = EmptyObject> = T & Timestamp
|
package/src/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export * from './Error.ts'
|
|
2
|
-
export * from './isPayloadOfSchemaType.ts'
|
|
3
|
-
export * from './isPayloadOfZodType.ts'
|
|
4
|
-
export * from './Payload.ts'
|
|
5
|
-
export * from './PayloadBundle.ts'
|
|
6
|
-
export * from './PayloadFindFilter.ts'
|
|
7
|
-
export * from './PayloadHashMap.ts'
|
|
8
|
-
export * from './PayloadSet/index.ts'
|
|
9
|
-
export * from './PayloadValidationFunction.ts'
|
|
10
|
-
export * from './PayloadValueExpression.ts'
|
|
11
|
-
export * from './PayloadZod.ts'
|
|
12
|
-
export * from './Query.ts'
|
|
13
|
-
export * from './Schema.ts'
|
|
14
|
-
export * from './StorageMeta/index.ts'
|
|
15
|
-
export * from './Timestamp.ts'
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { Payload, WithSources } from './Payload.ts'
|
|
2
|
-
import { isAnyPayload } from './PayloadZod.ts'
|
|
3
|
-
|
|
4
|
-
export function isPayloadOfSchemaType<T extends Payload | never = never>(schema: T['schema']) {
|
|
5
|
-
return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const isPayloadOfSchemaTypeWithSources = <T extends Payload | never = never>(schema: T['schema']) => {
|
|
9
|
-
return (x?: unknown | null): x is WithSources<T> =>
|
|
10
|
-
isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.$sources != undefined && Array.isArray(x.$sources)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const notPayloadOfSchemaType = <T extends Payload | never = never>(schema: T['schema']) => {
|
|
14
|
-
return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// test types -- keep for future validation, but comment out
|
|
18
|
-
|
|
19
|
-
/*
|
|
20
|
-
type TestSchema = 'network.xyo.test'
|
|
21
|
-
const TestSchema: TestSchema = 'network.xyo.test'
|
|
22
|
-
|
|
23
|
-
type Test = Payload<{ field: string }, TestSchema>
|
|
24
|
-
|
|
25
|
-
const testPayload: Test = { field: 'test', schema: TestSchema }
|
|
26
|
-
|
|
27
|
-
const testPayloads: Payload[] = [testPayload]
|
|
28
|
-
|
|
29
|
-
const isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType<Payload>(TestSchema))
|
|
30
|
-
|
|
31
|
-
const isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))
|
|
32
|
-
*/
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { isDefined } from '@xylabs/sdk-js'
|
|
2
|
-
import type { ZodObject } from 'zod'
|
|
3
|
-
|
|
4
|
-
import type { Payload } from './Payload.ts'
|
|
5
|
-
import { isAnyPayload } from './PayloadZod.ts'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Checks if a value is a payload of a specific Zod type.
|
|
9
|
-
* @param zodSchema The Zod schema to validate against
|
|
10
|
-
* @param schema The schema string to match against the payload. Optional in
|
|
11
|
-
* case you want to validate any payload matching the Zod schema or in case
|
|
12
|
-
* schema is part of the Zod schema.
|
|
13
|
-
* @returns A function that checks if a value is a payload of the specified Zod type
|
|
14
|
-
*/
|
|
15
|
-
export function isPayloadOfZodType<
|
|
16
|
-
T extends Payload | never = never,
|
|
17
|
-
S extends ZodObject = ZodObject,
|
|
18
|
-
>(zodSchema: S, schema?: T['schema']) {
|
|
19
|
-
return (x?: unknown | null): x is T => {
|
|
20
|
-
if (!isAnyPayload(x)) return false
|
|
21
|
-
if (isDefined(schema) && x.schema !== schema) return false
|
|
22
|
-
const { schema: _, ...data } = x
|
|
23
|
-
return zodSchema.safeParse(data).success
|
|
24
|
-
}
|
|
25
|
-
}
|
package/src/types.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
-
export interface Array<T> {
|
|
4
|
-
filter<T extends S>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]
|
|
5
|
-
find<T extends S>(predicate: (value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined
|
|
6
|
-
}
|