@xyo-network/payload 2.42.13 → 2.42.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/dist/cjs/Payloads.d.ts +1 -1
  2. package/dist/cjs/Payloads.d.ts.map +1 -1
  3. package/dist/cjs/index.d.ts +5 -6
  4. package/dist/cjs/index.d.ts.map +1 -1
  5. package/dist/cjs/index.js +5 -6
  6. package/dist/cjs/index.js.map +1 -1
  7. package/dist/cjs/isXyoPayloadOfSchemaType.d.ts +2 -2
  8. package/dist/cjs/isXyoPayloadOfSchemaType.d.ts.map +1 -1
  9. package/dist/esm/Payloads.d.ts +1 -1
  10. package/dist/esm/Payloads.d.ts.map +1 -1
  11. package/dist/esm/index.d.ts +5 -6
  12. package/dist/esm/index.d.ts.map +1 -1
  13. package/dist/esm/index.js +5 -6
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/esm/isXyoPayloadOfSchemaType.d.ts +2 -2
  16. package/dist/esm/isXyoPayloadOfSchemaType.d.ts.map +1 -1
  17. package/package.json +7 -8
  18. package/src/Payloads.ts +1 -1
  19. package/src/index.ts +5 -6
  20. package/src/isXyoPayloadOfSchemaType.ts +1 -1
  21. package/dist/cjs/Builder/Builder.d.ts +0 -13
  22. package/dist/cjs/Builder/Builder.d.ts.map +0 -1
  23. package/dist/cjs/Builder/Builder.js +0 -27
  24. package/dist/cjs/Builder/Builder.js.map +0 -1
  25. package/dist/cjs/Builder/index.d.ts +0 -2
  26. package/dist/cjs/Builder/index.d.ts.map +0 -1
  27. package/dist/cjs/Builder/index.js +0 -5
  28. package/dist/cjs/Builder/index.js.map +0 -1
  29. package/dist/cjs/Huri/Huri.d.ts +0 -32
  30. package/dist/cjs/Huri/Huri.d.ts.map +0 -1
  31. package/dist/cjs/Huri/Huri.js +0 -111
  32. package/dist/cjs/Huri/Huri.js.map +0 -1
  33. package/dist/cjs/Huri/index.d.ts +0 -2
  34. package/dist/cjs/Huri/index.d.ts.map +0 -1
  35. package/dist/cjs/Huri/index.js +0 -5
  36. package/dist/cjs/Huri/index.js.map +0 -1
  37. package/dist/cjs/SchemaNameValidator.d.ts +0 -68
  38. package/dist/cjs/SchemaNameValidator.d.ts.map +0 -1
  39. package/dist/cjs/SchemaNameValidator.js +0 -127
  40. package/dist/cjs/SchemaNameValidator.js.map +0 -1
  41. package/dist/cjs/Test/index.d.ts +0 -2
  42. package/dist/cjs/Test/index.d.ts.map +0 -1
  43. package/dist/cjs/Test/index.js +0 -5
  44. package/dist/cjs/Test/index.js.map +0 -1
  45. package/dist/cjs/Test/testPayload.d.ts +0 -6
  46. package/dist/cjs/Test/testPayload.d.ts.map +0 -1
  47. package/dist/cjs/Test/testPayload.js +0 -16
  48. package/dist/cjs/Test/testPayload.js.map +0 -1
  49. package/dist/cjs/Validator/Validator.d.ts +0 -11
  50. package/dist/cjs/Validator/Validator.d.ts.map +0 -1
  51. package/dist/cjs/Validator/Validator.js +0 -32
  52. package/dist/cjs/Validator/Validator.js.map +0 -1
  53. package/dist/cjs/Validator/index.d.ts +0 -2
  54. package/dist/cjs/Validator/index.d.ts.map +0 -1
  55. package/dist/cjs/Validator/index.js +0 -5
  56. package/dist/cjs/Validator/index.js.map +0 -1
  57. package/dist/cjs/Wrapper/Wrapper.d.ts +0 -23
  58. package/dist/cjs/Wrapper/Wrapper.d.ts.map +0 -1
  59. package/dist/cjs/Wrapper/Wrapper.js +0 -63
  60. package/dist/cjs/Wrapper/Wrapper.js.map +0 -1
  61. package/dist/cjs/Wrapper/index.d.ts +0 -2
  62. package/dist/cjs/Wrapper/index.d.ts.map +0 -1
  63. package/dist/cjs/Wrapper/index.js +0 -5
  64. package/dist/cjs/Wrapper/index.js.map +0 -1
  65. package/dist/cjs/models/PayloadFindFilter.d.ts +0 -16
  66. package/dist/cjs/models/PayloadFindFilter.d.ts.map +0 -1
  67. package/dist/cjs/models/PayloadFindFilter.js +0 -3
  68. package/dist/cjs/models/PayloadFindFilter.js.map +0 -1
  69. package/dist/cjs/models/PayloadSet/PayloadSetPayload.d.ts +0 -8
  70. package/dist/cjs/models/PayloadSet/PayloadSetPayload.d.ts.map +0 -1
  71. package/dist/cjs/models/PayloadSet/PayloadSetPayload.js +0 -3
  72. package/dist/cjs/models/PayloadSet/PayloadSetPayload.js.map +0 -1
  73. package/dist/cjs/models/PayloadSet/PayloadSetSchema.d.ts +0 -3
  74. package/dist/cjs/models/PayloadSet/PayloadSetSchema.d.ts.map +0 -1
  75. package/dist/cjs/models/PayloadSet/PayloadSetSchema.js +0 -5
  76. package/dist/cjs/models/PayloadSet/PayloadSetSchema.js.map +0 -1
  77. package/dist/cjs/models/PayloadSet/index.d.ts +0 -3
  78. package/dist/cjs/models/PayloadSet/index.d.ts.map +0 -1
  79. package/dist/cjs/models/PayloadSet/index.js +0 -6
  80. package/dist/cjs/models/PayloadSet/index.js.map +0 -1
  81. package/dist/cjs/models/XyoPayload.d.ts +0 -21
  82. package/dist/cjs/models/XyoPayload.d.ts.map +0 -1
  83. package/dist/cjs/models/XyoPayload.js +0 -5
  84. package/dist/cjs/models/XyoPayload.js.map +0 -1
  85. package/dist/cjs/models/index.d.ts +0 -4
  86. package/dist/cjs/models/index.d.ts.map +0 -1
  87. package/dist/cjs/models/index.js +0 -7
  88. package/dist/cjs/models/index.js.map +0 -1
  89. package/dist/docs.json +0 -7103
  90. package/dist/esm/Builder/Builder.d.ts +0 -13
  91. package/dist/esm/Builder/Builder.d.ts.map +0 -1
  92. package/dist/esm/Builder/Builder.js +0 -27
  93. package/dist/esm/Builder/Builder.js.map +0 -1
  94. package/dist/esm/Builder/index.d.ts +0 -2
  95. package/dist/esm/Builder/index.d.ts.map +0 -1
  96. package/dist/esm/Builder/index.js +0 -2
  97. package/dist/esm/Builder/index.js.map +0 -1
  98. package/dist/esm/Huri/Huri.d.ts +0 -32
  99. package/dist/esm/Huri/Huri.d.ts.map +0 -1
  100. package/dist/esm/Huri/Huri.js +0 -104
  101. package/dist/esm/Huri/Huri.js.map +0 -1
  102. package/dist/esm/Huri/index.d.ts +0 -2
  103. package/dist/esm/Huri/index.d.ts.map +0 -1
  104. package/dist/esm/Huri/index.js +0 -2
  105. package/dist/esm/Huri/index.js.map +0 -1
  106. package/dist/esm/SchemaNameValidator.d.ts +0 -68
  107. package/dist/esm/SchemaNameValidator.d.ts.map +0 -1
  108. package/dist/esm/SchemaNameValidator.js +0 -114
  109. package/dist/esm/SchemaNameValidator.js.map +0 -1
  110. package/dist/esm/Test/index.d.ts +0 -2
  111. package/dist/esm/Test/index.d.ts.map +0 -1
  112. package/dist/esm/Test/index.js +0 -2
  113. package/dist/esm/Test/index.js.map +0 -1
  114. package/dist/esm/Test/testPayload.d.ts +0 -6
  115. package/dist/esm/Test/testPayload.d.ts.map +0 -1
  116. package/dist/esm/Test/testPayload.js +0 -12
  117. package/dist/esm/Test/testPayload.js.map +0 -1
  118. package/dist/esm/Validator/Validator.d.ts +0 -11
  119. package/dist/esm/Validator/Validator.d.ts.map +0 -1
  120. package/dist/esm/Validator/Validator.js +0 -28
  121. package/dist/esm/Validator/Validator.js.map +0 -1
  122. package/dist/esm/Validator/index.d.ts +0 -2
  123. package/dist/esm/Validator/index.d.ts.map +0 -1
  124. package/dist/esm/Validator/index.js +0 -2
  125. package/dist/esm/Validator/index.js.map +0 -1
  126. package/dist/esm/Wrapper/Wrapper.d.ts +0 -23
  127. package/dist/esm/Wrapper/Wrapper.d.ts.map +0 -1
  128. package/dist/esm/Wrapper/Wrapper.js +0 -52
  129. package/dist/esm/Wrapper/Wrapper.js.map +0 -1
  130. package/dist/esm/Wrapper/index.d.ts +0 -2
  131. package/dist/esm/Wrapper/index.d.ts.map +0 -1
  132. package/dist/esm/Wrapper/index.js +0 -2
  133. package/dist/esm/Wrapper/index.js.map +0 -1
  134. package/dist/esm/models/PayloadFindFilter.d.ts +0 -16
  135. package/dist/esm/models/PayloadFindFilter.d.ts.map +0 -1
  136. package/dist/esm/models/PayloadFindFilter.js +0 -2
  137. package/dist/esm/models/PayloadFindFilter.js.map +0 -1
  138. package/dist/esm/models/PayloadSet/PayloadSetPayload.d.ts +0 -8
  139. package/dist/esm/models/PayloadSet/PayloadSetPayload.d.ts.map +0 -1
  140. package/dist/esm/models/PayloadSet/PayloadSetPayload.js +0 -2
  141. package/dist/esm/models/PayloadSet/PayloadSetPayload.js.map +0 -1
  142. package/dist/esm/models/PayloadSet/PayloadSetSchema.d.ts +0 -3
  143. package/dist/esm/models/PayloadSet/PayloadSetSchema.d.ts.map +0 -1
  144. package/dist/esm/models/PayloadSet/PayloadSetSchema.js +0 -2
  145. package/dist/esm/models/PayloadSet/PayloadSetSchema.js.map +0 -1
  146. package/dist/esm/models/PayloadSet/index.d.ts +0 -3
  147. package/dist/esm/models/PayloadSet/index.d.ts.map +0 -1
  148. package/dist/esm/models/PayloadSet/index.js +0 -3
  149. package/dist/esm/models/PayloadSet/index.js.map +0 -1
  150. package/dist/esm/models/XyoPayload.d.ts +0 -21
  151. package/dist/esm/models/XyoPayload.d.ts.map +0 -1
  152. package/dist/esm/models/XyoPayload.js +0 -2
  153. package/dist/esm/models/XyoPayload.js.map +0 -1
  154. package/dist/esm/models/index.d.ts +0 -4
  155. package/dist/esm/models/index.d.ts.map +0 -1
  156. package/dist/esm/models/index.js +0 -4
  157. package/dist/esm/models/index.js.map +0 -1
  158. package/src/Builder/Builder.spec.ts +0 -38
  159. package/src/Builder/Builder.ts +0 -37
  160. package/src/Builder/index.ts +0 -1
  161. package/src/Huri/Huri.spec.ts +0 -92
  162. package/src/Huri/Huri.ts +0 -154
  163. package/src/Huri/index.ts +0 -1
  164. package/src/SchemaNameValidator.ts +0 -120
  165. package/src/Test/index.ts +0 -1
  166. package/src/Test/testPayload.ts +0 -16
  167. package/src/Validator/Validator.spec.ts +0 -52
  168. package/src/Validator/Validator.ts +0 -33
  169. package/src/Validator/index.ts +0 -1
  170. package/src/Wrapper/Wrapper.ts +0 -69
  171. package/src/Wrapper/index.ts +0 -1
  172. package/src/models/PayloadFindFilter.ts +0 -19
  173. package/src/models/PayloadSet/PayloadSetPayload.ts +0 -9
  174. package/src/models/PayloadSet/PayloadSetSchema.ts +0 -2
  175. package/src/models/PayloadSet/index.ts +0 -2
  176. package/src/models/XyoPayload.ts +0 -31
  177. package/src/models/index.ts +0 -3
