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

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.
@@ -0,0 +1,18 @@
1
+ import type { Hash, Hex } from '@xylabs/hex';
2
+ import type { Payload } from './Payload.ts';
3
+ export interface StorageMeta {
4
+ _dataHash: Hash;
5
+ _hash: Hash;
6
+ _sequence: Hex;
7
+ }
8
+ export type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>;
9
+ export type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta;
10
+ export declare const StorageMetaConstants: {
11
+ epochBytes: number;
12
+ nonceBytes: number;
13
+ addressBytes: number;
14
+ maxEpoch: number;
15
+ localSequenceBytes: number;
16
+ qualifiedSequenceBytes: number;
17
+ };
18
+ //# sourceMappingURL=StorageMeta.d.ts.map
@@ -0,0 +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"}
@@ -8,4 +8,5 @@ export * from './PayloadValidationFunction.ts';
8
8
  export * from './PayloadValueExpression.ts';
9
9
  export * from './Query.ts';
10
10
  export * from './Schema.ts';
11
+ export * from './StorageMeta.ts';
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,cAAc,CAAA;AAC5B,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,cAAc,CAAA;AAC5B,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA"}
@@ -40,10 +40,27 @@ var isSchema = (value) => {
40
40
  return typeof value === "string";
41
41
  };
42
42
  var asSchema = AsTypeFactory.create(isSchema);
