@voxgig/sdkgen 4.40.0 → 4.41.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.
- package/bin/voxgig-sdkgen +1 -1
- package/dist/cmp/Main.js +4 -0
- package/dist/cmp/Main.js.map +1 -1
- package/dist/helpers/testPolicy.d.ts +5 -1
- package/dist/helpers/testPolicy.js +32 -3
- package/dist/helpers/testPolicy.js.map +1 -1
- package/dist/helpers/useragent.d.ts +2 -0
- package/dist/helpers/useragent.js +31 -0
- package/dist/helpers/useragent.js.map +1 -0
- package/dist/sdkgen.d.ts +2 -2
- package/dist/sdkgen.js +6 -3
- package/dist/sdkgen.js.map +1 -1
- package/dist/testkit.js +1 -1
- package/dist/testkit.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/model/sdkgen.aontu +6 -0
- package/package.json +2 -2
- package/project/.sdk/src/cmp/csharp/TestEntity_csharp.ts +35 -16
- package/project/.sdk/src/cmp/go/ReadmeExamplesTest_go.ts +7 -6
- package/project/.sdk/src/cmp/go/TestEntity_go.ts +24 -13
- package/project/.sdk/src/cmp/java/TestEntity_java.ts +21 -11
- package/project/.sdk/src/cmp/kotlin/TestEntity_kotlin.ts +26 -14
- package/project/.sdk/src/cmp/lua/ReadmeExamplesTest_lua.ts +7 -5
- package/project/.sdk/src/cmp/lua/ReadmeHowto_lua.ts +12 -0
- package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +25 -13
- package/project/.sdk/src/cmp/perl/ReadmeExamplesTest_perl.ts +15 -1
- package/project/.sdk/src/cmp/perl/TestEntity_perl.ts +23 -13
- package/project/.sdk/src/cmp/php/ReadmeExamplesTest_php.ts +31 -2
- package/project/.sdk/src/cmp/php/TestEntity_php.ts +29 -14
- package/project/.sdk/src/cmp/py/ReadmeExamplesTest_py.ts +14 -1
- package/project/.sdk/src/cmp/py/TestEntity_py.ts +28 -14
- package/project/.sdk/src/cmp/rb/ReadmeExamplesTest_rb.ts +18 -1
- package/project/.sdk/src/cmp/rb/TestEntity_rb.ts +24 -13
- package/project/.sdk/src/cmp/rust/TestEntity_rust.ts +27 -14
- package/project/.sdk/src/cmp/ts/ReadmeExamplesTest_ts.ts +7 -2
- package/project/.sdk/tm/c/feature/test.c +22 -2
- package/project/.sdk/tm/c/tests/transport_test.c +2 -2
- package/project/.sdk/tm/c/utility/http.c +1 -1
- package/project/.sdk/tm/clojure/src/sdk/core.clj +1 -1
- package/project/.sdk/tm/clojure/src/sdk/features.clj +13 -1
- package/project/.sdk/tm/cpp/feature/test.hpp +16 -2
- package/project/.sdk/tm/csharp/feature/TestFeature.cs +18 -0
- package/project/.sdk/tm/csharp/utility/Fetcher.cs +5 -4
- package/project/.sdk/tm/elixir/lib/projectname/feature/test.ex +19 -1
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +1 -1
- package/project/.sdk/tm/go/feature/test_feature.go +16 -0
- package/project/.sdk/tm/go/utility/fetcher.go +4 -3
- package/project/.sdk/tm/java/feature/TestFeature.java +15 -0
- package/project/.sdk/tm/java/utility/Fetcher.java +4 -4
- package/project/.sdk/tm/js/src/feature/test/TestFeature.js +16 -0
- package/project/.sdk/tm/js/src/utility/FetcherUtility.js +4 -3
- package/project/.sdk/tm/js/src/utility/ResultBodyUtility.js +19 -1
- package/project/.sdk/tm/js/test/live-entity.js +2 -1
- package/project/.sdk/tm/kotlin/feature/TestFeature.kt +15 -0
- package/project/.sdk/tm/kotlin/utility/Fetcher.kt +1 -1
- package/project/.sdk/tm/lua/feature/secrets_feature.lua +9 -2
- package/project/.sdk/tm/lua/feature/test_feature.lua +18 -0
- package/project/.sdk/tm/lua/utility/fetcher.lua +11 -25
- package/project/.sdk/tm/lua/utility/tls.lua +241 -0
- package/project/.sdk/tm/ocaml/sdk_features.ml +18 -1
- package/project/.sdk/tm/perl/feature/test_feature.pm +12 -0
- package/project/.sdk/tm/perl/utility/fetcher.pm +4 -4
- package/project/.sdk/tm/php/feature/TestFeature.php +18 -1
- package/project/.sdk/tm/php/utility/Fetcher.php +4 -4
- package/project/.sdk/tm/py/pkg/feature/test_feature.py +20 -4
- package/project/.sdk/tm/py/pkg/utility/fetcher.py +4 -4
- package/project/.sdk/tm/rb/feature/test_feature.rb +14 -1
- package/project/.sdk/tm/rb/utility/fetcher.rb +56 -6
- package/project/.sdk/tm/rust/feature/test.rs +18 -0
- package/project/.sdk/tm/rust/utility/fetcher.rs +4 -4
- package/project/.sdk/tm/scala/feature/TestFeature.scala +12 -0
- package/project/.sdk/tm/scala/utility/Fetcher.scala +1 -1
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TestFeature.swift +15 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +1 -1
- package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +26 -5
- package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +4 -3
- package/project/.sdk/tm/ts/src/utility/ResultBodyUtility.ts +19 -1
- package/project/.sdk/tm/ts/test/live-entity.ts +2 -1
- package/project/.sdk/tm/zig/feature/test.zig +23 -0
- package/project/sdkgen-package.json +1 -1
- package/src/cmp/Main.ts +5 -0
- package/src/helpers/testPolicy.ts +32 -3
- package/src/helpers/useragent.ts +41 -0
- package/src/sdkgen.ts +4 -0
- package/src/testkit.ts +1 -1
|
@@ -13,12 +13,17 @@ const ReadmeExamplesTest = cmp(function ReadmeExamplesTest(props: any) {
|
|
|
13
13
|
|
|
14
14
|
// Seed a fixture for every active entity so list()/load() resolve
|
|
15
15
|
// offline in test mode with no network. Keyed by the entity's model
|
|
16
|
-
// name (the same key the test-mode transport looks up)
|
|
16
|
+
// name (the same key the test-mode transport looks up), and the record
|
|
17
|
+
// carries the entity's declared identity field as well as `id`.
|
|
17
18
|
const entity = getModelPath(model, `main.${KIT}.entity`)
|
|
18
19
|
const seedEntities: Record<string, any> = {}
|
|
19
20
|
Object.values(entity).forEach((e: any) => {
|
|
20
21
|
if (e && false !== e.active && 'string' === typeof e.name) {
|
|
21
|
-
|
|
22
|
+
const idField = e.id?.field
|
|
23
|
+
seedEntities[e.name] = {
|
|
24
|
+
test01: 'string' === typeof idField && '' !== idField
|
|
25
|
+
? { id: 'test01', [idField]: 'test01' } : { id: 'test01' },
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
28
|
})
|
|
24
29
|
const seedLiteral = JSON.stringify({ entity: seedEntities })
|
|
@@ -223,6 +223,17 @@ static voxgig_value* build_args(Context* ctx, voxgig_value* args) {
|
|
|
223
223
|
return q;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
+
// The entity's declared identity field (`entity.id.field`), where it names
|
|
227
|
+
// one other than the `id` every record already carries; NULL otherwise.
|
|
228
|
+
static const char* declared_id_field(voxgig_value* config, const char* entname) {
|
|
229
|
+
if (entname == NULL) return NULL;
|
|
230
|
+
const char* keys[5] = {"entity", entname, "id", "field", NULL};
|
|
231
|
+
voxgig_value* field = getpath_c(config, keys);
|
|
232
|
+
if (!voxgig_is_string(field)) return NULL;
|
|
233
|
+
const char* f = voxgig_as_string(field);
|
|
234
|
+
return ('\0' == f[0] || 0 == strcmp(f, "id")) ? NULL : f;
|
|
235
|
+
}
|
|
236
|
+
|
|
226
237
|
static voxgig_value* test_fetch(voxgig_value* entity, Context* ctx, const char* fullurl,
|
|
227
238
|
voxgig_value* fetchdef, PNError** err) {
|
|
228
239
|
(void)fullurl;
|
|
@@ -334,6 +345,11 @@ static voxgig_value* test_fetch(voxgig_value* entity, Context* ctx, const char*
|
|
|
334
345
|
if (voxgig_is_map(ent)) {
|
|
335
346
|
voxgig_delprop(ent, v_str("$body"));
|
|
336
347
|
setp(ent, "id", id);
|
|
348
|
+
const char* id_field = declared_id_field(ctx->config, op->entity);
|
|
349
|
+
if (id_field != NULL) {
|
|
350
|
+
voxgig_value* had = getp(ent, id_field);
|
|
351
|
+
if (v_is_noval(had) || v_is_null(had)) setp(ent, id_field, id);
|
|
352
|
+
}
|
|
337
353
|
if (voxgig_is_string(id)) {
|
|
338
354
|
setp(entmap, voxgig_as_string(id), ent);
|
|
339
355
|
}
|
|
@@ -425,10 +441,14 @@ static voxgig_value* test_netsim_fn(Fetcher* self, Context* ctx, const char* url
|
|
|
425
441
|
static voxgig_value* fix_ids(voxgig_value* key, voxgig_value* val, voxgig_value* parent,
|
|
426
442
|
voxgig_value* path, void* ud) {
|
|
427
443
|
(void)parent;
|
|
428
|
-
(void)ud;
|
|
429
444
|
if (voxgig_size(path) == 2) {
|
|
430
445
|
if (voxgig_is_map(val) && voxgig_is_string(key)) {
|
|
431
446
|
setp(val, "id", v_str(voxgig_as_string(key)));
|
|
447
|
+
voxgig_value* entname = voxgig_getelem(path, v_int(0), NULL);
|
|
448
|
+
const char* id_field = voxgig_is_string(entname)
|
|
449
|
+
? declared_id_field((voxgig_value*)ud, voxgig_as_string(entname))
|
|
450
|
+
: NULL;
|
|
451
|
+
if (id_field != NULL) setp(val, id_field, v_str(voxgig_as_string(key)));
|
|
432
452
|
}
|
|
433
453
|
}
|
|
434
454
|
return voxgig_retain(val);
|
|
@@ -460,7 +480,7 @@ static void test_init(Feature* f, Context* ctx, voxgig_value* options) {
|
|
|
460
480
|
}
|
|
461
481
|
|
|
462
482
|
// Ensure entity ids are correct.
|
|
463
|
-
voxgig_walk(entity, fix_ids, NULL, VOXGIG_MAXDEPTH,
|
|
483
|
+
voxgig_walk(entity, fix_ids, NULL, VOXGIG_MAXDEPTH, ctx->config);
|
|
464
484
|
|
|
465
485
|
TestState* ts = (TestState*)calloc(1, sizeof(TestState));
|
|
466
486
|
ts->entity = entity;
|
|
@@ -258,9 +258,9 @@ int main(void) {
|
|
|
258
258
|
voxgig_value* seen = json_of(res);
|
|
259
259
|
CHECK_INT_EQ(to_int(getp(res, "status")), 200, "the GET's status");
|
|
260
260
|
CHECK_STR_EQ(get_str(seen, "target"), "/echo?x=1&y=two", "the query reaches the server");
|
|
261
|
-
CHECK_STR_EQ(get_str(seen, "user-agent"), "
|
|
261
|
+
CHECK_STR_EQ(get_str(seen, "user-agent"), "PROJECTUSERAGENT",
|
|
262
262
|
"the default agent is sent");
|
|
263
|
-
CHECK_STR_EQ(get_str(sent, "user-agent"), "
|
|
263
|
+
CHECK_STR_EQ(get_str(sent, "user-agent"), "PROJECTUSERAGENT",
|
|
264
264
|
"the default agent is recorded with the headers sent");
|
|
265
265
|
CHECK_STR_EQ(get_str(seen, "connection"), "close", "one request per connection");
|
|
266
266
|
snprintf(url, sizeof(url), "127.0.0.1:%d", port);
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
#define HTTP_MAX_BYTES (32 * 1024 * 1024)
|
|
30
30
|
#endif
|
|
31
31
|
|
|
32
|
-
#define HTTP_USER_AGENT "
|
|
32
|
+
#define HTTP_USER_AGENT "PROJECTUSERAGENT"
|
|
33
33
|
|
|
34
34
|
// The URL as an error may quote it: no userinfo, query or fragment.
|
|
35
35
|
static char* bare_url(const char* url) {
|
|
@@ -1866,7 +1866,7 @@
|
|
|
1866
1866
|
(.setHeader builder (str k) v))))
|
|
1867
1867
|
;; The default User-Agent is recorded with the headers the request sent.
|
|
1868
1868
|
(when-not @has-ua
|
|
1869
|
-
(let [ua
|
|
1869
|
+
(let [ua "PROJECTUSERAGENT"]
|
|
1870
1870
|
(.setHeader builder "User-Agent" ua)
|
|
1871
1871
|
(vs/setprop headers "user-agent" ua)))
|
|
1872
1872
|
(let [client (if (= "manual" (vs/getprop fetchdef "redirect")) @manual-http-client @http-client)
|
|
@@ -122,6 +122,13 @@
|
|
|
122
122
|
(when (string? merge)
|
|
123
123
|
(second (re-matches #"`\.([^.`$]+)`" merge))))))
|
|
124
124
|
|
|
125
|
+
;; The entity's declared identity field (`entity.id.field`), where it names
|
|
126
|
+
;; one other than the `id` every record already carries.
|
|
127
|
+
(defn- declared-id-field [config entname]
|
|
128
|
+
(when (string? entname)
|
|
129
|
+
(let [field (vs/getpath config (vs/jt "entity" entname "id" "field"))]
|
|
130
|
+
(when (and (string? field) (not= field "") (not= field "id")) field))))
|
|
131
|
+
|
|
125
132
|
(defn test-feature []
|
|
126
133
|
(let [fa (new-feature "test" true "0.0.1")]
|
|
127
134
|
(swap! fa assoc
|
|
@@ -133,7 +140,9 @@
|
|
|
133
140
|
;; Ensure entity ids are correct (id = key at depth 2).
|
|
134
141
|
(vs/walk entity (fn [key val _parent path]
|
|
135
142
|
(when (and (= (vs/size path) 2) (vs/ismap val) key)
|
|
136
|
-
(.put ^java.util.Map val "id" key)
|
|
143
|
+
(.put ^java.util.Map val "id" key)
|
|
144
|
+
(when-let [id-field (declared-id-field (core/oget ctx :config) (vs/getelem path 0))]
|
|
145
|
+
(.put ^java.util.Map val id-field key)))
|
|
137
146
|
val))
|
|
138
147
|
(let [test-fetcher
|
|
139
148
|
(fn [fctx _fullurl _fetchdef]
|
|
@@ -226,6 +235,9 @@
|
|
|
226
235
|
(if (vs/ismap ent)
|
|
227
236
|
(do (vs/delprop ent "$body")
|
|
228
237
|
(.put ^java.util.Map ent "id" id)
|
|
238
|
+
(when-let [id-field (declared-id-field (core/oget fctx :config) (core/op-entity op))]
|
|
239
|
+
(when (nil? (vs/getprop ent id-field))
|
|
240
|
+
(.put ^java.util.Map ent id-field id)))
|
|
229
241
|
(when (string? id) (.put ^java.util.Map entmap (str id) ent))
|
|
230
242
|
(vs/delprop ent "$KEY")
|
|
231
243
|
(respond 200 (vs/clone ent) nil))
|
|
@@ -32,10 +32,13 @@ public:
|
|
|
32
32
|
|
|
33
33
|
// Ensure entity ids are correct (2-deep maps get id = their key).
|
|
34
34
|
if (entity.is_map()) {
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
Value config = ctx->config;
|
|
36
|
+
Struct::walk(entity, [config](const Value& key, const Value& val, const Value& parent,
|
|
37
|
+
const std::vector<std::string>& path) -> Value {
|
|
37
38
|
if (path.size() == 2 && val.is_map() && key.is_string()) {
|
|
38
39
|
map_put(val, "id", key);
|
|
40
|
+
std::string idField = declaredIdField(config, path[0]);
|
|
41
|
+
if (!idField.empty()) map_put(val, idField, key);
|
|
39
42
|
}
|
|
40
43
|
return val;
|
|
41
44
|
});
|
|
@@ -57,6 +60,15 @@ public:
|
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
private:
|
|
63
|
+
// The entity's declared identity field (`entity.id.field`), where it names
|
|
64
|
+
// one other than the `id` every record already carries; empty otherwise.
|
|
65
|
+
static std::string declaredIdField(const Value& config, const std::string& entityName) {
|
|
66
|
+
Value field = Struct::getpath(config, {"entity", entityName, "id", "field"});
|
|
67
|
+
if (!field.is_string()) return "";
|
|
68
|
+
std::string f = field.as_string();
|
|
69
|
+
return "id" == f ? "" : f;
|
|
70
|
+
}
|
|
71
|
+
|
|
60
72
|
// The key a list's response transform
|
|
61
73
|
// ["`$EACH`", "body", {"`$MERGE`": "`.<key>`"}] reads each item's record
|
|
62
74
|
// under; empty for any other transform.
|
|
@@ -234,6 +246,8 @@ private:
|
|
|
234
246
|
if (ent.is_map()) {
|
|
235
247
|
Struct::delprop(ent, Value("$body"));
|
|
236
248
|
map_put(ent, "id", id);
|
|
249
|
+
std::string idField = declaredIdField(ctx->config, op->entity);
|
|
250
|
+
if (!idField.empty() && is_nullish(getp(ent, idField))) map_put(ent, idField, id);
|
|
237
251
|
if (id.is_string()) map_put(entmap, id.as_string(), ent);
|
|
238
252
|
Struct::delprop(ent, Value("$KEY"));
|
|
239
253
|
Value out = Struct::clone(ent);
|
|
@@ -39,6 +39,11 @@ public class TestFeature : BaseFeature
|
|
|
39
39
|
if (path.Count == 2 && val is Dictionary<string, object?> m && key != null)
|
|
40
40
|
{
|
|
41
41
|
m["id"] = StructUtils.StrKey(key);
|
|
42
|
+
var idField = DeclaredIdField(ctx.Config, StructUtils.StrKey(path[0]));
|
|
43
|
+
if (idField != null)
|
|
44
|
+
{
|
|
45
|
+
m[idField] = StructUtils.StrKey(key);
|
|
46
|
+
}
|
|
42
47
|
}
|
|
43
48
|
return val;
|
|
44
49
|
});
|
|
@@ -240,6 +245,11 @@ public class TestFeature : BaseFeature
|
|
|
240
245
|
if (ent is Dictionary<string, object?> entm)
|
|
241
246
|
{
|
|
242
247
|
entm["id"] = id;
|
|
248
|
+
var idField = DeclaredIdField(ctx2.Config, op.Entity);
|
|
249
|
+
if (idField != null && StructUtils.GetProp(entm, idField) == null)
|
|
250
|
+
{
|
|
251
|
+
entm[idField] = id;
|
|
252
|
+
}
|
|
243
253
|
if (id is string idStr)
|
|
244
254
|
{
|
|
245
255
|
entmap![idStr] = entm;
|
|
@@ -338,6 +348,14 @@ public class TestFeature : BaseFeature
|
|
|
338
348
|
};
|
|
339
349
|
}
|
|
340
350
|
|
|
351
|
+
// The entity's declared identity field (`entity.id.field`), where it names
|
|
352
|
+
// one other than the `id` every record already carries.
|
|
353
|
+
private static string? DeclaredIdField(Dictionary<string, object?>? config, string? entityName)
|
|
354
|
+
{
|
|
355
|
+
var field = StructUtils.GetPath(config, StructUtils.Jt("entity", entityName ?? "", "id", "field"));
|
|
356
|
+
return field is string f && f != "" && f != "id" ? f : null;
|
|
357
|
+
}
|
|
358
|
+
|
|
341
359
|
// The record the mock keeps: the request data without `$body`, which only the
|
|
342
360
|
// wire carries.
|
|
343
361
|
private static Dictionary<string, object?>? Record(Dictionary<string, object?>? reqdata)
|
|
@@ -145,12 +145,13 @@ public static partial class SdkUtility
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
// Default User-Agent - some CDNs block requests without one. Use
|
|
149
|
-
//
|
|
150
|
-
//
|
|
148
|
+
// Default User-Agent - some CDNs block requests without one. Use the
|
|
149
|
+
// project's agent (main.kit.http.useragent, browser-shaped by default)
|
|
150
|
+
// unless the caller already set one, and record it with the headers
|
|
151
|
+
// the request sent.
|
|
151
152
|
if (!hasUA)
|
|
152
153
|
{
|
|
153
|
-
var agent = "
|
|
154
|
+
var agent = "PROJECTUSERAGENT";
|
|
154
155
|
req.Headers.TryAddWithoutValidation("User-Agent", agent);
|
|
155
156
|
if (hraw is Dictionary<string, object?> sent)
|
|
156
157
|
{
|
|
@@ -26,9 +26,16 @@ defmodule ProjectName.Feature.Test do
|
|
|
26
26
|
S.setprop(S.getprop(ctx, "client"), "mode", "test")
|
|
27
27
|
|
|
28
28
|
# Ensure entity records carry their id (the map key).
|
|
29
|
+
config = S.getprop(ctx, "config")
|
|
30
|
+
|
|
29
31
|
S.walk(entity,
|
|
30
32
|
before: fn key, val, _parent, path ->
|
|
31
|
-
if S.size(path) == 2 and S.ismap(val) and key != nil
|
|
33
|
+
if S.size(path) == 2 and S.ismap(val) and key != nil do
|
|
34
|
+
S.setprop(val, "id", key)
|
|
35
|
+
id_field = declared_id_field(config, S.getelem(path, 0))
|
|
36
|
+
if id_field != nil, do: S.setprop(val, id_field, key)
|
|
37
|
+
end
|
|
38
|
+
|
|
32
39
|
val
|
|
33
40
|
end
|
|
34
41
|
)
|
|
@@ -223,6 +230,8 @@ defmodule ProjectName.Feature.Test do
|
|
|
223
230
|
if S.ismap(ent) do
|
|
224
231
|
S.delprop(ent, "$body")
|
|
225
232
|
S.setprop(ent, "id", eid)
|
|
233
|
+
id_field = declared_id_field(S.getprop(fctx, "config"), S.getprop(op, "entity"))
|
|
234
|
+
if id_field != nil and S.getprop(ent, id_field) == nil, do: S.setprop(ent, id_field, eid)
|
|
226
235
|
if is_binary(eid), do: S.setprop(entmap, eid, ent)
|
|
227
236
|
S.delprop(ent, "$KEY")
|
|
228
237
|
respond(fctx, 200, S.clone(ent))
|
|
@@ -278,6 +287,15 @@ defmodule ProjectName.Feature.Test do
|
|
|
278
287
|
S.transform(reqd_args, S.jt(["`$EACH`", "", "`$KEY.name`"]))
|
|
279
288
|
end
|
|
280
289
|
|
|
290
|
+
# The entity's declared identity field (`entity.id.field`), where it names
|
|
291
|
+
# one other than the `id` every record already carries.
|
|
292
|
+
def declared_id_field(config, entname) when is_binary(entname) do
|
|
293
|
+
field = S.getpath(config, S.jt(["entity", entname, "id", "field"]))
|
|
294
|
+
if is_binary(field) and field != "" and field != "id", do: field, else: nil
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
def declared_id_field(_config, _entname), do: nil
|
|
298
|
+
|
|
281
299
|
# Build a struct select query ($AND of $OR alternatives) from the required
|
|
282
300
|
# params + id, resolving each value through the pipeline param resolver.
|
|
283
301
|
def build_args(_f, ctx, op, args) do
|
|
@@ -17,7 +17,7 @@ defmodule ProjectName.Utility do
|
|
|
17
17
|
# src/cmp/elixir/PrepareAuth_elixir.ts into lib/<app>/prepare_auth.ex.
|
|
18
18
|
alias ProjectName.PrepareAuth
|
|
19
19
|
|
|
20
|
-
@default_user_agent "
|
|
20
|
+
@default_user_agent "PROJECTUSERAGENT"
|
|
21
21
|
|
|
22
22
|
# Content type every GraphQL-over-HTTP request uses.
|
|
23
23
|
@graphql_content_type "application/json"
|
|
@@ -32,6 +32,16 @@ func itemEnvelopeKey(restf any) string {
|
|
|
32
32
|
return ""
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
// The entity's declared identity field (`entity.id.field`), where it names
|
|
36
|
+
// one other than the `id` every record already carries.
|
|
37
|
+
func declaredIdField(config map[string]any, entityName string) string {
|
|
38
|
+
field, _ := vs.GetPath(config, []any{"entity", entityName, "id", "field"}).(string)
|
|
39
|
+
if field == "id" {
|
|
40
|
+
return ""
|
|
41
|
+
}
|
|
42
|
+
return field
|
|
43
|
+
}
|
|
44
|
+
|
|
35
45
|
type TestFeature struct {
|
|
36
46
|
BaseFeature
|
|
37
47
|
client *core.ProjectNameSDK
|
|
@@ -63,6 +73,9 @@ func (f *TestFeature) Init(ctx *core.Context, options map[string]any) {
|
|
|
63
73
|
if m, ok := val.(map[string]any); ok {
|
|
64
74
|
if key != nil {
|
|
65
75
|
m["id"] = *key
|
|
76
|
+
if idField := declaredIdField(ctx.Config, path[0]); idField != "" {
|
|
77
|
+
m[idField] = *key
|
|
78
|
+
}
|
|
66
79
|
}
|
|
67
80
|
}
|
|
68
81
|
}
|
|
@@ -223,6 +236,9 @@ func (f *TestFeature) Init(ctx *core.Context, options map[string]any) {
|
|
|
223
236
|
ent := vs.Clone(testRecord(ctx.Reqdata))
|
|
224
237
|
if entm, ok := ent.(map[string]any); ok {
|
|
225
238
|
entm["id"] = id
|
|
239
|
+
if idField := declaredIdField(ctx.Config, op.Entity); idField != "" && entm[idField] == nil {
|
|
240
|
+
entm[idField] = id
|
|
241
|
+
}
|
|
226
242
|
if idStr, ok := id.(string); ok {
|
|
227
243
|
entmap[idStr] = entm
|
|
228
244
|
}
|
|
@@ -129,10 +129,11 @@ func defaultHTTPFetch(fullurl string, fetchdef map[string]any) (map[string]any,
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
// Default User-Agent — Go's net/http defaults to "Go-http-client/1.1"
|
|
132
|
-
// which some CDNs block. Use
|
|
133
|
-
// already set one, and record
|
|
132
|
+
// which some CDNs block. Use the project's agent (main.kit.http.useragent,
|
|
133
|
+
// browser-shaped by default) unless the caller already set one, and record
|
|
134
|
+
// it with the headers the request sent.
|
|
134
135
|
if !hasUA {
|
|
135
|
-
agent := "
|
|
136
|
+
agent := "PROJECTUSERAGENT"
|
|
136
137
|
req.Header.Set("User-Agent", agent)
|
|
137
138
|
if headers, ok := fetchdef["headers"].(map[string]any); ok {
|
|
138
139
|
headers["user-agent"] = agent
|
|
@@ -42,6 +42,13 @@ public class TestFeature extends BaseFeature {
|
|
|
42
42
|
return out;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
// The entity's declared identity field (`entity.id.field`), where it names
|
|
46
|
+
// one other than the `id` every record already carries.
|
|
47
|
+
private static String declaredIdField(Object config, String entityName) {
|
|
48
|
+
Object field = Struct.getpath(config, List.of("entity", entityName == null ? "" : entityName, "id", "field"));
|
|
49
|
+
return field instanceof String && !"".equals(field) && !"id".equals(field) ? (String) field : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
45
52
|
private static final java.util.regex.Pattern ITEM_ENVELOPE_RE =
|
|
46
53
|
java.util.regex.Pattern.compile("^`\\.([^.`$]+)`$");
|
|
47
54
|
|
|
@@ -100,6 +107,10 @@ public class TestFeature extends BaseFeature {
|
|
|
100
107
|
Struct.walk(entity, (key, val, parent, path) -> {
|
|
101
108
|
if (path != null && path.size() == 2 && val instanceof Map && key != null) {
|
|
102
109
|
((Map<String, Object>) val).put("id", key);
|
|
110
|
+
String idField = declaredIdField(ctx.config, path.get(0));
|
|
111
|
+
if (idField != null) {
|
|
112
|
+
((Map<String, Object>) val).put(idField, key);
|
|
113
|
+
}
|
|
103
114
|
}
|
|
104
115
|
return val;
|
|
105
116
|
});
|
|
@@ -308,6 +319,10 @@ public class TestFeature extends BaseFeature {
|
|
|
308
319
|
if (ent instanceof Map) {
|
|
309
320
|
Map<String, Object> entm = (Map<String, Object>) ent;
|
|
310
321
|
entm.put("id", id);
|
|
322
|
+
String idField = declaredIdField(ctx.config, op.entity);
|
|
323
|
+
if (idField != null && entm.get(idField) == null) {
|
|
324
|
+
entm.put(idField, id);
|
|
325
|
+
}
|
|
311
326
|
if (id instanceof String) {
|
|
312
327
|
entmap.put((String) id, entm);
|
|
313
328
|
}
|
|
@@ -128,11 +128,11 @@ final class Fetcher {
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
// Default User-Agent — some CDNs block Java's default. Use
|
|
132
|
-
//
|
|
133
|
-
// the headers the request sent.
|
|
131
|
+
// Default User-Agent — some CDNs block Java's default. Use the project's
|
|
132
|
+
// agent (main.kit.http.useragent, browser-shaped by default) unless the
|
|
133
|
+
// caller already set one, and record it with the headers the request sent.
|
|
134
134
|
if (!hasUA) {
|
|
135
|
-
String agent = "
|
|
135
|
+
String agent = "PROJECTUSERAGENT";
|
|
136
136
|
reqb.setHeader("User-Agent", agent);
|
|
137
137
|
if (headersRaw instanceof Map) {
|
|
138
138
|
((Map<String, Object>) headersRaw).put("user-agent", agent);
|
|
@@ -16,6 +16,14 @@ function mintId() {
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
19
|
+
// The entity's declared identity field (`entity.id.field`), where it names
|
|
20
|
+
// one other than the `id` every record already carries.
|
|
21
|
+
function declaredIdField(config, getpath, entityName) {
|
|
22
|
+
const field = getpath(config, ['entity', entityName, 'id', 'field'])
|
|
23
|
+
return 'string' === typeof field && '' !== field && 'id' !== field ? field : null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
19
27
|
// The record the mock keeps: the request data without `$body`, which only the
|
|
20
28
|
// wire carries.
|
|
21
29
|
function recordOf(reqdata) {
|
|
@@ -64,6 +72,10 @@ class TestFeature extends BaseFeature {
|
|
|
64
72
|
walk(entity, (k, v, _parent, path) => {
|
|
65
73
|
if (2 === size(path)) {
|
|
66
74
|
setprop(v, 'id', k)
|
|
75
|
+
const idField = declaredIdField(ctx.config, struct.getpath, String(path[0]))
|
|
76
|
+
if (null != idField) {
|
|
77
|
+
setprop(v, idField, k)
|
|
78
|
+
}
|
|
67
79
|
}
|
|
68
80
|
return v
|
|
69
81
|
})
|
|
@@ -204,6 +216,10 @@ class TestFeature extends BaseFeature {
|
|
|
204
216
|
|
|
205
217
|
const ent = clone(recordOf(ctx.reqdata))
|
|
206
218
|
setprop(ent, 'id', id)
|
|
219
|
+
const idField = declaredIdField(ctx.config, struct.getpath, getprop(op, 'entity'))
|
|
220
|
+
if (null != idField && null == getprop(ent, idField)) {
|
|
221
|
+
setprop(ent, idField, id)
|
|
222
|
+
}
|
|
207
223
|
setprop(entmap, id, ent)
|
|
208
224
|
delprop(ent, '$KEY')
|
|
209
225
|
const out = clone(ent)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
2
|
+
// Outside a browser a request without an agent carries the project's
|
|
3
|
+
// (main.kit.http.useragent): browser-shaped unless the model says otherwise,
|
|
4
|
+
// as several CDNs refuse a library's own.
|
|
5
|
+
const DEFAULT_USER_AGENT = 'PROJECTUSERAGENT'
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
function defaultUserAgent(fetchdef) {
|
|
@@ -14,7 +14,11 @@ async function resultBody(ctx) {
|
|
|
14
14
|
}
|
|
15
15
|
catch (err) {
|
|
16
16
|
if ('SyntaxError' !== err?.name) {
|
|
17
|
-
|
|
17
|
+
if (true === ctx.ctrl?.signal?.aborted) {
|
|
18
|
+
throw err
|
|
19
|
+
}
|
|
20
|
+
result.err = result.err ?? bodyReadError(ctx, result, err)
|
|
21
|
+
return result
|
|
18
22
|
}
|
|
19
23
|
result.err = unreadableBody(ctx, {
|
|
20
24
|
status: result.status, headers: result.headers, text: err.text,
|
|
@@ -28,6 +32,20 @@ async function resultBody(ctx) {
|
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
|
|
35
|
+
// A body that stopped before its end (a dropped connection, a deadline),
|
|
36
|
+
// named by the failure's kind alone: its message can carry a value.
|
|
37
|
+
function bodyReadError(ctx, result, err) {
|
|
38
|
+
const kind = [err?.name, err?.code ?? err?.cause?.code]
|
|
39
|
+
.filter((part) => 'string' === typeof part && '' !== part).join(' ')
|
|
40
|
+
const type = headerValue(result.headers, 'content-type')
|
|
41
|
+
const failed = ctx.error('response_body_read', 'response: body could not be read' +
|
|
42
|
+
('' === kind ? '' : ' (' + kind + ')') + ' (HTTP ' + result.status + ', content-type ' +
|
|
43
|
+
(type || 'none') + ')')
|
|
44
|
+
Object.defineProperty(failed, 'cause', { value: err, writable: true, configurable: true })
|
|
45
|
+
return failed
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
31
49
|
// A body that is not JSON. An HTTP failure keeps its own error, with the
|
|
32
50
|
// response described; otherwise the code tells a wrong content type from
|
|
33
51
|
// malformed JSON.
|
|
@@ -28,7 +28,8 @@ async function runLiveEntity(setup, entity, flow, accessor, facts = {}, settle =
|
|
|
28
28
|
...Object.values(entity.fields || {}).map((field) => field?.n).filter(Boolean)]);
|
|
29
29
|
const marks = new Map();
|
|
30
30
|
const idField = entity.id?.field || 'id';
|
|
31
|
-
const declared = new Set(Object.values(entity.fields || {})
|
|
31
|
+
const declared = new Set(Object.values(entity.fields || {})
|
|
32
|
+
.filter((field) => true !== field?.syn).map((field) => field?.n));
|
|
32
33
|
const repeatsId = null != entity.id && (declared.has(idField) || declared.has('id'));
|
|
33
34
|
const copy = (value) => JSON.parse(JSON.stringify(value ?? {}));
|
|
34
35
|
const hasCreate = steps.some(step => step.o === 'create');
|
|
@@ -36,6 +36,10 @@ class TestFeature : BaseFeature("test", "0.0.1", true) {
|
|
|
36
36
|
Struct.WalkApply { key, value, _, path ->
|
|
37
37
|
if (path.size == 2 && value is MutableMap<*, *> && key != null) {
|
|
38
38
|
(value as MutableMap<String, Any?>)["id"] = key
|
|
39
|
+
val idField = declaredIdField(ctx.config, path[0])
|
|
40
|
+
if (idField != null) {
|
|
41
|
+
(value as MutableMap<String, Any?>)[idField] = key
|
|
42
|
+
}
|
|
39
43
|
}
|
|
40
44
|
value
|
|
41
45
|
},
|
|
@@ -54,6 +58,13 @@ class TestFeature : BaseFeature("test", "0.0.1", true) {
|
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
|
|
61
|
+
// The entity's declared identity field (`entity.id.field`), where it names
|
|
62
|
+
// one other than the `id` every record already carries.
|
|
63
|
+
private fun declaredIdField(config: Any?, entityName: String): String? {
|
|
64
|
+
val field = Struct.getpath(config, listOf("entity", entityName, "id", "field"))
|
|
65
|
+
return if (field is String && field != "" && field != "id") field else null
|
|
66
|
+
}
|
|
67
|
+
|
|
57
68
|
// THE MOCK HAS TO AGREE WITH THE MODEL. A point carrying
|
|
58
69
|
// `transform.res: `body.item`` describes an API that answers {"item": {...}}
|
|
59
70
|
// and the response transform unwraps that key on the way back. Returning the
|
|
@@ -219,6 +230,10 @@ class TestFeature : BaseFeature("test", "0.0.1", true) {
|
|
|
219
230
|
if (ent is MutableMap<*, *>) {
|
|
220
231
|
val entm = ent as MutableMap<String, Any?>
|
|
221
232
|
entm["id"] = id
|
|
233
|
+
val idField = declaredIdField(ctx.config, op.entity)
|
|
234
|
+
if (idField != null && entm[idField] == null) {
|
|
235
|
+
entm[idField] = id
|
|
236
|
+
}
|
|
222
237
|
if (id is String) {
|
|
223
238
|
entmap[id] = entm
|
|
224
239
|
}
|
|
@@ -112,7 +112,7 @@ fun defaultHttpFetch(fullurl: String, fetchdef: MutableMap<String, Any?>): Mutab
|
|
|
112
112
|
// Default User-Agent — some CDNs block Java's default. It is recorded with
|
|
113
113
|
// the headers the request sent.
|
|
114
114
|
if (!hasUA) {
|
|
115
|
-
val agent = "
|
|
115
|
+
val agent = "PROJECTUSERAGENT"
|
|
116
116
|
reqb.setHeader("User-Agent", agent)
|
|
117
117
|
if (headersRaw is MutableMap<*, *>) {
|
|
118
118
|
(headersRaw as MutableMap<String, Any?>)["user-agent"] = agent
|
|
@@ -63,6 +63,7 @@ local json = require("dkjson")
|
|
|
63
63
|
local helpers = require("core.helpers")
|
|
64
64
|
local BaseFeature = require("feature.base_feature")
|
|
65
65
|
local sekreto = require("feature.secrets.sekreto")
|
|
66
|
+
local tls = require("utility.tls")
|
|
66
67
|
|
|
67
68
|
|
|
68
69
|
local SecretsFeature = {}
|
|
@@ -582,8 +583,8 @@ end
|
|
|
582
583
|
-- transport for the COMMON case would reject every live token purchase
|
|
583
584
|
-- before a request was made. Mirrors utility/fetcher.lua's own default
|
|
584
585
|
-- (which is a local there, not exported); like it, this is HTTP through
|
|
585
|
-
-- socket.http, and an https token endpoint needs luasec
|
|
586
|
-
--
|
|
586
|
+
-- socket.http, and an https token endpoint needs luasec on the package path,
|
|
587
|
+
-- which the rockspec does not require, and is verified as utility/tls says.
|
|
587
588
|
local function raw_exchange_fetch(fullurl, fetchdef)
|
|
588
589
|
local http_ok, http = pcall(require, "socket.http")
|
|
589
590
|
local ltn12_ok, ltn12 = pcall(require, "ltn12")
|
|
@@ -606,6 +607,11 @@ local function raw_exchange_fetch(fullurl, fetchdef)
|
|
|
606
607
|
headers["content-length"] = tostring(#body)
|
|
607
608
|
end
|
|
608
609
|
|
|
610
|
+
local create, refused = tls.create(fullurl)
|
|
611
|
+
if refused ~= nil then
|
|
612
|
+
return nil, refused
|
|
613
|
+
end
|
|
614
|
+
|
|
609
615
|
local chunks = {}
|
|
610
616
|
local res, code = http.request({
|
|
611
617
|
url = fullurl,
|
|
@@ -613,6 +619,7 @@ local function raw_exchange_fetch(fullurl, fetchdef)
|
|
|
613
619
|
headers = headers,
|
|
614
620
|
source = body and ltn12.source.string(body) or nil,
|
|
615
621
|
sink = ltn12.sink.table(chunks),
|
|
622
|
+
create = create,
|
|
616
623
|
})
|
|
617
624
|
|
|
618
625
|
if not res then
|
|
@@ -44,6 +44,16 @@ local function record(reqdata)
|
|
|
44
44
|
return out
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
-- The entity's declared identity field (`entity.id.field`), where it names
|
|
48
|
+
-- one other than the `id` every record already carries.
|
|
49
|
+
local function declared_id_field(config, entity_name)
|
|
50
|
+
local field = vs.getpath(config, { "entity", entity_name, "id", "field" })
|
|
51
|
+
if type(field) == "string" and field ~= "" and field ~= "id" then
|
|
52
|
+
return field
|
|
53
|
+
end
|
|
54
|
+
return nil
|
|
55
|
+
end
|
|
56
|
+
|
|
47
57
|
function TestFeature:init(ctx, options)
|
|
48
58
|
self.client = ctx.client
|
|
49
59
|
self.options = options
|
|
@@ -59,6 +69,10 @@ function TestFeature:init(ctx, options)
|
|
|
59
69
|
vs.walk(entity, function(key, val, parent, path)
|
|
60
70
|
if #path == 2 and type(val) == "table" and key ~= nil then
|
|
61
71
|
val["id"] = key
|
|
72
|
+
local id_field = declared_id_field(ctx.config, path[1])
|
|
73
|
+
if id_field ~= nil then
|
|
74
|
+
val[id_field] = key
|
|
75
|
+
end
|
|
62
76
|
end
|
|
63
77
|
return val
|
|
64
78
|
end)
|
|
@@ -235,6 +249,10 @@ function TestFeature:init(ctx, options)
|
|
|
235
249
|
local ent = vs.clone(record(fctx.reqdata))
|
|
236
250
|
if type(ent) == "table" then
|
|
237
251
|
ent["id"] = id
|
|
252
|
+
local id_field = declared_id_field(fctx.config, op.entity)
|
|
253
|
+
if id_field ~= nil and ent[id_field] == nil then
|
|
254
|
+
ent[id_field] = id
|
|
255
|
+
end
|
|
238
256
|
if type(id) == "string" then
|
|
239
257
|
entmap[id] = ent
|
|
240
258
|
end
|