@@ -1,16 +0,0 @@
1
- /** @deprecated use offset as a string (hash) instead */
2
- export interface PayloadFindFilterTimeOffset {
3
- offset?: number;
4
- }
5
- export interface PayloadFindFilterHashOffset {
6
- offset?: string;
7
- }
8
- export type PayloadFindFilterOffset = PayloadFindFilterTimeOffset | PayloadFindFilterHashOffset;
9
- export type PayloadFindFilter = {
10
- limit?: number;
11
- order?: 'desc' | 'asc';
12
- schema?: string | string[];
13
- /** @deprecated use offset instead */
14
- timestamp?: number;
15
- } & PayloadFindFilterOffset;
16
- //# sourceMappingURL=PayloadFindFilter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PayloadFindFilter.d.ts","sourceRoot":"","sources":["../../../src/models/PayloadFindFilter.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,MAAM,WAAW,2BAA2B;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,2BAA2B;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAGD,MAAM,MAAM,uBAAuB,GAAG,2BAA2B,GAAG,2BAA2B,CAAA;AAE/F,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IACtB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC1B,qCAAqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,GAAG,uBAAuB,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=PayloadFindFilter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PayloadFindFilter.js","sourceRoot":"","sources":["../../../src/models/PayloadFindFilter.ts"],"names":[],"mappings":""}
@@ -1,8 +0,0 @@
1
- import { XyoPayload } from '../XyoPayload';
2
- import { PayloadSetSchema } from './PayloadSetSchema';
3
- export interface PayloadSet {
4
- optional?: Record<string, number>;
5
- required?: Record<string, number>;
6
- }
7
- export type PayloadSetPayload = XyoPayload<PayloadSet, PayloadSetSchema>;
8
- //# sourceMappingURL=PayloadSetPayload.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PayloadSetPayload.d.ts","sourceRoot":"","sources":["../../../../src/models/PayloadSet/PayloadSetPayload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAClC;AAED,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=PayloadSetPayload.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PayloadSetPayload.js","sourceRoot":"","sources":["../../../../src/models/PayloadSet/PayloadSetPayload.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- export type PayloadSetSchema = 'network.xyo.payload.set';
2
- export declare const PayloadSetSchema: PayloadSetSchema;
3
- //# sourceMappingURL=PayloadSetSchema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PayloadSetSchema.d.ts","sourceRoot":"","sources":["../../../../src/models/PayloadSet/PayloadSetSchema.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,yBAAyB,CAAA;AACxD,eAAO,MAAM,gBAAgB,EAAE,gBAA4C,CAAA"}
@@ -1,2 +0,0 @@
1
- export const PayloadSetSchema = 'network.xyo.payload.set';
2
- //# sourceMappingURL=PayloadSetSchema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PayloadSetSchema.js","sourceRoot":"","sources":["../../../../src/models/PayloadSet/PayloadSetSchema.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,gBAAgB,GAAqB,yBAAyB,CAAA"}
@@ -1,3 +0,0 @@
1
- export * from './PayloadSetPayload';
2
- export * from './PayloadSetSchema';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/PayloadSet/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA"}
@@ -1,3 +0,0 @@
1
- export * from './PayloadSetPayload';
2
- export * from './PayloadSetSchema';
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/models/PayloadSet/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA"}
@@ -1,21 +0,0 @@
1
- import { EmptyObject } from '@xyo-network/core';
2
- export type WithTimestamp<T extends EmptyObject = EmptyObject> = T & {
3
- timestamp: number;
4
- };
5
- export type XyoPayloadSchema = 'network.xyo.payload';
6
- export declare const XyoPayloadSchema: XyoPayloadSchema;
7
- export type SchemaFields = {
8
- schema: string;
9
- };
10
- export type WithSchema<T extends EmptyObject | void = void> = T extends EmptyObject ? SchemaFields & T : SchemaFields;
11
- export type PayloadFields = {
12
- sources?: string[];
13
- timestamp?: number;
14
- };
15
- export type WithPayload<T extends EmptyObject | void = void> = WithSchema<T extends EmptyObject ? PayloadFields & T : PayloadFields>;
16
- export type XyoPayload<T extends void | EmptyObject | WithSchema = void, S extends string = T extends WithSchema ? T['schema'] : string> = T extends WithSchema ? WithPayload<T> : T extends EmptyObject ? WithPayload<T & {
17
- schema: S;
18
- }> : WithPayload<{
19
- schema: S;
20
- }>;
21
- //# sourceMappingURL=XyoPayload.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"XyoPayload.d.ts","sourceRoot":"","sources":["../../../src/models/XyoPayload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/C,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,IAAI,CAAC,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAA;AAE1F,MAAM,MAAM,gBAAgB,GAAG,qBAAqB,CAAA;AACpD,eAAO,MAAM,gBAAgB,EAAE,gBAAwC,CAAA;AAEvE,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,WAAW,GAAG,YAAY,GAAG,CAAC,GAAG,YAAY,CAAA;AAErH,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,IAAI,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,aAAa,GAAG,CAAC,GAAG,aAAa,CAAC,CAAA;AAEpI,MAAM,MAAM,UAAU,CACpB,CAAC,SAAS,IAAI,GAAG,WAAW,GAAG,UAAU,GAAG,IAAI,EAChD,CAAC,SAAS,MAAM,GAAG,CAAC,SAAS,UAAU,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,MAAM,IAC5D,CAAC,SAAS,UAAU,GAEpB,WAAW,CAAC,CAAC,CAAC,GACd,CAAC,SAAS,WAAW,GAErB,WAAW,CAAC,CAAC,GAAG;IAAE,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC,GAE9B,WAAW,CAAC;IAAE,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export const XyoPayloadSchema = 'network.xyo.payload';
2
- //# sourceMappingURL=XyoPayload.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"XyoPayload.js","sourceRoot":"","sources":["../../../src/models/XyoPayload.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,gBAAgB,GAAqB,qBAAqB,CAAA"}
@@ -1,4 +0,0 @@
1
- export * from './PayloadFindFilter';
2
- export * from './PayloadSet';
3
- export * from './XyoPayload';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}
@@ -1,4 +0,0 @@
1
- export * from './PayloadFindFilter';
2
- export * from './PayloadSet';
3
- export * from './XyoPayload';
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}
@@ -1,38 +0,0 @@
1
- import { XyoPayload } from '../models'
2
- import { XyoPayloadBuilder } from './Builder'
3
-
4
- const schema = 'network.xyo.temp'
5
-
6
- const payloadHash = '57b78b1b7df3ac0369654642e879cdf2f3c95f9c5949bcb34ea3cb8309c538b4'
7
-
8
- const ADDITIONAL_FIELD_COUNT = 4
9
-
10
- describe('XyoBoundWitnessBuilder', () => {
11
- test('build', () => {
12
- let builder = new XyoPayloadBuilder<XyoPayload<Record<string, unknown>>>({ schema })
13
- expect(builder).toBeDefined()
14
- builder = builder.fields({
15
- testArray: [1, 2, 3],
16
- testBoolean: true,
17
- testNull: null,
18
- testNullObject: { t: null, x: undefined },
19
- testNumber: 5,
20
- testObject: { t: 1 },
21
- testSomeNullObject: { s: 1, t: null, x: undefined },
22
- testString: 'hi',
23
- testUndefined: undefined,
24
- })
25
- expect(builder).toBeDefined()
26
-
27
- const actual = builder.build()
28
-
29
- expect(actual).toBeDefined()
30
- expect(actual._timestamp).toBeDefined()
31
- expect(actual._client).toBeDefined()
32
- expect(actual._hash).toBeDefined()
33
- expect(actual.schema).toBeDefined()
34
- expect(Object.keys(actual).length).toBe(8 + ADDITIONAL_FIELD_COUNT)
35
- expect(Object.keys(actual.testSomeNullObject as object).length).toBe(2)
36
- expect(actual._hash).toEqual(payloadHash)
37
- })
38
- })
@@ -1,37 +0,0 @@
1
- import { deepOmitUnderscoreFields, Hasher, removeEmptyFields } from '@xyo-network/core'
2
-
3
- import { XyoPayload } from '../models'
4
-
5
- export interface XyoPayloadBuilderOptions {
6
- schema: string
7
- }
8
-
9
- export class XyoPayloadBuilder<T extends XyoPayload = XyoPayload<Record<string, unknown>>> {
10
- private _fields: Partial<T> = {}
11
- private _schema: string
12
-
13
- constructor({ schema }: XyoPayloadBuilderOptions) {
14
- this._schema = schema
15
- }
16
-
17
- public build(): T {
18
- const hashableFields = this.hashableFields()
19
- const _hash = new Hasher(hashableFields).hash
20
- const _timestamp = Date.now()
21
- return { ...hashableFields, _client: 'js', _hash, _timestamp, schema: this._schema }
22
- }
23
-
24
- public fields(fields?: Partial<T>) {
25
- if (fields) {
26
- this._fields = { ...this._fields, ...removeEmptyFields(fields) }
27
- }
28
- return this
29
- }
30
-
31
- public hashableFields() {
32
- return {
33
- ...removeEmptyFields(deepOmitUnderscoreFields(this._fields)),
34
- schema: this._schema,
35
- } as T
36
- }
37
- }
@@ -1 +0,0 @@
1
- export * from './Builder'
@@ -1,92 +0,0 @@
1
- import { delay } from '@xylabs/delay'
2
-
3
- import { XyoPayload } from '../models'
4
- import { Huri } from './Huri'
5
-
6
- const hash = 'fb3606d71dcdd49a0aacc9d234e412684d577803c8a9ed9399a9d3776cc88e24'
7
-
8
- const valid = [
9
- `https://${hash}`,
10
- `https://api.archivist.xyo.network/temp/${hash}`,
11
- `https://api.archivist.xyo.network/${hash}`,
12
- `http://api.archivist.xyo.network/${hash}`,
13
- `/api.archivist.xyo.network/${hash}`,
14
- `//${hash}`,
15
- `/${hash}`,
16
- `${hash}`,
17
- ]
18
-
19
- const validWithTempArchive = [
20
- `https://api.archivist.xyo.network/temp/${hash}`,
21
- `https://api.archivist.xyo.network/temp/${hash}`,
22
- `http://api.archivist.xyo.network/temp/${hash}`,
23
- `/api.archivist.xyo.network/temp/${hash}`,
24
- ]
25
-
26
- const invalid = [`https:///api.archivist.xyo.network/${hash}`, `https://api.archivist.xyo.network//${hash}`]
27
-
28
- describe('Huri', () => {
29
- describe('Valid Items', () => {
30
- valid.map((item) => {
31
- test(`valid [${item}]`, () => {
32
- try {
33
- const huri = new Huri(item)
34
- expect(huri.hash).toBe(hash)
35
- } catch (ex) {
36
- console.error(`Valid Huri failed: [${item}]`)
37
- console.error(ex)
38
- }
39
- })
40
- })
41
- })
42
- describe('Valid Items w/archive', () => {
43
- validWithTempArchive.map((item) => {
44
- test(`valid w/archive [${item}]`, () => {
45
- try {
46
- const huri = new Huri(item)
47
- expect(huri.hash).toBe(hash)
48
- expect(huri.archive).toBe('temp')
49
- } catch (ex) {
50
- console.error(`Valid Huri w/archive failed: [${item}]`)
51
- console.error(ex)
52
- }
53
- })
54
- })
55
- })
56
- describe('Invalid Items', () => {
57
- invalid.map((item) => {
58
- test(`invalid [${item}]`, () => {
59
- expect(() => new Huri(item)).toThrowError()
60
- })
61
- })
62
- })
63
- describe('Api Fetch', () => {
64
- it('Valid Huri', async () => {
65
- const huri = new Huri('https://beta.api.archivist.xyo.network/18f97b3e85f5bede65e7c0a85d74aee896de58ead8bc4b1b3d7300646c653057')
66
- const result = await huri.fetch()
67
- expect(result?.schema).toBe('network.xyo.schema')
68
- })
69
- it('Invalid Huri', async () => {
70
- const huri = new Huri('https://beta.api.archivist.xyo.network/18f97b3e85f5bede65e7c0a85d74aee896de58ead8bc4b1b3d7300646c653bad')
71
- await expect(huri.fetch()).rejects.toThrow()
72
- })
73
- })
74
- describe('Fetch Override', () => {
75
- invalid.map((item) => {
76
- test(`invalid [${item}]`, async () => {
77
- const oldFetch = Huri.fetch
78
- Huri.fetch = async <T extends XyoPayload = XyoPayload>(huri: Huri): Promise<T | undefined> => {
79
- await delay(0)
80
- const payload: T = {
81
- schema: huri.hash,
82
- } as T
83
- return payload
84
- }
85
- const huri = new Huri('https://beta.api.archivist.xyo.network/18f97b3e85f5bede65e7c0a85d74aee896de58ead8bc4b1b3d7300646c653057')
86
- const result = await huri.fetch()
87
- Huri.fetch = oldFetch
88
- expect(result?.schema).toBe('18f97b3e85f5bede65e7c0a85d74aee896de58ead8bc4b1b3d7300646c653057')
89
- })
90
- })
91
- })
92
- })
package/src/Huri/Huri.ts DELETED
@@ -1,154 +0,0 @@
1
- import { assertEx } from '@xylabs/assert'
2
- import { AddressValue } from '@xyo-network/account'
3
- import { DataLike } from '@xyo-network/core'
4
- import axios from 'axios'
5
-
6
- import { XyoPayload } from '../models'
7
-
8
- export type XyoObjectCategory = 'block' | 'payload'
9
-
10
- export type HuriFetchFunction = (huri: Huri) => Promise<XyoPayload | undefined>
11
-
12
- /*
13
- Valid Huri:
14
-
15
- [<protocol>://][<archivist>/[<archive>/]]<hash>
16
-
17
- defaults:
18
- protocol: https
19
- archivist: api.archivist.xyo.network
20
- */
21
-
22
- export interface HuriOptions {
23
- archivistUri?: string
24
- }
25
-
26
- export interface FetchedPayload<T extends XyoPayload = XyoPayload> {
27
- huri?: Huri
28
- payload: T
29
- }
30
-
31
- export class Huri<T extends XyoPayload = XyoPayload> {
32
- public archive?: string
33
- public archivist?: string
34
- public hash: string
35
- public originalHref: string
36
- public protocol?: string
37
-
38
- private isHuri = true
39
-
40
- constructor(huri: DataLike | Huri, { archivistUri }: HuriOptions = {}) {
41
- const huriString = Huri.isHuri(huri)?.href ?? typeof huri === 'string' ? (huri as string) : new AddressValue(huri as DataLike).hex
42
- this.originalHref = huriString
43
-
44
- const protocol = Huri.parseProtocol(huriString)
45
- this.protocol = protocol ?? 'https'
46
-
47
- const path = assertEx(Huri.parsePath(huriString), 'Missing path')
48
- this.hash = this.parsePath(path, protocol !== undefined)
49
-
50
- //if archivistUri sent, overwrite protocol and archivist
51
- if (archivistUri) {
52
- const archivistUriParts = archivistUri.split('://')
53
- this.protocol = archivistUriParts[0]
54
- this.archivist = archivistUriParts[1]
55
- }
56
-
57
- this.validateParse()
58
- }
59
-
60
- /*
61
- The full href or the hash
62
- */
63
- public get href() {
64
- const parts: string[] = []
65
- if (this.protocol) {
66
- parts.push(`${this.protocol}:/`)
67
- }
68
- if (this.archive) {
69
- parts.push(`${this.archive}`)
70
- }
71
- if (this.archivist) {
72
- parts.push(`${this.archivist}`)
73
- }
74
- parts.push(this.hash)
75
- return parts.join('/')
76
- }
77
-
78
- static async fetch<T extends XyoPayload = XyoPayload>(huri: Huri): Promise<T | undefined> {
79
- return (await axios.get<T>(huri.href)).data
80
- }
81
-
82
- public static isHuri(value: unknown) {
83
- if (typeof value === 'object') {
84
- return (value as Huri).isHuri ? (value as Huri) : undefined
85
- }
86
- return undefined
87
- }
88
-
89
- private static parsePath(huri: string) {
90
- const protocolSplit = huri.split('//')
91
- assertEx(protocolSplit.length <= 2, `Invalid format [${huri}]`)
92
- if (protocolSplit.length === 1) {
93
- return huri
94
- }
95
- if (protocolSplit.length === 2) {
96
- return protocolSplit[1]
97
- }
98
- }
99
-
100
- private static parseProtocol(huri: string) {
101
- const protocolSplit = huri.split('//')
102
- assertEx(protocolSplit.length <= 2, `Invalid second protocol [${protocolSplit[2]}]`)
103
- const rawProtocol = protocolSplit.length === 2 ? protocolSplit.shift() : undefined
104
- if (rawProtocol) {
105
- const protocolParts = rawProtocol?.split(':')
106
- assertEx(protocolParts.length === 2, `Invalid protocol format [${rawProtocol}]`)
107
- assertEx(protocolParts[1].length === 0, `Invalid protocol format (post :) [${rawProtocol}]`)
108
- return protocolParts.shift()
109
- }
110
- }
111
-
112
- public async fetch(): Promise<T | undefined> {
113
- return await Huri.fetch<T>(this)
114
- }
115
-
116
- public toString() {
117
- return this.href
118
- }
119
-
120
- private parsePath(path: string, hasProtocol: boolean) {
121
- const pathParts = path.split('/')
122
-
123
- //if the protocol was found, then there is not allowed to be a leading /
124
- assertEx(!(hasProtocol && pathParts[0].length === 0), 'Invalid protocol separator')
125
-
126
- //remove leading '/' if needed
127
- pathParts[0].length === 0 ? pathParts.shift() : null
128
-
129
- //hash is assumed to be the last part
130
- const hash = assertEx(pathParts.pop(), 'No hash specified')
131
-
132
- //archivist is assumed to be the first part
133
- this.archivist = pathParts.shift() ?? 'api.archivist.xyo.network'
134
-
135
- //the archive is whatever is left
136
- this.archive = pathParts.pop()
137
-
138
- //after we pull off all the path parts, there should be nothing left
139
- assertEx(pathParts.length === 0, 'Too many path parts')
140
-
141
- return hash
142
- }
143
-
144
- private validateParse() {
145
- //the archivist should not be zero length
146
- assertEx(this.archivist?.length !== 0, 'Invalid archivist length')
147
-
148
- //the archivist should not be zero length (can be undefined)
149
- assertEx(this.archive?.length !== 0, 'Invalid archive length')
150
-
151
- //the archive should not be set if the archivist is not set
152
- assertEx(!(this.archive && !this.archivist), 'If specifying archive, archivist is also required')
153
- }
154
- }
package/src/Huri/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './Huri'
@@ -1,120 +0,0 @@
1
- import { domainExists } from '@xyo-network/core'
2
-
3
- /**
4
- * Validates a XYO schema structure and existence
5
- */
6
- export class XyoSchemaNameValidator {
7
- public schema?: string
8
- private _parts?: string[]
9
- private _rootDomain?: string
10
- constructor(schema?: string) {
11
- this.schema = schema
12
- }
13
-
14
- /**
15
- * Checks whether the schema is all lowercase
16
- *
17
- * @returns boolean
18
- */
19
- get isLowercase(): boolean {
20
- return this.schema === this.schema?.toLowerCase()
21
- }
22
-
23
- /**
24
- * Levels in the schema
25
- *
26
- * @returns number
27
- */
28
- get levels(): number | undefined {
29
- return this.parts?.length
30
- }
31
-
32
- /**
33
- * The schema converted into a string array split on '.'
34
- *
35
- * @returns string[]
36
- */
37
- get parts() {
38
- this._parts = this._parts ?? this.schema?.split('.')
39
- return this._parts
40
- }
41
-
42
- /**
43
- * The rootDomain is the first two levels of the schema, in reverse order
44
- * This can be used to determine who 'owns' that schema, based on domain
45
- * registration
46
- *
47
- * @returns string
48
- */
49
- get rootDomain(): string | undefined {
50
- this._rootDomain = this._rootDomain ?? this.domainLevel(1)
51
- return this._rootDomain
52
- }
53
-
54
- /**
55
- * Run all static validations
56
- * @returns Error[]
57
- */
58
-
59
- public all() {
60
- const errors: Error[] = []
61
- if ((this.schema?.length ?? 0) === 0) errors.push(Error('schema missing'))
62
- else if ((this.levels ?? 0) < 3) errors.push(Error(`schema levels < 3 [${this.levels}, ${this.schema}]`))
63
- else if (!this.isLowercase) errors.push(Error(`schema not lowercase [${this.schema}]`))
64
- return errors
65
- }
66
-
67
- /**
68
- * Run all the validations
69
- * @param checkExistance - boolean
70
- * @returns Error[]
71
- */
72
-
73
- public async allDynamic() {
74
- const errors: Error[] = []
75
- if ((this.schema?.length ?? 0) === 0) errors.push(Error('schema missing'))
76
- else if (!(await this.rootDomainExists())) errors.push(Error(`schema root domain must exist [${this.rootDomain}]`))
77
- return errors
78
- }
79
-
80
- /**
81
- * Determines how many levels of the schema's reverse domain
82
- * pass DNS resolution
83
- *
84
- * @returns number (0 if none exist)
85
- */
86
- public async domainExistenceDepth() {
87
- const levels = this.levels ?? 0
88
- let level = 0
89
- while (level < levels) {
90
- if (!(await domainExists(this.domainLevel(level)))) {
91
- break
92
- }
93
- level += 1
94
- }
95
- return level
96
- }
97
-
98
- /**
99
- * Checks if the root domain validates via DNS resolution
100
- *
101
- * @returns boolean
102
- */
103
- public async rootDomainExists() {
104
- return await domainExists(this.rootDomain)
105
- }
106
-
107
- /**
108
- *
109
- * Get a domain for the schema at a certain level
110
- *
111
- * @param level - Zero based level to check
112
- * @returns string
113
- */
114
- private domainLevel(level: number): string | undefined {
115
- return this.parts
116
- ?.slice(0, level + 1)
117
- .reverse()
118
- .join('.')
119
- }
120
- }
package/src/Test/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './testPayload'
@@ -1,16 +0,0 @@
1
- import { StringKeyObject } from '@xyo-network/core'
2
-
3
- import { XyoPayload } from '../models'
4
-
5
- const testSchema = 'network.xyo.test'
6
- const testPayload: XyoPayload<StringKeyObject> = {
7
- numberField: 1,
8
- objectField: {
9
- numberField: 1,
10
- stringField: 'stringValue',
11
- },
12
- schema: testSchema,
13
- stringField: 'stringValue',
14
- }
15
-
16
- export { testPayload, testSchema }
@@ -1,52 +0,0 @@
1
- import { dumpErrors } from '@xyo-network/core'
2
-
3
- import { XyoPayload } from '../models'
4
- import { PayloadValidator } from './Validator'
5
-
6
- const testPayloadNoSchema: XyoPayload = {} as XyoPayload
7
- const testPayloadMixedCase: XyoPayload = {
8
- schema: 'network.xyo.testMixedCaseSchema',
9
- } as XyoPayload
10
- const testPayloadTooFewLevels: XyoPayload = {
11
- schema: 'network.xyo',
12
- } as XyoPayload
13
- const testPayloadDoesNotExist: XyoPayload = {
14
- schema: 'network.dfd-sf-sf-s.blahblah',
15
- } as XyoPayload
16
- const testPayloadValid: XyoPayload = {
17
- schema: 'network.xyo.test',
18
- } as XyoPayload
19
-
20
- test('all [missing schema]', () => {
21
- const validator = new PayloadValidator(testPayloadNoSchema)
22
- const errors = validator.validate()
23
- expect(errors.length).toBe(1)
24
- })
25
-
26
- test('all [mixed case]', () => {
27
- const validator = new PayloadValidator(testPayloadMixedCase)
28
- const errors = validator.validate()
29
- expect(errors.length).toBe(1)
30
- })
31
-
32
- test('all [too few levels]', () => {
33
- const validator = new PayloadValidator(testPayloadTooFewLevels)
34
- const errors = validator.validate()
35
- expect(errors.length).toBe(1)
36
- })
37
-
38
- test('all [does not exist]', () => {
39
- const validator = new PayloadValidator(testPayloadDoesNotExist)
40
- const errors = validator.validate()
41
- dumpErrors(errors)
42
- expect(errors.length).toBe(0)
43
- })
44
-
45
- test('all [valid]', () => {
46
- const validator = new PayloadValidator(testPayloadValid)
47
-
48
- let errors: Error[] = []
49
- errors = validator.validate()
50
- dumpErrors(errors)
51
- expect(errors.length).toBe(0)
52
- })