43
+
44
+ // src/StorageMeta.ts
45
+ var StorageMetaComponentConstants = {
46
+ epochBytes: 8,
47
+ nonceBytes: 8,
48
+ addressBytes: 20
49
+ };
50
+ var StorageMetaLocalConstants = {
51
+ maxEpoch: Math.pow(256, StorageMetaComponentConstants.epochBytes) - 1,
52
+ localSequenceBytes: StorageMetaComponentConstants.epochBytes + StorageMetaComponentConstants.nonceBytes,
53
+ ...StorageMetaComponentConstants
54
+ };
55
+ var StorageMetaConstants = {
56
+ qualifiedSequenceBytes: StorageMetaLocalConstants.localSequenceBytes + StorageMetaComponentConstants.addressBytes,
57
+ ...StorageMetaLocalConstants
58
+ };
43
59
  export {
44
60
  ModuleErrorSchema,
45
61
  PayloadSchema,
46
62
  PayloadSetSchema,
63
+ StorageMetaConstants,
47
64
  asAnyPayload,
48
65
  asPayload,
49
66
  asSchema,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport type { Payload } from './Payload.ts'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload\n = <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.ts'\nimport type { 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"],"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;","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 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":[]}
@@ -0,0 +1,18 @@
1
+ import type { Hash, Hex } from '@xylabs/hex';
2
+ import type { Payload } from './Payload.ts';
3
+ export interface StorageMeta {
4
+ _dataHash: Hash;
5
+ _hash: Hash;
6
+ _sequence: Hex;
7
+ }
8
+ export type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>;
9
+ export type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta;
10
+ export declare const StorageMetaConstants: {
11
+ epochBytes: number;
12
+ nonceBytes: number;
13
+ addressBytes: number;
14
+ maxEpoch: number;
15
+ localSequenceBytes: number;
16
+ qualifiedSequenceBytes: number;
17
+ };
18
+ //# sourceMappingURL=StorageMeta.d.ts.map
@@ -0,0 +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"}
@@ -8,4 +8,5 @@ export * from './PayloadValidationFunction.ts';
8
8
  export * from './PayloadValueExpression.ts';
9
9
  export * from './Query.ts';
10
10
  export * from './Schema.ts';
11
+ export * from './StorageMeta.ts';
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,cAAc,CAAA;AAC5B,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,cAAc,CAAA;AAC5B,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA"}
@@ -40,10 +40,27 @@ var isSchema = (value) => {
40
40
  return typeof value === "string";
41
41
  };
42
42
  var asSchema = AsTypeFactory.create(isSchema);
43
+
44
+ // src/StorageMeta.ts
45
+ var StorageMetaComponentConstants = {
46
+ epochBytes: 8,
47
+ nonceBytes: 8,
48
+ addressBytes: 20
49
+ };
50
+ var StorageMetaLocalConstants = {
51
+ maxEpoch: Math.pow(256, StorageMetaComponentConstants.epochBytes) - 1,
52
+ localSequenceBytes: StorageMetaComponentConstants.epochBytes + StorageMetaComponentConstants.nonceBytes,
53
+ ...StorageMetaComponentConstants
54
+ };
55
+ var StorageMetaConstants = {
56
+ qualifiedSequenceBytes: StorageMetaLocalConstants.localSequenceBytes + StorageMetaComponentConstants.addressBytes,
57
+ ...StorageMetaLocalConstants
58
+ };
43
59
  export {
44
60
  ModuleErrorSchema,
45
61
  PayloadSchema,
46
62
  PayloadSetSchema,
63
+ StorageMetaConstants,
47
64
  asAnyPayload,
48
65
  asPayload,
49
66
  asSchema,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport type { Payload } from './Payload.ts'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload\n = <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.ts'\nimport type { 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"],"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;","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 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":[]}
@@ -0,0 +1,18 @@
1
+ import type { Hash, Hex } from '@xylabs/hex';
2
+ import type { Payload } from './Payload.ts';
3
+ export interface StorageMeta {
4
+ _dataHash: Hash;
5
+ _hash: Hash;
6
+ _sequence: Hex;
7
+ }
8
+ export type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>;
9
+ export type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta;
10
+ export declare const StorageMetaConstants: {
11
+ epochBytes: number;
12
+ nonceBytes: number;
13
+ addressBytes: number;
14
+ maxEpoch: number;
15
+ localSequenceBytes: number;
16
+ qualifiedSequenceBytes: number;
17
+ };
18
+ //# sourceMappingURL=StorageMeta.d.ts.map
@@ -0,0 +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"}
@@ -8,4 +8,5 @@ export * from './PayloadValidationFunction.ts';
8
8
  export * from './PayloadValueExpression.ts';
9
9
  export * from './Query.ts';
10
10
  export * from './Schema.ts';
11
+ export * from './StorageMeta.ts';
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,cAAc,CAAA;AAC5B,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,cAAc,CAAA;AAC5B,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA"}
@@ -40,10 +40,27 @@ var isSchema = (value) => {
40
40
  return typeof value === "string";
41
41
  };
42
42
  var asSchema = AsTypeFactory.create(isSchema);
43
+
44
+ // src/StorageMeta.ts
45
+ var StorageMetaComponentConstants = {
46
+ epochBytes: 8,
47
+ nonceBytes: 8,
48
+ addressBytes: 20
49
+ };
50
+ var StorageMetaLocalConstants = {
51
+ maxEpoch: Math.pow(256, StorageMetaComponentConstants.epochBytes) - 1,
52
+ localSequenceBytes: StorageMetaComponentConstants.epochBytes + StorageMetaComponentConstants.nonceBytes,
53
+ ...StorageMetaComponentConstants
54
+ };
55
+ var StorageMetaConstants = {
56
+ qualifiedSequenceBytes: StorageMetaLocalConstants.localSequenceBytes + StorageMetaComponentConstants.addressBytes,
57
+ ...StorageMetaLocalConstants
58
+ };
43
59
  export {
44
60
  ModuleErrorSchema,
45
61
  PayloadSchema,
46
62
  PayloadSetSchema,
63
+ StorageMetaConstants,
47
64
  asAnyPayload,
48
65
  asPayload,
49
66
  asSchema,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/isPayload.ts","../../src/isPayloadOfSchemaType.ts","../../src/Error.ts","../../src/PayloadSet/PayloadSetSchema.ts","../../src/Schema.ts"],"sourcesContent":["import { AsObjectFactory, isObject } from '@xylabs/object'\n\nimport type { Payload } from './Payload.ts'\n\nexport const isAnyPayload = (value: unknown): value is Payload => {\n if (isObject(value)) {\n return typeof value.schema === 'string'\n }\n return false\n}\n\nexport const asAnyPayload = AsObjectFactory.create(isAnyPayload)\n\nexport const isPayload\n = <T extends Payload>(schema: string[]) =>\n (value: unknown): value is T => {\n if (isAnyPayload(value)) {\n return schema.includes(value.schema)\n }\n return false\n }\n\nexport const asPayload = <T extends Payload>(schema: string[]) => AsObjectFactory.create((value: unknown): value is T => isPayload(schema)(value))\n","import { isAnyPayload } from './isPayload.ts'\nimport type { 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"],"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;","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 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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/payload-model",
3
- "version": "3.6.0-rc.1",
3
+ "version": "3.6.0-rc.2",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -0,0 +1,38 @@
1
+ import type { Hash, Hex } from '@xylabs/hex'
2
+
3
+ import type { Payload } from './Payload.ts'
4
+
5
+ export interface StorageMeta {
6
+ _dataHash: Hash
7
+ _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
+ }
11
+
12
+ export type WithPartialStorageMeta<T extends Payload = Payload> = Partial<WithStorageMeta<T>>
13
+
14
+ export type WithStorageMeta<T extends Payload = Payload> = T & StorageMeta
15
+
16
+ const StorageMetaComponentConstants = {
17
+ epochBytes: 8,
18
+ nonceBytes: 8,
19
+ addressBytes: 20,
20
+ }
21
+
22
+ const StorageMetaLocalConstants = {
23
+ maxEpoch: Math.pow(256, StorageMetaComponentConstants.epochBytes) - 1,
24
+ localSequenceBytes: StorageMetaComponentConstants.epochBytes + StorageMetaComponentConstants.nonceBytes,
25
+ ...StorageMetaComponentConstants,
26
+ }
27
+
28
+ export const StorageMetaConstants = {
29
+ qualifiedSequenceBytes: StorageMetaLocalConstants.localSequenceBytes + StorageMetaComponentConstants.addressBytes,
30
+ ...StorageMetaLocalConstants,
31
+ }
32
+
33
+ // "00005a7f354762f3ac1bc5ddc6cfd08d14" is and example of a local sequence string
34
+
35
+ // "00005a7f354762f3ac1bc5ddc6cfd08d14a123456789abcdef0123" is and example of a local sequence string
36
+ // epoch = "00005a7f354762f3ac"
37
+ // nonce = "1bc5ddc6cfd08d14"
38
+ // address = "a123456789abcdef0123"
package/src/index.ts CHANGED
@@ -8,3 +8,4 @@ export * from './PayloadValidationFunction.ts'
8
8
  export * from './PayloadValueExpression.ts'
9
9
  export * from './Query.ts'
10
10
  export * from './Schema.ts'
11
+ export * from './StorageMeta.ts'