@anysoftinc/anydb-sdk 0.7.0 → 0.8.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 (2) hide show
  1. package/dist/client.js +32 -28
  2. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -80,57 +80,67 @@ export function stringifyEdn(obj) {
80
80
  }
81
81
  return String(obj);
82
82
  }
83
- // Normalize edn-data parsed value into JS with keywordized keys (no leading colon)
83
+ // ===== Type Guards =====
84
+ function isKeyword(v) {
85
+ return typeof v === "object" && v !== null && v._type === "keyword";
86
+ }
87
+ function isSymbol(v) {
88
+ return typeof v === "object" && v !== null && v._type === "symbol";
89
+ }
90
+ // Normalize edn-data parsed value into JS with consistent symbolic types
91
+ // Keywords and symbols are returned as typed objects for round-trip consistency
84
92
  function normalizeEdn(value) {
85
93
  if (value === null || value === undefined)
86
94
  return value;
87
95
  // Preserve native Date instances returned by the parser
88
96
  if (value instanceof Date)
89
97
  return value;
90
- // edn-data often wraps keywords/symbols/strings as { key: '...' } or { sym: '...' }
98
+ // edn-data wraps keywords/symbols as { key: '...' } or { sym: '...' }
91
99
  if (typeof value === "object" && value) {
100
+ // Keywords: return as Keyword object for consistency with kw()
92
101
  if (typeof value.key === "string") {
93
102
  const key = value.key; // e.g., ":db/ident"
94
- return key.startsWith(":") ? key.slice(1) : key;
103
+ const bareKey = key.startsWith(":") ? key.slice(1) : key;
104
+ return { _type: "keyword", value: bareKey };
95
105
  }
106
+ // Symbols: return as Symbol object for consistency with sym()
96
107
  if (typeof value.sym === "string") {
97
- return value.sym;
108
+ return { _type: "symbol", value: value.sym };
109
+ }
110
+ // Tagged values - check before generic object handling
111
+ if (value.tag === "inst" && typeof value.val === "string") {
112
+ const d = new Date(value.val);
113
+ return isNaN(d.getTime()) ? value.val : d;
114
+ }
115
+ if (value.tag === "uuid" && typeof value.val === "string") {
116
+ return { _type: "uuid", value: value.val };
98
117
  }
118
+ // Sets
99
119
  if (value instanceof Set) {
100
120
  return Array.from(value, (v) => normalizeEdn(v));
101
121
  }
102
122
  if (Array.isArray(value.set)) {
103
123
  return value.set.map((v) => normalizeEdn(v));
104
124
  }
125
+ // Maps (EDN maps come as array of [k,v] pairs)
105
126
  if (Array.isArray(value.map)) {
106
127
  const out = {};
107
128
  for (const [k, v] of value.map) {
108
129
  const kNorm = normalizeEdn(k);
109
- const kStr = typeof kNorm === "string" ? kNorm : String(kNorm);
110
- const bareKey = kStr.startsWith(":") ? kStr.slice(1) : kStr;
111
- out[bareKey] = normalizeEdn(v);
130
+ // Extract string key from symbolic types (Keyword, Symbol, UUID) for JS object keys
131
+ const kStr = (typeof kNorm === "object" && kNorm !== null && "_type" in kNorm && "value" in kNorm)
132
+ ? kNorm.value
133
+ : kNorm;
134
+ out[kStr] = normalizeEdn(v);
112
135
  }
113
136
  return out;
114
137
  }
115
138
  }
116
139
  if (Array.isArray(value))
117
140
  return value.map((v) => normalizeEdn(v));
118
- // Tagged values
119
- if (typeof value === "object" &&
120
- value &&
121
- value.tag === "inst" &&
122
- typeof value.val === "string") {
123
- const d = new Date(value.val);
124
- return isNaN(d.getTime()) ? value.val : d;
125
- }
126
- if (typeof value === "object" &&
127
- value &&
128
- value.tag === "uuid" &&
129
- typeof value.val === "string") {
130
- return { _type: "uuid", value: value.val };
131
- }
141
+ // Generic object fallback
132
142
  if (typeof value === "object") {
133
- const out = Array.isArray(value) ? [] : {};
143
+ const out = {};
134
144
  for (const [k, v] of Object.entries(value)) {
135
145
  out[k] = normalizeEdn(v);
136
146
  }
@@ -139,12 +149,6 @@ function normalizeEdn(value) {
139
149
  return value;
140
150
  }
141
151
  // ===== Validation =====
142
- function isKeyword(v) {
143
- return typeof v === "object" && v !== null && v._type === "keyword";
144
- }
145
- function isSymbol(v) {
146
- return typeof v === "object" && v !== null && v._type === "symbol";
147
- }
148
152
  function validateSymbolicQuery(q) {
149
153
  if (!q ||
150
154
  typeof q !== "object" ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anysoftinc/anydb-sdk",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "AnyDB TypeScript SDK for querying and transacting with Datomic databases",
5
5
  "main": "dist/client.js",
6
6
  "types": "dist/client.d.ts",