@codecks/fetch 0.1.4 → 0.1.5
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.
- package/dist/_exploration/store.js +12 -4
- package/dist/index.js +4 -3
- package/package.json +4 -4
|
@@ -98,7 +98,10 @@ var Store = class {
|
|
|
98
98
|
* Accumulates missing requests in the missingRequests array
|
|
99
99
|
*/
|
|
100
100
|
checkQueryRecursive(desc, model, id, query, missingRequests, acceptDirty) {
|
|
101
|
-
const data = {}
|
|
101
|
+
const data = model === "_root" ? {} : {
|
|
102
|
+
"~model": model,
|
|
103
|
+
"~key": id
|
|
104
|
+
};
|
|
102
105
|
const partKeys = [];
|
|
103
106
|
let allPresent = true;
|
|
104
107
|
if (query.fields) for (const field of query.fields) {
|
|
@@ -136,13 +139,18 @@ var Store = class {
|
|
|
136
139
|
if (acceptsData) {
|
|
137
140
|
if (!relatedModelDesc) throw new Error(`Model ${relatedModel} not found`);
|
|
138
141
|
const fieldName = relQuery.as || relationName;
|
|
139
|
-
if (
|
|
140
|
-
|
|
142
|
+
if (relQuery.type === "count" || relQuery.type === "exists") {
|
|
143
|
+
data[fieldName] = cachedValue.value;
|
|
144
|
+
partKeys.push(...cachedValue.partKeys);
|
|
145
|
+
} else if (Array.isArray(cachedValue.value)) {
|
|
146
|
+
const relationResults = cachedValue.value.map((key) => this.checkQueryRecursive(relatedModelDesc, relatedModel, `${key}`, relQuery, missingRequests, acceptDirty));
|
|
147
|
+
data[`~${fieldName}`] = cachedValue.value.map((v) => `${v}`);
|
|
141
148
|
data[fieldName] = relationResults.map((result) => result.data);
|
|
142
149
|
partKeys.push(...relationResults.flatMap((result) => result.partKeys));
|
|
143
150
|
if (relationResults.some((result) => !result.allPresent)) allPresent = false;
|
|
144
151
|
} else {
|
|
145
|
-
const relationResult = this.checkQueryRecursive(relatedModelDesc, relatedModel, cachedValue.value
|
|
152
|
+
const relationResult = this.checkQueryRecursive(relatedModelDesc, relatedModel, `${cachedValue.value}`, relQuery, missingRequests, acceptDirty);
|
|
153
|
+
data[`~${fieldName}`] = cachedValue.value != null ? `${cachedValue.value}` : null;
|
|
146
154
|
data[fieldName] = relationResult.data;
|
|
147
155
|
partKeys.push(...relationResult.partKeys);
|
|
148
156
|
if (!relationResult.allPresent) allPresent = false;
|
package/dist/index.js
CHANGED
|
@@ -75,10 +75,11 @@ const reconcileInstanceQuery = (query, response, instanceModel, key, store) => {
|
|
|
75
75
|
switch (opts.type) {
|
|
76
76
|
case "belongsTo":
|
|
77
77
|
result[opts.fk] = instance[relName];
|
|
78
|
+
result[`~${relName}`] = instance[relName] != null ? `${instance[relName]}` : null;
|
|
78
79
|
result[relName] = opts.fk ? reconcileInstanceQuery(relEntry, response, relModel, `${instance[relName]}`, store) : null;
|
|
79
80
|
break;
|
|
80
81
|
case "hasOne":
|
|
81
|
-
result[`~${relName}`] = instance[relName];
|
|
82
|
+
result[`~${relName}`] = instance[relName] != null ? `${instance[relName]}` : null;
|
|
82
83
|
result[relName] = reconcileInstanceQuery(relEntry, response, relModel, `${instance[relName]}`, store);
|
|
83
84
|
break;
|
|
84
85
|
case "hasMany":
|
|
@@ -92,11 +93,11 @@ const reconcileInstanceQuery = (query, response, instanceModel, key, store) => {
|
|
|
92
93
|
break;
|
|
93
94
|
}
|
|
94
95
|
case "first":
|
|
95
|
-
result[`~${asName}`] = val;
|
|
96
|
+
result[`~${asName}`] = val != null ? `${val}` : null;
|
|
96
97
|
result[asName] = reconcileInstanceQuery(relEntry, response, relModel, `${val}`, store);
|
|
97
98
|
break;
|
|
98
99
|
default: {
|
|
99
|
-
result[`~${asName}`] = val;
|
|
100
|
+
result[`~${asName}`] = val.map((v) => `${v}`);
|
|
100
101
|
result[asName] = val.map((id) => reconcileInstanceQuery(relEntry, response, relModel, `${id}`, store));
|
|
101
102
|
}
|
|
102
103
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codecks/fetch",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Quickly create deeply nested queries for the Codecks API with advanced TypeScript support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://github.com/codecks-io/
|
|
7
|
+
"homepage": "https://github.com/codecks-io/fetch#readme",
|
|
8
8
|
"bugs": {
|
|
9
|
-
"url": "https://github.com/codecks-io/
|
|
9
|
+
"url": "https://github.com/codecks-io/fetch/issues"
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/codecks-io/
|
|
13
|
+
"url": "git+https://github.com/codecks-io/fetch.git"
|
|
14
14
|
},
|
|
15
15
|
"author": "Daniel Berndt <daniel@codecks.io>",
|
|
16
16
|
"files": [
|