@rxferrix/client 0.0.0-stage → 0.1.0

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 (97) hide show
  1. package/dist/api.d.ts +60 -0
  2. package/dist/api.d.ts.map +1 -0
  3. package/dist/api.js +22 -0
  4. package/dist/api.js.map +1 -0
  5. package/dist/auth.d.ts +251 -0
  6. package/dist/auth.d.ts.map +1 -0
  7. package/dist/auth.js +531 -0
  8. package/dist/auth.js.map +1 -0
  9. package/dist/bytes.d.ts +21 -0
  10. package/dist/bytes.d.ts.map +1 -0
  11. package/dist/bytes.js +51 -0
  12. package/dist/bytes.js.map +1 -0
  13. package/dist/canonical.d.ts +13 -0
  14. package/dist/canonical.d.ts.map +1 -0
  15. package/dist/canonical.js +66 -0
  16. package/dist/canonical.js.map +1 -0
  17. package/dist/client.d.ts +170 -0
  18. package/dist/client.d.ts.map +1 -0
  19. package/dist/client.js +638 -0
  20. package/dist/client.js.map +1 -0
  21. package/dist/diff.d.ts +20 -0
  22. package/dist/diff.d.ts.map +1 -0
  23. package/dist/diff.js +100 -0
  24. package/dist/diff.js.map +1 -0
  25. package/dist/errors.d.ts +24 -0
  26. package/dist/errors.d.ts.map +1 -0
  27. package/dist/errors.js +34 -0
  28. package/dist/errors.js.map +1 -0
  29. package/dist/index.d.ts +14 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +12 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/local_query_set.d.ts +56 -0
  34. package/dist/local_query_set.d.ts.map +1 -0
  35. package/dist/local_query_set.js +108 -0
  36. package/dist/local_query_set.js.map +1 -0
  37. package/dist/logging.d.ts +15 -0
  38. package/dist/logging.d.ts.map +1 -0
  39. package/dist/logging.js +17 -0
  40. package/dist/logging.js.map +1 -0
  41. package/dist/optimistic_updates.d.ts +48 -0
  42. package/dist/optimistic_updates.d.ts.map +1 -0
  43. package/dist/optimistic_updates.js +113 -0
  44. package/dist/optimistic_updates.js.map +1 -0
  45. package/dist/paginated_query.d.ts +118 -0
  46. package/dist/paginated_query.d.ts.map +1 -0
  47. package/dist/paginated_query.js +199 -0
  48. package/dist/paginated_query.js.map +1 -0
  49. package/dist/protocol.d.ts +136 -0
  50. package/dist/protocol.d.ts.map +1 -0
  51. package/dist/protocol.js +11 -0
  52. package/dist/protocol.js.map +1 -0
  53. package/dist/query_state.d.ts +16 -0
  54. package/dist/query_state.d.ts.map +1 -0
  55. package/dist/query_state.js +2 -0
  56. package/dist/query_state.js.map +1 -0
  57. package/dist/remote_query_set.d.ts +37 -0
  58. package/dist/remote_query_set.d.ts.map +1 -0
  59. package/dist/remote_query_set.js +87 -0
  60. package/dist/remote_query_set.js.map +1 -0
  61. package/dist/request_manager.d.ts +57 -0
  62. package/dist/request_manager.d.ts.map +1 -0
  63. package/dist/request_manager.js +163 -0
  64. package/dist/request_manager.js.map +1 -0
  65. package/dist/storage.d.ts +45 -0
  66. package/dist/storage.d.ts.map +1 -0
  67. package/dist/storage.js +120 -0
  68. package/dist/storage.js.map +1 -0
  69. package/dist/testing.d.ts +68 -0
  70. package/dist/testing.d.ts.map +1 -0
  71. package/dist/testing.js +97 -0
  72. package/dist/testing.js.map +1 -0
  73. package/dist/web_socket_manager.d.ts +88 -0
  74. package/dist/web_socket_manager.d.ts.map +1 -0
  75. package/dist/web_socket_manager.js +291 -0
  76. package/dist/web_socket_manager.js.map +1 -0
  77. package/package.json +50 -4
  78. package/src/api.ts +86 -0
  79. package/src/auth.ts +636 -0
  80. package/src/bytes.ts +57 -0
  81. package/src/canonical.ts +61 -0
  82. package/src/client.ts +740 -0
  83. package/src/diff.ts +87 -0
  84. package/src/errors.ts +36 -0
  85. package/src/index.ts +60 -0
  86. package/src/local_query_set.ts +130 -0
  87. package/src/logging.ts +26 -0
  88. package/src/optimistic_updates.ts +137 -0
  89. package/src/paginated_query.ts +299 -0
  90. package/src/protocol.ts +152 -0
  91. package/src/query_state.ts +12 -0
  92. package/src/remote_query_set.ts +105 -0
  93. package/src/request_manager.ts +199 -0
  94. package/src/storage.ts +171 -0
  95. package/src/testing.ts +120 -0
  96. package/src/web_socket_manager.ts +322 -0
  97. package/README.md +0 -3
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Canonical JSON: `JSON.stringify` with object keys sorted recursively. Two arg objects that are structurally equal
3
+ * produce the same string, regardless of key insertion order. `undefined` object values are dropped, as in JSON.
4
+ */
5
+ export function canonicalJSON(value: unknown): string {
6
+ return JSON.stringify(sortKeys(value)) ?? "null";
7
+ }
8
+
9
+ function sortKeys(value: unknown): unknown {
10
+ if (value === null || typeof value !== "object") return value;
11
+ if (typeof (value as { toJSON?: unknown }).toJSON === "function") {
12
+ return sortKeys((value as { toJSON: () => unknown }).toJSON());
13
+ }
14
+ if (Array.isArray(value)) return value.map(sortKeys);
15
+ const out: Record<string, unknown> = {};
16
+ for (const key of Object.keys(value).sort()) {
17
+ const v = (value as Record<string, unknown>)[key];
18
+ if (v === undefined || typeof v === "function" || typeof v === "symbol") continue;
19
+ out[key] = sortKeys(v);
20
+ }
21
+ return out;
22
+ }
23
+
24
+ /** The client-side identity of a query: `udfPath + canonicalJSON(args)`. */
25
+ export type QueryToken = string;
26
+
27
+ export function queryToken(udfPath: string, args: Record<string, unknown>): QueryToken {
28
+ return udfPath + canonicalJSON(args);
29
+ }
30
+
31
+ /** Structural equality for JSON values (as produced by `JSON.parse`). */
32
+ export function jsonEqual(a: unknown, b: unknown): boolean {
33
+ if (a === b) return true;
34
+ if (typeof a !== typeof b || a === null || b === null || typeof a !== "object") {
35
+ // NaN never appears in JSON; plain === suffices for primitives.
36
+ return false;
37
+ }
38
+ if (Array.isArray(a)) {
39
+ if (!Array.isArray(b) || a.length !== b.length) return false;
40
+ for (let i = 0; i < a.length; i++) if (!jsonEqual(a[i], b[i])) return false;
41
+ return true;
42
+ }
43
+ if (Array.isArray(b)) return false;
44
+ const ao = a as Record<string, unknown>;
45
+ const bo = b as Record<string, unknown>;
46
+ const aKeys = Object.keys(ao);
47
+ if (aKeys.length !== Object.keys(bo).length) return false;
48
+ for (const k of aKeys) {
49
+ if (!Object.prototype.hasOwnProperty.call(bo, k) || !jsonEqual(ao[k], bo[k])) return false;
50
+ }
51
+ return true;
52
+ }
53
+
54
+ /** Normalizes user-supplied args: `undefined` becomes `{}`; anything else must be a plain object. */
55
+ export function normalizeArgs(args: unknown): Record<string, unknown> {
56
+ if (args === undefined || args === null) return {};
57
+ if (typeof args !== "object" || Array.isArray(args)) {
58
+ throw new TypeError(`RxFerrix function args must be an object, got ${Array.isArray(args) ? "array" : typeof args}`);
59
+ }
60
+ return args as Record<string, unknown>;
61
+ }