@xyo-network/payload-model 3.6.0-rc.2 → 3.6.0-rc.4

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.
@@ -5,8 +5,8 @@ export declare const PayloadSchema: "network.xyo.payload";
5
5
  export type PayloadSchema = typeof PayloadSchema;
6
6
  export declare const isSchema: (value: unknown) => value is Schema;
7
7
  export declare const asSchema: {
8
- <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.12-5822811789/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
9
- <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.12-5822811789/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<string>, config?: import("@xylabs/object").TypeCheckConfig): TType;
8
+ <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
9
+ <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<string>, config?: import("@xylabs/object").TypeCheckConfig): TType;
10
10
  };
11
11
  /** Schema fields for a Payload */
12
12
  export interface SchemaFields extends EmptyObject {
@@ -1,9 +1,17 @@
1
- import type { Hash, Hex } from '@xylabs/hex';
1
+ import { type Hash, type Hex } from '@xylabs/hex';
2
2
  import type { Payload } from './Payload.ts';
3
- export interface StorageMeta {
3
+ export interface SequenceMeta {
4
+ _sequence: Hex;
5
+ }
6
+ export type WithPartialSequenceMeta<T extends Payload = Payload> = Partial<WithSequenceMeta<T>>;
7
+ export type WithSequenceMeta<T extends Payload = Payload> = T & SequenceMeta;
8
+ export interface HashMeta {
4
9
  _dataHash: Hash;
5
10
  _hash: Hash;
6
- _sequence: Hex;
11
+ }
12
+ export type WithPartialHashMeta<T extends Payload = Payload> = Partial<WithHashMeta<T>>;
13
+ export type WithHashMeta<T extends Payload = Payload> = T & HashMeta;
14
+ export interface StorageMeta extends SequenceMeta, HashMeta {
7
15
  }
8
16
  export type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>;
9
17
  export type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta;
@@ -13,6 +21,13 @@ export declare const StorageMetaConstants: {
13
21
  addressBytes: number;
14
22
  maxEpoch: number;
15
23
  localSequenceBytes: number;
24
+ minLocalSequence: Hex;
25
+ maxLocalSequence: Hex;
16
26
  qualifiedSequenceBytes: number;
27
+ minSequence: Hex;
28
+ maxSequence: Hex;
17
29
  };
30
+ export declare const isSequenceMeta: (value: unknown) => value is SequenceMeta;
31
+ export declare const isHashMeta: (value: unknown) => value is HashMeta;
32
+ export declare const isStorageMeta: (value: unknown) => value is StorageMeta;
18
33
  //# sourceMappingURL=StorageMeta.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"StorageMeta.d.ts","sourceRoot":"","sources":["../../src/StorageMeta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAE5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,IAAI,CAAA;IACf,KAAK,EAAE,IAAI,CAAA;IAEX,SAAS,EAAE,GAAG,CAAA;CACf;AAED,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAA;AAE7F,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,CAAC,GAAG,WAAW,CAAA;AAc1E,eAAO,MAAM,oBAAoB;;;;;;;CAGhC,CAAA"}
1
+ {"version":3,"file":"StorageMeta.d.ts","sourceRoot":"","sources":["../../src/StorageMeta.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,EAAE,KAAK,GAA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+42,9 @@ var isSchema = (value) => {
42
42
  var asSchema = AsTypeFactory.create(isSchema);
43
43
 
44
44
  // src/StorageMeta.ts
45
+ import {
46
+ isHash
47
+ } from "@xylabs/hex";
45
48
  var StorageMetaComponentConstants = {
46
49
  epochBytes: 8,
47
50
  nonceBytes: 8,
@@ -50,12 +53,25 @@ var StorageMetaComponentConstants = {
50
53
  var StorageMetaLocalConstants = {
51
54
  maxEpoch: Math.pow(256, StorageMetaComponentConstants.epochBytes) - 1,
52
55
  localSequenceBytes: StorageMetaComponentConstants.epochBytes + StorageMetaComponentConstants.nonceBytes,
56
+ minLocalSequence: "00000000000000000000000000000000",
57
+ maxLocalSequence: "ffffffffffffffffffffffffffffffff",
53
58
  ...StorageMetaComponentConstants
54
59
  };
55
60
  var StorageMetaConstants = {
56
61
  qualifiedSequenceBytes: StorageMetaLocalConstants.localSequenceBytes + StorageMetaComponentConstants.addressBytes,
62
+ minSequence: `${StorageMetaLocalConstants}0000000000000000000000000000000000000000`,
63
+ maxSequence: `${StorageMetaLocalConstants}ffffffffffffffffffffffffffffffffffffffff`,
57
64
  ...StorageMetaLocalConstants
58
65
  };
66
+ var isSequenceMeta = (value) => {
67
+ return value?._sequence !== void 0;
68
+ };
69
+ var isHashMeta = (value) => {
70
+ return isHash(value?._hash) && isHash(value?._dataHash);
71
+ };
72
+ var isStorageMeta = (value) => {
73
+ return isSequenceMeta(value) && isHashMeta(value);
74
+ };
59
75
  export {
60
76
  ModuleErrorSchema,
61
77
  PayloadSchema,
@@ -65,11 +81,14 @@ export {
65
81
  asPayload,
66
82
  asSchema,
67
83
  isAnyPayload,
84
+ isHashMeta,
68
85
  isModuleError,
69
86
  isPayload,
70
87
  isPayloadOfSchemaType,
71
88
  isPayloadOfSchemaTypeWithSources,
72
89
  isSchema,
90
+ isSequenceMeta,
91
+ isStorageMeta,
73
92
  notPayloadOfSchemaType
74
93
  };
75
94
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts","../../src/StorageMeta.ts"],"sourcesContent":["import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport type { Payload } from './Payload.ts'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload\n = <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.ts'\nimport type { Payload, WithSources } from './Payload.ts'\n\nexport const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithSources<T> =>\n isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.sources !== undefined && Array.isArray(x.sources)\n}\n\nexport const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n\n// test types -- keep for future validation, but comment out\n\n/*\ntype TestSchema = 'network.xyo.test'\nconst TestSchema: TestSchema = 'network.xyo.test'\n\ntype Test = Payload<{ field: string }, TestSchema>\n\nconst testPayload: Test = { field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n*/\n","import type { Hash } from '@xylabs/hex'\nimport type { JsonValue } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.ts'\nimport type { Payload } from './Payload.ts'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import type { EmptyObject } from '@xylabs/object'\nimport { AsTypeFactory } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n return typeof value === 'string'\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n","import type { Hash, Hex } from '@xylabs/hex'\n\nimport type { Payload } from './Payload.ts'\n\nexport interface StorageMeta {\n _dataHash: Hash\n _hash: Hash\n // this sequence number must be a 0 padded string representation of a 18 byte sequence number\n _sequence: Hex // zero padded epoch/index (when returned, has address as suffix) - to be used as a universal cursor\n}\n\nexport type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>\n\nexport type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta\n\nconst StorageMetaComponentConstants = {\n epochBytes: 8,\n nonceBytes: 8,\n addressBytes: 20,\n}\n\nconst StorageMetaLocalConstants = {\n maxEpoch: Math.pow(256, StorageMetaComponentConstants.epochBytes) - 1,\n localSequenceBytes: StorageMetaComponentConstants.epochBytes + StorageMetaComponentConstants.nonceBytes,\n ...StorageMetaComponentConstants,\n}\n\nexport const StorageMetaConstants = {\n qualifiedSequenceBytes: StorageMetaLocalConstants.localSequenceBytes + StorageMetaComponentConstants.addressBytes,\n ...StorageMetaLocalConstants,\n}\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14\" is and example of a local sequence string\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14a123456789abcdef0123\" is and example of a local sequence string\n// epoch = \"00005a7f354762f3ac\"\n// nonce = \"1bc5ddc6cfd08d14\"\n// address = \"a123456789abcdef0123\"\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAgB;AAInC,IAAM,eAAe,CAAC,UAAqC;AAChE,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,OAAO,MAAM,WAAW;AAAA,EACjC;AACA,SAAO;AACT;AAEO,IAAM,eAAe,gBAAgB,OAAO,YAAY;AAExD,IAAM,YACT,CAAoB,WACpB,CAAC,UAA+B;AAC9B,MAAI,aAAa,KAAK,GAAG;AACvB,WAAO,OAAO,SAAS,MAAM,MAAM;AAAA,EACrC;AACA,SAAO;AACT;AAEG,IAAM,YAAY,CAAoB,WAAqB,gBAAgB,OAAO,CAAC,UAA+B,UAAU,MAAM,EAAE,KAAK,CAAC;;;ACnB1I,IAAM,wBAAwB,CAAoB,WAAmB;AAC1E,SAAO,CAAC,MAA+B,aAAa,CAAC,KAAK,GAAG,WAAW;AAC1E;AAEO,IAAM,mCAAmC,CAAoB,WAAmB;AACrF,SAAO,CAAC,MACN,sBAAsC,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,UAAa,MAAM,QAAQ,EAAE,OAAO;AAC1G;AAEO,IAAM,yBAAyB,CAAoB,WAAmB;AAC3E,SAAO,CAAC,MAA+B,CAAC,aAAa,CAAC,KAAK,GAAG,WAAW;AAC3E;;;ACPO,IAAM,oBAAuC;AAW7C,IAAM,gBAAgB,sBAAmC,iBAAiB;;;ACjB1E,IAAM,mBAAqC;;;ACAlD,SAAS,qBAAqB;AAKvB,IAAM,gBAAgB;AAGtB,IAAM,WAAW,CAAC,UAAoC;AAC3D,SAAO,OAAO,UAAU;AAC1B;AAEO,IAAM,WAAW,cAAc,OAAe,QAAQ;;;ACE7D,IAAM,gCAAgC;AAAA,EACpC,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,cAAc;AAChB;AAEA,IAAM,4BAA4B;AAAA,EAChC,UAAU,KAAK,IAAI,KAAK,8BAA8B,UAAU,IAAI;AAAA,EACpE,oBAAoB,8BAA8B,aAAa,8BAA8B;AAAA,EAC7F,GAAG;AACL;AAEO,IAAM,uBAAuB;AAAA,EAClC,wBAAwB,0BAA0B,qBAAqB,8BAA8B;AAAA,EACrG,GAAG;AACL;","names":[]}
1
+ {"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts","../../src/StorageMeta.ts"],"sourcesContent":["import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport type { Payload } from './Payload.ts'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload\n = <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.ts'\nimport type { Payload, WithSources } from './Payload.ts'\n\nexport const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithSources<T> =>\n isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.sources !== undefined && Array.isArray(x.sources)\n}\n\nexport const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n\n// test types -- keep for future validation, but comment out\n\n/*\ntype TestSchema = 'network.xyo.test'\nconst TestSchema: TestSchema = 'network.xyo.test'\n\ntype Test = Payload<{ field: string }, TestSchema>\n\nconst testPayload: Test = { field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n*/\n","import type { Hash } from '@xylabs/hex'\nimport type { JsonValue } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.ts'\nimport type { Payload } from './Payload.ts'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import type { EmptyObject } from '@xylabs/object'\nimport { AsTypeFactory } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n return typeof value === 'string'\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n","import {\n type Hash, type Hex, isHash,\n} from '@xylabs/hex'\n\nimport type { Payload } from './Payload.ts'\n\nexport interface SequenceMeta {\n _sequence: Hex\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\nconst StorageMetaComponentConstants = {\n epochBytes: 8,\n nonceBytes: 8,\n addressBytes: 20,\n}\n\nconst StorageMetaLocalConstants = {\n maxEpoch: Math.pow(256, StorageMetaComponentConstants.epochBytes) - 1,\n localSequenceBytes: StorageMetaComponentConstants.epochBytes + StorageMetaComponentConstants.nonceBytes,\n minLocalSequence: '00000000000000000000000000000000' as Hex,\n maxLocalSequence: 'ffffffffffffffffffffffffffffffff' as Hex,\n ...StorageMetaComponentConstants,\n}\n\nexport const StorageMetaConstants = {\n qualifiedSequenceBytes: StorageMetaLocalConstants.localSequenceBytes + StorageMetaComponentConstants.addressBytes,\n minSequence: `${StorageMetaLocalConstants}0000000000000000000000000000000000000000` as Hex,\n maxSequence: `${StorageMetaLocalConstants}ffffffffffffffffffffffffffffffffffffffff` as Hex,\n ...StorageMetaLocalConstants,\n}\n\nexport const isSequenceMeta = (value: unknown): value is SequenceMeta => {\n return (value as WithSequenceMeta)?._sequence !== undefined\n}\n\nexport const isHashMeta = (value: unknown): value is HashMeta => {\n return isHash((value as WithHashMeta)?._hash) && isHash((value as WithHashMeta)?._dataHash)\n}\n\nexport const isStorageMeta = (value: unknown): value is StorageMeta => {\n return isSequenceMeta(value) && isHashMeta(value)\n}\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14\" is and example of a local sequence string\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14a123456789abcdef0123\" is and example of a local sequence string\n// epoch = \"00005a7f354762f3ac\"\n// nonce = \"1bc5ddc6cfd08d14\"\n// address = \"a123456789abcdef0123\"\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAgB;AAInC,IAAM,eAAe,CAAC,UAAqC;AAChE,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,OAAO,MAAM,WAAW;AAAA,EACjC;AACA,SAAO;AACT;AAEO,IAAM,eAAe,gBAAgB,OAAO,YAAY;AAExD,IAAM,YACT,CAAoB,WACpB,CAAC,UAA+B;AAC9B,MAAI,aAAa,KAAK,GAAG;AACvB,WAAO,OAAO,SAAS,MAAM,MAAM;AAAA,EACrC;AACA,SAAO;AACT;AAEG,IAAM,YAAY,CAAoB,WAAqB,gBAAgB,OAAO,CAAC,UAA+B,UAAU,MAAM,EAAE,KAAK,CAAC;;;ACnB1I,IAAM,wBAAwB,CAAoB,WAAmB;AAC1E,SAAO,CAAC,MAA+B,aAAa,CAAC,KAAK,GAAG,WAAW;AAC1E;AAEO,IAAM,mCAAmC,CAAoB,WAAmB;AACrF,SAAO,CAAC,MACN,sBAAsC,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,UAAa,MAAM,QAAQ,EAAE,OAAO;AAC1G;AAEO,IAAM,yBAAyB,CAAoB,WAAmB;AAC3E,SAAO,CAAC,MAA+B,CAAC,aAAa,CAAC,KAAK,GAAG,WAAW;AAC3E;;;ACPO,IAAM,oBAAuC;AAW7C,IAAM,gBAAgB,sBAAmC,iBAAiB;;;ACjB1E,IAAM,mBAAqC;;;ACAlD,SAAS,qBAAqB;AAKvB,IAAM,gBAAgB;AAGtB,IAAM,WAAW,CAAC,UAAoC;AAC3D,SAAO,OAAO,UAAU;AAC1B;AAEO,IAAM,WAAW,cAAc,OAAe,QAAQ;;;ACb7D;AAAA,EACuB;AAAA,OAChB;AA2BP,IAAM,gCAAgC;AAAA,EACpC,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,cAAc;AAChB;AAEA,IAAM,4BAA4B;AAAA,EAChC,UAAU,KAAK,IAAI,KAAK,8BAA8B,UAAU,IAAI;AAAA,EACpE,oBAAoB,8BAA8B,aAAa,8BAA8B;AAAA,EAC7F,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,GAAG;AACL;AAEO,IAAM,uBAAuB;AAAA,EAClC,wBAAwB,0BAA0B,qBAAqB,8BAA8B;AAAA,EACrG,aAAa,GAAG,yBAAyB;AAAA,EACzC,aAAa,GAAG,yBAAyB;AAAA,EACzC,GAAG;AACL;AAEO,IAAM,iBAAiB,CAAC,UAA0C;AACvE,SAAQ,OAA4B,cAAc;AACpD;AAEO,IAAM,aAAa,CAAC,UAAsC;AAC/D,SAAO,OAAQ,OAAwB,KAAK,KAAK,OAAQ,OAAwB,SAAS;AAC5F;AAEO,IAAM,gBAAgB,CAAC,UAAyC;AACrE,SAAO,eAAe,KAAK,KAAK,WAAW,KAAK;AAClD;","names":[]}
@@ -3,16 +3,16 @@ export declare const isAnyPayload: (value: unknown) => value is Payload;
3
3
  export declare const asAnyPayload: {
4
4
  <TType extends {
5
5
  schema: string;
6
- } & import("./Payload.ts").PayloadFields>(value: import(".store/@xylabs-promise-npm-4.4.12-5822811789/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
6
+ } & import("./Payload.ts").PayloadFields>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
7
7
  <TType extends {
8
8
  schema: string;
9
- } & import("./Payload.ts").PayloadFields>(value: import(".store/@xylabs-promise-npm-4.4.12-5822811789/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<{
9
+ } & import("./Payload.ts").PayloadFields>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<{
10
10
  schema: string;
11
11
  } & import("./Payload.ts").PayloadFields>, 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.12-5822811789/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
16
- <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.12-5822811789/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
15
+ <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
16
+ <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
17
17
  };
18
18
  //# sourceMappingURL=isPayload.d.ts.map
@@ -5,8 +5,8 @@ export declare const PayloadSchema: "network.xyo.payload";
5
5
  export type PayloadSchema = typeof PayloadSchema;
6
6
  export declare const isSchema: (value: unknown) => value is Schema;
7
7
  export declare const asSchema: {
8
- <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.12-5822811789/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
9
- <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.12-5822811789/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<string>, config?: import("@xylabs/object").TypeCheckConfig): TType;
8
+ <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
9
+ <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<string>, config?: import("@xylabs/object").TypeCheckConfig): TType;
10
10
  };
11
11
  /** Schema fields for a Payload */
12
12
  export interface SchemaFields extends EmptyObject {
@@ -1,9 +1,17 @@
1
- import type { Hash, Hex } from '@xylabs/hex';
1
+ import { type Hash, type Hex } from '@xylabs/hex';
2
2
  import type { Payload } from './Payload.ts';
3
- export interface StorageMeta {
3
+ export interface SequenceMeta {
4
+ _sequence: Hex;
5
+ }
6
+ export type WithPartialSequenceMeta<T extends Payload = Payload> = Partial<WithSequenceMeta<T>>;
7
+ export type WithSequenceMeta<T extends Payload = Payload> = T & SequenceMeta;
8
+ export interface HashMeta {
4
9
  _dataHash: Hash;
5
10
  _hash: Hash;
6
- _sequence: Hex;
11
+ }
12
+ export type WithPartialHashMeta<T extends Payload = Payload> = Partial<WithHashMeta<T>>;
13
+ export type WithHashMeta<T extends Payload = Payload> = T & HashMeta;
14
+ export interface StorageMeta extends SequenceMeta, HashMeta {
7
15
  }
8
16
  export type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>;
9
17
  export type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta;
@@ -13,6 +21,13 @@ export declare const StorageMetaConstants: {
13
21
  addressBytes: number;
14
22
  maxEpoch: number;
15
23
  localSequenceBytes: number;
24
+ minLocalSequence: Hex;
25
+ maxLocalSequence: Hex;
16
26
  qualifiedSequenceBytes: number;
27
+ minSequence: Hex;
28
+ maxSequence: Hex;
17
29
  };
30
+ export declare const isSequenceMeta: (value: unknown) => value is SequenceMeta;
31
+ export declare const isHashMeta: (value: unknown) => value is HashMeta;
32
+ export declare const isStorageMeta: (value: unknown) => value is StorageMeta;
18
33
  //# sourceMappingURL=StorageMeta.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"StorageMeta.d.ts","sourceRoot":"","sources":["../../src/StorageMeta.ts"],"names":[],"mappings":"AA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AAG,OAAO,IAAI,CAAC,GAAG,QAAQ,CAAA;AAEpE,MAAM,WAAW,WAAY,SAAQ,YAAY,EAAE,QAAQ;CAAG;AAE9D,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAA;AAE7F,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,CAAC,GAAG,WAAW,CAAA;AAgB1E,eAAO,MAAM,oBAAoB;;;;;;sBALyB,GAAG;sBACH,GAAG;;iBAM4B,GAAG;iBACH,GAAG;CAE3F,CAAA;AAED,eAAO,MAAM,cAAc,UAAW,OAAO,KAAG,KAAK,IAAI,YAExD,CAAA;AAED,eAAO,MAAM,UAAU,UAAW,OAAO,KAAG,KAAK,IAAI,QAEpD,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,OAAO,KAAG,KAAK,IAAI,WAEvD,CAAA"}
@@ -42,6 +42,9 @@ var isSchema = (value) => {
42
42
  var asSchema = AsTypeFactory.create(isSchema);
43
43
 
44
44
  // src/StorageMeta.ts
45
+ import {
46
+ isHash
47
+ } from "@xylabs/hex";
45
48
  var StorageMetaComponentConstants = {
46
49
  epochBytes: 8,
47
50
  nonceBytes: 8,
@@ -50,12 +53,25 @@ var StorageMetaComponentConstants = {
50
53
  var StorageMetaLocalConstants = {
51
54
  maxEpoch: Math.pow(256, StorageMetaComponentConstants.epochBytes) - 1,
52
55
  localSequenceBytes: StorageMetaComponentConstants.epochBytes + StorageMetaComponentConstants.nonceBytes,
56
+ minLocalSequence: "00000000000000000000000000000000",
57
+ maxLocalSequence: "ffffffffffffffffffffffffffffffff",
53
58
  ...StorageMetaComponentConstants
54
59
  };
55
60
  var StorageMetaConstants = {
56
61
  qualifiedSequenceBytes: StorageMetaLocalConstants.localSequenceBytes + StorageMetaComponentConstants.addressBytes,
62
+ minSequence: `${StorageMetaLocalConstants}0000000000000000000000000000000000000000`,
63
+ maxSequence: `${StorageMetaLocalConstants}ffffffffffffffffffffffffffffffffffffffff`,
57
64
  ...StorageMetaLocalConstants
58
65
  };
66
+ var isSequenceMeta = (value) => {
67
+ return value?._sequence !== void 0;
68
+ };
69
+ var isHashMeta = (value) => {
70
+ return isHash(value?._hash) && isHash(value?._dataHash);
71
+ };
72
+ var isStorageMeta = (value) => {
73
+ return isSequenceMeta(value) && isHashMeta(value);
74
+ };
59
75
  export {
60
76
  ModuleErrorSchema,
61
77
  PayloadSchema,
@@ -65,11 +81,14 @@ export {
65
81
  asPayload,
66
82
  asSchema,
67
83
  isAnyPayload,
84
+ isHashMeta,
68
85
  isModuleError,
69
86
  isPayload,
70
87
  isPayloadOfSchemaType,
71
88
  isPayloadOfSchemaTypeWithSources,
72
89
  isSchema,
90
+ isSequenceMeta,
91
+ isStorageMeta,
73
92
  notPayloadOfSchemaType
74
93
  };
75
94
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts","../../src/StorageMeta.ts"],"sourcesContent":["import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport type { Payload } from './Payload.ts'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload\n = <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.ts'\nimport type { Payload, WithSources } from './Payload.ts'\n\nexport const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithSources<T> =>\n isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.sources !== undefined && Array.isArray(x.sources)\n}\n\nexport const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n\n// test types -- keep for future validation, but comment out\n\n/*\ntype TestSchema = 'network.xyo.test'\nconst TestSchema: TestSchema = 'network.xyo.test'\n\ntype Test = Payload<{ field: string }, TestSchema>\n\nconst testPayload: Test = { field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n*/\n","import type { Hash } from '@xylabs/hex'\nimport type { JsonValue } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.ts'\nimport type { Payload } from './Payload.ts'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import type { EmptyObject } from '@xylabs/object'\nimport { AsTypeFactory } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n return typeof value === 'string'\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n","import type { Hash, Hex } from '@xylabs/hex'\n\nimport type { Payload } from './Payload.ts'\n\nexport interface StorageMeta {\n _dataHash: Hash\n _hash: Hash\n // this sequence number must be a 0 padded string representation of a 18 byte sequence number\n _sequence: Hex // zero padded epoch/index (when returned, has address as suffix) - to be used as a universal cursor\n}\n\nexport type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>\n\nexport type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta\n\nconst StorageMetaComponentConstants = {\n epochBytes: 8,\n nonceBytes: 8,\n addressBytes: 20,\n}\n\nconst StorageMetaLocalConstants = {\n maxEpoch: Math.pow(256, StorageMetaComponentConstants.epochBytes) - 1,\n localSequenceBytes: StorageMetaComponentConstants.epochBytes + StorageMetaComponentConstants.nonceBytes,\n ...StorageMetaComponentConstants,\n}\n\nexport const StorageMetaConstants = {\n qualifiedSequenceBytes: StorageMetaLocalConstants.localSequenceBytes + StorageMetaComponentConstants.addressBytes,\n ...StorageMetaLocalConstants,\n}\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14\" is and example of a local sequence string\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14a123456789abcdef0123\" is and example of a local sequence string\n// epoch = \"00005a7f354762f3ac\"\n// nonce = \"1bc5ddc6cfd08d14\"\n// address = \"a123456789abcdef0123\"\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAgB;AAInC,IAAM,eAAe,CAAC,UAAqC;AAChE,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,OAAO,MAAM,WAAW;AAAA,EACjC;AACA,SAAO;AACT;AAEO,IAAM,eAAe,gBAAgB,OAAO,YAAY;AAExD,IAAM,YACT,CAAoB,WACpB,CAAC,UAA+B;AAC9B,MAAI,aAAa,KAAK,GAAG;AACvB,WAAO,OAAO,SAAS,MAAM,MAAM;AAAA,EACrC;AACA,SAAO;AACT;AAEG,IAAM,YAAY,CAAoB,WAAqB,gBAAgB,OAAO,CAAC,UAA+B,UAAU,MAAM,EAAE,KAAK,CAAC;;;ACnB1I,IAAM,wBAAwB,CAAoB,WAAmB;AAC1E,SAAO,CAAC,MAA+B,aAAa,CAAC,KAAK,GAAG,WAAW;AAC1E;AAEO,IAAM,mCAAmC,CAAoB,WAAmB;AACrF,SAAO,CAAC,MACN,sBAAsC,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,UAAa,MAAM,QAAQ,EAAE,OAAO;AAC1G;AAEO,IAAM,yBAAyB,CAAoB,WAAmB;AAC3E,SAAO,CAAC,MAA+B,CAAC,aAAa,CAAC,KAAK,GAAG,WAAW;AAC3E;;;ACPO,IAAM,oBAAuC;AAW7C,IAAM,gBAAgB,sBAAmC,iBAAiB;;;ACjB1E,IAAM,mBAAqC;;;ACAlD,SAAS,qBAAqB;AAKvB,IAAM,gBAAgB;AAGtB,IAAM,WAAW,CAAC,UAAoC;AAC3D,SAAO,OAAO,UAAU;AAC1B;AAEO,IAAM,WAAW,cAAc,OAAe,QAAQ;;;ACE7D,IAAM,gCAAgC;AAAA,EACpC,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,cAAc;AAChB;AAEA,IAAM,4BAA4B;AAAA,EAChC,UAAU,KAAK,IAAI,KAAK,8BAA8B,UAAU,IAAI;AAAA,EACpE,oBAAoB,8BAA8B,aAAa,8BAA8B;AAAA,EAC7F,GAAG;AACL;AAEO,IAAM,uBAAuB;AAAA,EAClC,wBAAwB,0BAA0B,qBAAqB,8BAA8B;AAAA,EACrG,GAAG;AACL;","names":[]}
1
+ {"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts","../../src/StorageMeta.ts"],"sourcesContent":["import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport type { Payload } from './Payload.ts'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload\n = <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.ts'\nimport type { Payload, WithSources } from './Payload.ts'\n\nexport const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithSources<T> =>\n isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.sources !== undefined && Array.isArray(x.sources)\n}\n\nexport const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n\n// test types -- keep for future validation, but comment out\n\n/*\ntype TestSchema = 'network.xyo.test'\nconst TestSchema: TestSchema = 'network.xyo.test'\n\ntype Test = Payload<{ field: string }, TestSchema>\n\nconst testPayload: Test = { field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n*/\n","import type { Hash } from '@xylabs/hex'\nimport type { JsonValue } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.ts'\nimport type { Payload } from './Payload.ts'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import type { EmptyObject } from '@xylabs/object'\nimport { AsTypeFactory } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n return typeof value === 'string'\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n","import {\n type Hash, type Hex, isHash,\n} from '@xylabs/hex'\n\nimport type { Payload } from './Payload.ts'\n\nexport interface SequenceMeta {\n _sequence: Hex\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\nconst StorageMetaComponentConstants = {\n epochBytes: 8,\n nonceBytes: 8,\n addressBytes: 20,\n}\n\nconst StorageMetaLocalConstants = {\n maxEpoch: Math.pow(256, StorageMetaComponentConstants.epochBytes) - 1,\n localSequenceBytes: StorageMetaComponentConstants.epochBytes + StorageMetaComponentConstants.nonceBytes,\n minLocalSequence: '00000000000000000000000000000000' as Hex,\n maxLocalSequence: 'ffffffffffffffffffffffffffffffff' as Hex,\n ...StorageMetaComponentConstants,\n}\n\nexport const StorageMetaConstants = {\n qualifiedSequenceBytes: StorageMetaLocalConstants.localSequenceBytes + StorageMetaComponentConstants.addressBytes,\n minSequence: `${StorageMetaLocalConstants}0000000000000000000000000000000000000000` as Hex,\n maxSequence: `${StorageMetaLocalConstants}ffffffffffffffffffffffffffffffffffffffff` as Hex,\n ...StorageMetaLocalConstants,\n}\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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F;AAEO,IAAM,gBAAgB,CAAC,UAAyC;AACrE,SAAO,eAAe,KAAK,KAAK,WAAW,KAAK;AAClD;","names":[]}
@@ -3,16 +3,16 @@ export declare const isAnyPayload: (value: unknown) => value is Payload;
3
3
  export declare const asAnyPayload: {
4
4
  <TType extends {
5
5
  schema: string;
6
- } & import("./Payload.ts").PayloadFields>(value: import(".store/@xylabs-promise-npm-4.4.12-5822811789/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
6
+ } & import("./Payload.ts").PayloadFields>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
7
7
  <TType extends {
8
8
  schema: string;
9
- } & import("./Payload.ts").PayloadFields>(value: import(".store/@xylabs-promise-npm-4.4.12-5822811789/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<{
9
+ } & import("./Payload.ts").PayloadFields>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<{
10
10
  schema: string;
11
11
  } & import("./Payload.ts").PayloadFields>, 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.12-5822811789/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
16
- <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.12-5822811789/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
15
+ <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
16
+ <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
17
17
  };
18
18
  //# sourceMappingURL=isPayload.d.ts.map
@@ -5,8 +5,8 @@ export declare const PayloadSchema: "network.xyo.payload";
5
5
  export type PayloadSchema = typeof PayloadSchema;
6
6
  export declare const isSchema: (value: unknown) => value is Schema;
7
7
  export declare const asSchema: {
8
- <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.12-5822811789/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
9
- <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.12-5822811789/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<string>, config?: import("@xylabs/object").TypeCheckConfig): TType;
8
+ <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
9
+ <TType extends string>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<string>, config?: import("@xylabs/object").TypeCheckConfig): TType;
10
10
  };
11
11
  /** Schema fields for a Payload */
12
12
  export interface SchemaFields extends EmptyObject {
@@ -1,9 +1,17 @@
1
- import type { Hash, Hex } from '@xylabs/hex';
1
+ import { type Hash, type Hex } from '@xylabs/hex';
2
2
  import type { Payload } from './Payload.ts';
3
- export interface StorageMeta {
3
+ export interface SequenceMeta {
4
+ _sequence: Hex;
5
+ }
6
+ export type WithPartialSequenceMeta<T extends Payload = Payload> = Partial<WithSequenceMeta<T>>;
7
+ export type WithSequenceMeta<T extends Payload = Payload> = T & SequenceMeta;
8
+ export interface HashMeta {
4
9
  _dataHash: Hash;
5
10
  _hash: Hash;
6
- _sequence: Hex;
11
+ }
12
+ export type WithPartialHashMeta<T extends Payload = Payload> = Partial<WithHashMeta<T>>;
13
+ export type WithHashMeta<T extends Payload = Payload> = T & HashMeta;
14
+ export interface StorageMeta extends SequenceMeta, HashMeta {
7
15
  }
8
16
  export type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>;
9
17
  export type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta;
@@ -13,6 +21,13 @@ export declare const StorageMetaConstants: {
13
21
  addressBytes: number;
14
22
  maxEpoch: number;
15
23
  localSequenceBytes: number;
24
+ minLocalSequence: Hex;
25
+ maxLocalSequence: Hex;
16
26
  qualifiedSequenceBytes: number;
27
+ minSequence: Hex;
28
+ maxSequence: Hex;
17
29
  };
30
+ export declare const isSequenceMeta: (value: unknown) => value is SequenceMeta;
31
+ export declare const isHashMeta: (value: unknown) => value is HashMeta;
32
+ export declare const isStorageMeta: (value: unknown) => value is StorageMeta;
18
33
  //# sourceMappingURL=StorageMeta.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"StorageMeta.d.ts","sourceRoot":"","sources":["../../src/StorageMeta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAE5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,IAAI,CAAA;IACf,KAAK,EAAE,IAAI,CAAA;IAEX,SAAS,EAAE,GAAG,CAAA;CACf;AAED,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAA;AAE7F,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,CAAC,GAAG,WAAW,CAAA;AAc1E,eAAO,MAAM,oBAAoB;;;;;;;CAGhC,CAAA"}
1
+ {"version":3,"file":"StorageMeta.d.ts","sourceRoot":"","sources":["../../src/StorageMeta.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,EAAE,KA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 -42,6 +42,9 @@ var isSchema = (value) => {
42
42
  var asSchema = AsTypeFactory.create(isSchema);
43
43
 
44
44
  // src/StorageMeta.ts
45
+ import {
46
+ isHash
47
+ } from "@xylabs/hex";
45
48
  var StorageMetaComponentConstants = {
46
49
  epochBytes: 8,
47
50
  nonceBytes: 8,
@@ -50,12 +53,25 @@ var StorageMetaComponentConstants = {
50
53
  var StorageMetaLocalConstants = {
51
54
  maxEpoch: Math.pow(256, StorageMetaComponentConstants.epochBytes) - 1,
52
55
  localSequenceBytes: StorageMetaComponentConstants.epochBytes + StorageMetaComponentConstants.nonceBytes,
56
+ minLocalSequence: "00000000000000000000000000000000",
57
+ maxLocalSequence: "ffffffffffffffffffffffffffffffff",
53
58
  ...StorageMetaComponentConstants
54
59
  };
55
60
  var StorageMetaConstants = {
56
61
  qualifiedSequenceBytes: StorageMetaLocalConstants.localSequenceBytes + StorageMetaComponentConstants.addressBytes,
62
+ minSequence: `${StorageMetaLocalConstants}0000000000000000000000000000000000000000`,
63
+ maxSequence: `${StorageMetaLocalConstants}ffffffffffffffffffffffffffffffffffffffff`,
57
64
  ...StorageMetaLocalConstants
58
65
  };
66
+ var isSequenceMeta = (value) => {
67
+ return value?._sequence !== void 0;
68
+ };
69
+ var isHashMeta = (value) => {
70
+ return isHash(value?._hash) && isHash(value?._dataHash);
71
+ };
72
+ var isStorageMeta = (value) => {
73
+ return isSequenceMeta(value) && isHashMeta(value);
74
+ };
59
75
  export {
60
76
  ModuleErrorSchema,
61
77
  PayloadSchema,
@@ -65,11 +81,14 @@ export {
65
81
  asPayload,
66
82
  asSchema,
67
83
  isAnyPayload,
84
+ isHashMeta,
68
85
  isModuleError,
69
86
  isPayload,
70
87
  isPayloadOfSchemaType,
71
88
  isPayloadOfSchemaTypeWithSources,
72
89
  isSchema,
90
+ isSequenceMeta,
91
+ isStorageMeta,
73
92
  notPayloadOfSchemaType
74
93
  };
75
94
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts","../../src/StorageMeta.ts"],"sourcesContent":["import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport type { Payload } from './Payload.ts'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload\n = <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.ts'\nimport type { Payload, WithSources } from './Payload.ts'\n\nexport const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithSources<T> =>\n isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.sources !== undefined && Array.isArray(x.sources)\n}\n\nexport const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n\n// test types -- keep for future validation, but comment out\n\n/*\ntype TestSchema = 'network.xyo.test'\nconst TestSchema: TestSchema = 'network.xyo.test'\n\ntype Test = Payload<{ field: string }, TestSchema>\n\nconst testPayload: Test = { field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n*/\n","import type { Hash } from '@xylabs/hex'\nimport type { JsonValue } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.ts'\nimport type { Payload } from './Payload.ts'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import type { EmptyObject } from '@xylabs/object'\nimport { AsTypeFactory } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n return typeof value === 'string'\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n","import type { Hash, Hex } from '@xylabs/hex'\n\nimport type { Payload } from './Payload.ts'\n\nexport interface StorageMeta {\n _dataHash: Hash\n _hash: Hash\n // this sequence number must be a 0 padded string representation of a 18 byte sequence number\n _sequence: Hex // zero padded epoch/index (when returned, has address as suffix) - to be used as a universal cursor\n}\n\nexport type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>\n\nexport type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta\n\nconst StorageMetaComponentConstants = {\n epochBytes: 8,\n nonceBytes: 8,\n addressBytes: 20,\n}\n\nconst StorageMetaLocalConstants = {\n maxEpoch: Math.pow(256, StorageMetaComponentConstants.epochBytes) - 1,\n localSequenceBytes: StorageMetaComponentConstants.epochBytes + StorageMetaComponentConstants.nonceBytes,\n ...StorageMetaComponentConstants,\n}\n\nexport const StorageMetaConstants = {\n qualifiedSequenceBytes: StorageMetaLocalConstants.localSequenceBytes + StorageMetaComponentConstants.addressBytes,\n ...StorageMetaLocalConstants,\n}\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14\" is and example of a local sequence string\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14a123456789abcdef0123\" is and example of a local sequence string\n// epoch = \"00005a7f354762f3ac\"\n// nonce = \"1bc5ddc6cfd08d14\"\n// address = \"a123456789abcdef0123\"\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAgB;AAInC,IAAM,eAAe,CAAC,UAAqC;AAChE,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,OAAO,MAAM,WAAW;AAAA,EACjC;AACA,SAAO;AACT;AAEO,IAAM,eAAe,gBAAgB,OAAO,YAAY;AAExD,IAAM,YACT,CAAoB,WACpB,CAAC,UAA+B;AAC9B,MAAI,aAAa,KAAK,GAAG;AACvB,WAAO,OAAO,SAAS,MAAM,MAAM;AAAA,EACrC;AACA,SAAO;AACT;AAEG,IAAM,YAAY,CAAoB,WAAqB,gBAAgB,OAAO,CAAC,UAA+B,UAAU,MAAM,EAAE,KAAK,CAAC;;;ACnB1I,IAAM,wBAAwB,CAAoB,WAAmB;AAC1E,SAAO,CAAC,MAA+B,aAAa,CAAC,KAAK,GAAG,WAAW;AAC1E;AAEO,IAAM,mCAAmC,CAAoB,WAAmB;AACrF,SAAO,CAAC,MACN,sBAAsC,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,UAAa,MAAM,QAAQ,EAAE,OAAO;AAC1G;AAEO,IAAM,yBAAyB,CAAoB,WAAmB;AAC3E,SAAO,CAAC,MAA+B,CAAC,aAAa,CAAC,KAAK,GAAG,WAAW;AAC3E;;;ACPO,IAAM,oBAAuC;AAW7C,IAAM,gBAAgB,sBAAmC,iBAAiB;;;ACjB1E,IAAM,mBAAqC;;;ACAlD,SAAS,qBAAqB;AAKvB,IAAM,gBAAgB;AAGtB,IAAM,WAAW,CAAC,UAAoC;AAC3D,SAAO,OAAO,UAAU;AAC1B;AAEO,IAAM,WAAW,cAAc,OAAe,QAAQ;;;ACE7D,IAAM,gCAAgC;AAAA,EACpC,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,cAAc;AAChB;AAEA,IAAM,4BAA4B;AAAA,EAChC,UAAU,KAAK,IAAI,KAAK,8BAA8B,UAAU,IAAI;AAAA,EACpE,oBAAoB,8BAA8B,aAAa,8BAA8B;AAAA,EAC7F,GAAG;AACL;AAEO,IAAM,uBAAuB;AAAA,EAClC,wBAAwB,0BAA0B,qBAAqB,8BAA8B;AAAA,EACrG,GAAG;AACL;","names":[]}
1
+ {"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts","../../src/StorageMeta.ts"],"sourcesContent":["import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport type { Payload } from './Payload.ts'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload\n = <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.ts'\nimport type { Payload, WithSources } from './Payload.ts'\n\nexport const isPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => isAnyPayload(x) && x?.schema === schema\n}\n\nexport const isPayloadOfSchemaTypeWithSources = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is WithSources<T> =>\n isPayloadOfSchemaType<WithSources<T>>(schema)(x) && x.sources !== undefined && Array.isArray(x.sources)\n}\n\nexport const notPayloadOfSchemaType = <T extends Payload>(schema: string) => {\n return (x?: unknown | null): x is T => !isAnyPayload(x) || x?.schema !== schema\n}\n\n// test types -- keep for future validation, but comment out\n\n/*\ntype TestSchema = 'network.xyo.test'\nconst TestSchema: TestSchema = 'network.xyo.test'\n\ntype Test = Payload<{ field: string }, TestSchema>\n\nconst testPayload: Test = { field: 'test', schema: TestSchema }\n\nconst testPayloads: Payload[] = [testPayload]\n\nconst isTest: Test[] = testPayloads.filter(isPayloadOfSchemaType(TestSchema))\n\nconst isTestFromMetaTyped = testMetaPayloads.filter(isPayloadOfSchemaType<Test>(TestSchema))\n*/\n","import type { Hash } from '@xylabs/hex'\nimport type { JsonValue } from '@xylabs/object'\n\nimport { isPayloadOfSchemaType } from './isPayloadOfSchemaType.ts'\nimport type { Payload } from './Payload.ts'\n\nexport type ModuleErrorSchema = 'network.xyo.error.module'\nexport const ModuleErrorSchema: ModuleErrorSchema = 'network.xyo.error.module'\n\nexport type ModuleError = Payload<{\n details?: JsonValue\n message?: string\n name?: string\n query?: Hash\n schema: ModuleErrorSchema\n sources?: Hash[]\n}>\n\nexport const isModuleError = isPayloadOfSchemaType<ModuleError>(ModuleErrorSchema)\n","export type PayloadSetSchema = 'network.xyo.payload.set'\nexport const PayloadSetSchema: PayloadSetSchema = 'network.xyo.payload.set'\n","import type { EmptyObject } from '@xylabs/object'\nimport { AsTypeFactory } from '@xylabs/object'\n\n/** Schema type in Javascript is a string */\nexport type Schema = string\n\nexport const PayloadSchema = 'network.xyo.payload' as const\nexport type PayloadSchema = typeof PayloadSchema\n\nexport const isSchema = (value: unknown): value is Schema => {\n return typeof value === 'string'\n}\n\nexport const asSchema = AsTypeFactory.create<Schema>(isSchema)\n\n/** Schema fields for a Payload */\nexport interface SchemaFields extends EmptyObject {\n /** Schema of the object */\n schema: Schema\n}\n\n/** Add the Schema Fields to an object */\nexport type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields\n","import {\n type Hash, type Hex, isHash,\n} from '@xylabs/hex'\n\nimport type { Payload } from './Payload.ts'\n\nexport interface SequenceMeta {\n _sequence: Hex\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\nconst StorageMetaComponentConstants = {\n epochBytes: 8,\n nonceBytes: 8,\n addressBytes: 20,\n}\n\nconst StorageMetaLocalConstants = {\n maxEpoch: Math.pow(256, StorageMetaComponentConstants.epochBytes) - 1,\n localSequenceBytes: StorageMetaComponentConstants.epochBytes + StorageMetaComponentConstants.nonceBytes,\n minLocalSequence: '00000000000000000000000000000000' as Hex,\n maxLocalSequence: 'ffffffffffffffffffffffffffffffff' as Hex,\n ...StorageMetaComponentConstants,\n}\n\nexport const StorageMetaConstants = {\n qualifiedSequenceBytes: StorageMetaLocalConstants.localSequenceBytes + StorageMetaComponentConstants.addressBytes,\n minSequence: `${StorageMetaLocalConstants}0000000000000000000000000000000000000000` as Hex,\n maxSequence: `${StorageMetaLocalConstants}ffffffffffffffffffffffffffffffffffffffff` as Hex,\n ...StorageMetaLocalConstants,\n}\n\nexport const isSequenceMeta = (value: unknown): value is SequenceMeta => {\n return (value as WithSequenceMeta)?._sequence !== undefined\n}\n\nexport const isHashMeta = (value: unknown): value is HashMeta => {\n return isHash((value as WithHashMeta)?._hash) && isHash((value as WithHashMeta)?._dataHash)\n}\n\nexport const isStorageMeta = (value: unknown): value is StorageMeta => {\n return isSequenceMeta(value) && isHashMeta(value)\n}\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14\" is and example of a local sequence string\n\n// \"00005a7f354762f3ac1bc5ddc6cfd08d14a123456789abcdef0123\" is and example of a local sequence string\n// epoch = \"00005a7f354762f3ac\"\n// nonce = \"1bc5ddc6cfd08d14\"\n// address = \"a123456789abcdef0123\"\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAgB;AAInC,IAAM,eAAe,CAAC,UAAqC;AAChE,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,OAAO,MAAM,WAAW;AAAA,EACjC;AACA,SAAO;AACT;AAEO,IAAM,eAAe,gBAAgB,OAAO,YAAY;AAExD,IAAM,YACT,CAAoB,WACpB,CAAC,UAA+B;AAC9B,MAAI,aAAa,KAAK,GAAG;AACvB,WAAO,OAAO,SAAS,MAAM,MAAM;AAAA,EACrC;AACA,SAAO;AACT;AAEG,IAAM,YAAY,CAAoB,WAAqB,gBAAgB,OAAO,CAAC,UAA+B,UAAU,MAAM,EAAE,KAAK,CAAC;;;ACnB1I,IAAM,wBAAwB,CAAoB,WAAmB;AAC1E,SAAO,CAAC,MAA+B,aAAa,CAAC,KAAK,GAAG,WAAW;AAC1E;AAEO,IAAM,mCAAmC,CAAoB,WAAmB;AACrF,SAAO,CAAC,MACN,sBAAsC,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,UAAa,MAAM,QAAQ,EAAE,OAAO;AAC1G;AAEO,IAAM,yBAAyB,CAAoB,WAAmB;AAC3E,SAAO,CAAC,MAA+B,CAAC,aAAa,CAAC,KAAK,GAAG,WAAW;AAC3E;;;ACPO,IAAM,oBAAuC;AAW7C,IAAM,gBAAgB,sBAAmC,iBAAiB;;;ACjB1E,IAAM,mBAAqC;;;ACAlD,SAAS,qBAAqB;AAKvB,IAAM,gBAAgB;AAGtB,IAAM,WAAW,CAAC,UAAoC;AAC3D,SAAO,OAAO,UAAU;AAC1B;AAEO,IAAM,WAAW,cAAc,OAAe,QAAQ;;;ACb7D;AAAA,EACuB;AAAA,OAChB;AA2BP,IAAM,gCAAgC;AAAA,EACpC,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,cAAc;AAChB;AAEA,IAAM,4BAA4B;AAAA,EAChC,UAAU,KAAK,IAAI,KAAK,8BAA8B,UAAU,IAAI;AAAA,EACpE,oBAAoB,8BAA8B,aAAa,8BAA8B;AAAA,EAC7F,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,GAAG;AACL;AAEO,IAAM,uBAAuB;AAAA,EAClC,wBAAwB,0BAA0B,qBAAqB,8BAA8B;AAAA,EACrG,aAAa,GAAG,yBAAyB;AAAA,EACzC,aAAa,GAAG,yBAAyB;AAAA,EACzC,GAAG;AACL;AAEO,IAAM,iBAAiB,CAAC,UAA0C;AACvE,SAAQ,OAA4B,cAAc;AACpD;AAEO,IAAM,aAAa,CAAC,UAAsC;AAC/D,SAAO,OAAQ,OAAwB,KAAK,KAAK,OAAQ,OAAwB,SAAS;AAC5F;AAEO,IAAM,gBAAgB,CAAC,UAAyC;AACrE,SAAO,eAAe,KAAK,KAAK,WAAW,KAAK;AAClD;","names":[]}
@@ -3,16 +3,16 @@ export declare const isAnyPayload: (value: unknown) => value is Payload;
3
3
  export declare const asAnyPayload: {
4
4
  <TType extends {
5
5
  schema: string;
6
- } & import("./Payload.ts").PayloadFields>(value: import(".store/@xylabs-promise-npm-4.4.12-5822811789/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
6
+ } & import("./Payload.ts").PayloadFields>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
7
7
  <TType extends {
8
8
  schema: string;
9
- } & import("./Payload.ts").PayloadFields>(value: import(".store/@xylabs-promise-npm-4.4.12-5822811789/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<{
9
+ } & import("./Payload.ts").PayloadFields>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<{
10
10
  schema: string;
11
11
  } & import("./Payload.ts").PayloadFields>, 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.12-5822811789/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
16
- <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.12-5822811789/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
15
+ <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, config?: import("@xylabs/object").TypeCheckConfig): TType | undefined;
16
+ <TType extends T>(value: import(".store/@xylabs-promise-npm-4.4.13-f119ea3c1f/package").AnyNonPromise, assert: import("@xylabs/object").StringOrAlertFunction<T>, config?: import("@xylabs/object").TypeCheckConfig): TType;
17
17
  };
18
18
  //# sourceMappingURL=isPayload.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/payload-model",
3
- "version": "3.6.0-rc.2",
3
+ "version": "3.6.0-rc.4",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -37,13 +37,13 @@
37
37
  "module": "dist/neutral/index.mjs",
38
38
  "types": "dist/neutral/index.d.ts",
39
39
  "dependencies": {
40
- "@xylabs/hex": "^4.4.12",
41
- "@xylabs/object": "^4.4.12"
40
+ "@xylabs/hex": "^4.4.13",
41
+ "@xylabs/object": "^4.4.13"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@xylabs/ts-scripts-yarn3": "^4.2.4",
45
45
  "@xylabs/tsconfig": "^4.2.4",
46
- "@xylabs/vitest-extended": "^4.4.12",
46
+ "@xylabs/vitest-extended": "^4.4.13",
47
47
  "typescript": "^5.7.2",
48
48
  "vitest": "^2.1.8"
49
49
  },
@@ -1,14 +1,28 @@
1
- import type { Hash, Hex } from '@xylabs/hex'
1
+ import {
2
+ type Hash, type Hex, isHash,
3
+ } from '@xylabs/hex'
2
4
 
3
5
  import type { Payload } from './Payload.ts'
4
6
 
5
- export interface StorageMeta {
7
+ export interface SequenceMeta {
8
+ _sequence: Hex
9
+ }
10
+
11
+ export type WithPartialSequenceMeta<T extends Payload = Payload> = Partial<WithSequenceMeta<T>>
12
+
13
+ export type WithSequenceMeta<T extends Payload = Payload> = T & SequenceMeta
14
+
15
+ export interface HashMeta {
6
16
  _dataHash: Hash
7
17
  _hash: Hash
8
- // this sequence number must be a 0 padded string representation of a 18 byte sequence number
9
- _sequence: Hex // zero padded epoch/index (when returned, has address as suffix) - to be used as a universal cursor
10
18
  }
11
19
 
20
+ export type WithPartialHashMeta<T extends Payload = Payload> = Partial<WithHashMeta<T>>
21
+
22
+ export type WithHashMeta<T extends Payload = Payload> = T & HashMeta
23
+
24
+ export interface StorageMeta extends SequenceMeta, HashMeta {}
25
+
12
26
  export type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>
13
27
 
14
28
  export type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta
@@ -22,14 +36,30 @@ const StorageMetaComponentConstants = {
22
36
  const StorageMetaLocalConstants = {
23
37
  maxEpoch: Math.pow(256, StorageMetaComponentConstants.epochBytes) - 1,
24
38
  localSequenceBytes: StorageMetaComponentConstants.epochBytes + StorageMetaComponentConstants.nonceBytes,
39
+ minLocalSequence: '00000000000000000000000000000000' as Hex,
40
+ maxLocalSequence: 'ffffffffffffffffffffffffffffffff' as Hex,
25
41
  ...StorageMetaComponentConstants,
26
42
  }
27
43
 
28
44
  export const StorageMetaConstants = {
29
45
  qualifiedSequenceBytes: StorageMetaLocalConstants.localSequenceBytes + StorageMetaComponentConstants.addressBytes,
46
+ minSequence: `${StorageMetaLocalConstants}0000000000000000000000000000000000000000` as Hex,
47
+ maxSequence: `${StorageMetaLocalConstants}ffffffffffffffffffffffffffffffffffffffff` as Hex,
30
48
  ...StorageMetaLocalConstants,
31
49
  }
32
50
 
51
+ export const isSequenceMeta = (value: unknown): value is SequenceMeta => {
52
+ return (value as WithSequenceMeta)?._sequence !== undefined
53
+ }
54
+
55
+ export const isHashMeta = (value: unknown): value is HashMeta => {
56
+ return isHash((value as WithHashMeta)?._hash) && isHash((value as WithHashMeta)?._dataHash)
57
+ }
58
+
59
+ export const isStorageMeta = (value: unknown): value is StorageMeta => {
60
+ return isSequenceMeta(value) && isHashMeta(value)
61
+ }
62
+
33
63
  // "00005a7f354762f3ac1bc5ddc6cfd08d14" is and example of a local sequence string
34
64
 
35
65
  // "00005a7f354762f3ac1bc5ddc6cfd08d14a123456789abcdef0123" is and example of a local sequence string